Spaceship death parts flying to oblivion
This commit is contained in:
parent
4fec0fda01
commit
45d10ea271
34
game.odin
34
game.odin
@ -2,6 +2,7 @@ package asteroids
|
||||
|
||||
import rl "vendor:raylib"
|
||||
import "core:math"
|
||||
import "core:math/rand"
|
||||
import "core:fmt"
|
||||
|
||||
Vec2 :: [2]f32
|
||||
@ -72,6 +73,11 @@ update_ship_shape :: proc(p : ^Player) {
|
||||
p.points[3] = rl.Vector2Rotate({-SHIP_H*0.5, SHIP_W*0.5}, p.angle) + p.pos
|
||||
}
|
||||
|
||||
random_direction :: proc() -> Vec2 {
|
||||
angle := rand.float32() * math.PI
|
||||
return {math.cos(angle), math.sin(angle)}
|
||||
}
|
||||
|
||||
swap_n_pop :: proc(bullets: ^[dynamic]$T, idx: int) {
|
||||
last := len(bullets) - 1
|
||||
if last == 0 {
|
||||
@ -186,7 +192,12 @@ update :: proc(s: ^GameState) {
|
||||
if ship_collision {
|
||||
// Randomize everything
|
||||
s.player_state = Death {
|
||||
|
||||
flying_parts = {
|
||||
PlayerSpinningPart { {player.points[0],player.points[1]}, 0.2, random_direction() },
|
||||
PlayerSpinningPart { {player.points[1],player.points[2]}, 0.2, random_direction() },
|
||||
PlayerSpinningPart { {player.points[2],player.points[3]}, 0.2, random_direction() },
|
||||
PlayerSpinningPart { {player.points[3],player.points[0]}, 0.2, random_direction() },
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if player.pos.x + SHIP_W < 0 { player.pos.x = BW + SHIP_W}
|
||||
@ -195,6 +206,22 @@ update :: proc(s: ^GameState) {
|
||||
if player.pos.y - SHIP_H > BH { player.pos.y = -SHIP_H}
|
||||
}
|
||||
case Death:
|
||||
for i := 0; i < len(player.flying_parts); i += 1 {
|
||||
part := &player.flying_parts[i]
|
||||
part.points[0] += part.vel
|
||||
part.points[1] += part.vel
|
||||
}
|
||||
for i := 0; i < len(s.bullets); i += 1 {
|
||||
if ( s.bullets[i].pos.x < 0 || s.bullets[i].pos.x > BW
|
||||
|| s.bullets[i].pos.y < 0 || s.bullets[i].pos.y > BH) {
|
||||
append(&s.bullet_pop_idxs, i)
|
||||
}
|
||||
s.bullets[i].pos += s.bullets[i].vel
|
||||
}
|
||||
for i := 0; i < len(s.asteroids); i += 1 {
|
||||
s.asteroids[i].rect.x += s.asteroids[i].vel.x * s.dt
|
||||
s.asteroids[i].rect.y += s.asteroids[i].vel.y * s.dt
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -207,11 +234,14 @@ draw2d :: proc(s: ^GameState) {
|
||||
rl.DrawLineEx(player.points[2], player.points[3], 1, rl.WHITE)
|
||||
rl.DrawLineEx(player.points[3], player.points[0], 1, rl.WHITE)
|
||||
case Death:
|
||||
for i := 0; i < len(player.flying_parts); i += 1 {
|
||||
part := &player.flying_parts[i]
|
||||
rl.DrawLineEx(part.points[0], part.points[1], 1, rl.WHITE)
|
||||
}
|
||||
}
|
||||
for i := 0; i < len(s.asteroids); i += 1 {
|
||||
rl.DrawRectangleLinesEx(s.asteroids[i].rect, 1, rl.WHITE)
|
||||
}
|
||||
|
||||
for i := 0; i < len(s.bullets); i += 1 {
|
||||
rl.DrawCircleLinesV(s.bullets[i].pos, BULLET_RADIUS, rl.WHITE)
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user