aboutsummaryrefslogtreecommitdiff
path: root/v_windows/v/examples/fireworks/modules/objects/particle.v
blob: 8f84a394a9684535ba5a29767031d9505e3df234 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
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(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 = byte(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{}
}