2021-01-26 22:13:11 +01:00
|
|
|
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) {
|
2021-12-23 12:31:25 +01:00
|
|
|
ctx.draw_circle_filled(particle.pos.x, get_params().height - particle.pos.y, get_params().particle_radius,
|
2021-01-26 22:40:30 +01:00
|
|
|
particle.color)
|
2021-01-26 22:13:11 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn (mut particle Particle) tick(mut rocket Rocket, mut ctx gg.Context) {
|
2021-01-26 22:40:30 +01:00
|
|
|
particle.lifespan -= get_params().age_rate
|
2021-01-26 22:13:11 +01:00
|
|
|
particle.color.a = byte(particle.lifespan)
|
|
|
|
|
|
|
|
if particle.lifespan <= 0 {
|
|
|
|
rocket.dead = true
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2021-01-26 22:40:30 +01:00
|
|
|
particle.accel += get_params().gravity
|
2021-01-26 22:13:11 +01:00
|
|
|
particle.vel += particle.accel
|
2021-01-26 22:40:30 +01:00
|
|
|
particle.vel = particle.vel.mult(get_params().drag)
|
2021-01-26 22:13:11 +01:00
|
|
|
particle.pos += particle.vel
|
|
|
|
particle.draw(mut ctx)
|
|
|
|
|
2021-07-20 10:17:08 +02:00
|
|
|
particle.accel = Vector{}
|
2021-01-26 22:13:11 +01:00
|
|
|
}
|