1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00
v/examples/fireworks/modules/objects/particle.v
Alexander Medvednikov d4a0d6f73c all: byte => u8
2022-04-15 14:58:56 +03:00

37 lines
780 B
V

module objects
import gg
import gx
pub struct Particle {
pub mut:
color gx.Color
pos Vector
vel Vector
accel Vector
lifespan f32 = 255
}
pub fn (particle Particle) draw(mut ctx gg.Context) {
ctx.draw_circle_filled(particle.pos.x, get_params().height - particle.pos.y, get_params().particle_radius,
particle.color)
}
pub fn (mut particle Particle) tick(mut rocket Rocket, mut ctx gg.Context) {
particle.lifespan -= get_params().age_rate
particle.color.a = u8(particle.lifespan)
if particle.lifespan <= 0 {
rocket.dead = true
return
}
particle.accel += get_params().gravity
particle.vel += particle.accel
particle.vel = particle.vel.mult(get_params().drag)
particle.pos += particle.vel
particle.draw(mut ctx)
particle.accel = Vector{}
}