Ragnarokkr/player_bullets.odin

52 lines
1.3 KiB
Odin
Raw Normal View History

2024-10-04 21:16:58 +03:00
package main
import rl "vendor:raylib"
bullets : [dynamic]Bullet
Bullet :: struct{
pos: vec3,
vel: vec3,
radius: f32,
alive: bool,
}
bullet_spawn :: proc(pos: vec3, dir: f32) -> Bullet {
return Bullet {
pos = pos,
vel = get_vec_from_angle(dir) * 70,
alive = true,
radius = 0.4
}
}
bullet_process :: proc(bullet: ^Bullet, game: ^Game, delta: f32) {
bullet.vel = rl.Vector3MoveTowards(bullet.vel, {}, 60 * delta)
bullet.pos += bullet.vel * delta
if rl.Vector3LengthSqr(bullet.vel) < 0.2 {
bullet.alive = false
}
if rl.CheckCollisionCircles(bullet.pos.xy, bullet.radius, Head.pos.xy, Head.radius) {
bullet.alive = false
if game.snake_health == 0 {
Head.health -= 1
}
return
}
for &segment in Segments {
if rl.CheckCollisionCircles(bullet.pos.xy, bullet.radius, segment.pos.xy, segment.collider_radius) {
bullet.alive = false
if segment.health > 0 {
segment.health -= 1
if segment.health == 0 {
segment.collider_radius = 1.5
}
}
}
}
}
bullet_draw :: proc(bullet: Bullet) {
rl.DrawSphere(bullet.pos, bullet.radius, rl.WHITE)
}