aboutsummaryrefslogtreecommitdiff
path: root/v_windows/v/examples/fireworks/modules/objects/rocket.v
diff options
context:
space:
mode:
authorIndrajith K L2022-12-03 17:00:20 +0530
committerIndrajith K L2022-12-03 17:00:20 +0530
commitf5c4671bfbad96bf346bd7e9a21fc4317b4959df (patch)
tree2764fc62da58f2ba8da7ed341643fc359873142f /v_windows/v/examples/fireworks/modules/objects/rocket.v
downloadcli-tools-windows-f5c4671bfbad96bf346bd7e9a21fc4317b4959df.tar.gz
cli-tools-windows-f5c4671bfbad96bf346bd7e9a21fc4317b4959df.tar.bz2
cli-tools-windows-f5c4671bfbad96bf346bd7e9a21fc4317b4959df.zip
Adds most of the toolsHEADmaster
Diffstat (limited to 'v_windows/v/examples/fireworks/modules/objects/rocket.v')
-rw-r--r--v_windows/v/examples/fireworks/modules/objects/rocket.v69
1 files changed, 69 insertions, 0 deletions
diff --git a/v_windows/v/examples/fireworks/modules/objects/rocket.v b/v_windows/v/examples/fireworks/modules/objects/rocket.v
new file mode 100644
index 0000000..ebdce0a
--- /dev/null
+++ b/v_windows/v/examples/fireworks/modules/objects/rocket.v
@@ -0,0 +1,69 @@
+module objects
+
+import gg
+import gx
+import rand
+
+pub struct Rocket {
+pub mut:
+ color gx.Color
+ pos Vector
+ vel Vector
+ accel Vector
+ exploded bool
+ particles []Particle
+ dead bool
+}
+
+pub fn (rocket Rocket) draw(mut ctx gg.Context) {
+ ctx.draw_circle(rocket.pos.x, get_params().height - rocket.pos.y, get_params().rocket_radius,
+ rocket.color)
+}
+
+pub fn (mut rocket Rocket) explode() {
+ rocket.exploded = true
+
+ for _ in 0 .. get_params().offspring_count {
+ rocket.spawn_particle()
+ }
+}
+
+pub fn (mut rocket Rocket) tick(mut ctx gg.Context) {
+ if !rocket.exploded {
+ if rocket.vel.y <= 1 {
+ rocket.explode()
+ }
+
+ rocket.accel += get_params().gravity
+ rocket.vel += rocket.accel
+ rocket.pos += rocket.vel
+ rocket.draw(mut ctx)
+
+ rocket.accel = Vector{}
+ }
+
+ for mut particle in rocket.particles {
+ particle.tick(mut rocket, mut ctx)
+ }
+}
+
+pub fn new_rocket() Rocket {
+ return Rocket{
+ color: random_color()
+ pos: Vector{
+ x: rand.f32_in_range(50, get_params().width - 50)
+ }
+ vel: Vector{
+ x: rand.f32_in_range(-1.5, 1.5)
+ y: rand.f32_in_range(5, 7)
+ }
+ }
+}
+
+pub fn (mut rocket Rocket) spawn_particle() {
+ rocket.particles << Particle{
+ color: rocket.color
+ pos: rocket.pos
+ accel: random_vector_in_circle().mult(2)
+ }
+}