2024-10-04 21:16:58 +03:00
|
|
|
package main
|
|
|
|
|
|
|
|
import rl "vendor:raylib"
|
2024-10-05 20:44:32 +03:00
|
|
|
import "core:fmt"
|
|
|
|
import "core:math/rand"
|
|
|
|
import "core:slice"
|
|
|
|
import "core:math"
|
2024-10-04 21:16:58 +03:00
|
|
|
|
|
|
|
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,
|
2024-10-05 20:44:32 +03:00
|
|
|
radius = 0.7
|
2024-10-04 21:16:58 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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 {
|
2024-10-05 20:44:32 +03:00
|
|
|
diff := bullet.pos - Head.pos
|
|
|
|
diff_ang := math.atan2(-diff.y, diff.x)
|
|
|
|
angle := angle_cycle(Head.dir - diff_ang, -math.PI, math.PI)
|
|
|
|
if abs(angle) > math.PI / 3 {
|
|
|
|
rl.PlaySound(Res.Sfx.LightningHit)
|
|
|
|
explode(bullet.pos, 1, 0.6, rl.YELLOW)
|
|
|
|
Head.health -= 1
|
|
|
|
}
|
2024-10-04 21:16:58 +03:00
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
for &segment in Segments {
|
|
|
|
if rl.CheckCollisionCircles(bullet.pos.xy, bullet.radius, segment.pos.xy, segment.collider_radius) {
|
|
|
|
bullet.alive = false
|
2024-10-05 20:44:32 +03:00
|
|
|
rl.PlaySound(Res.Sfx.LightningHit)
|
2024-10-04 21:16:58 +03:00
|
|
|
if segment.health > 0 {
|
|
|
|
segment.health -= 1
|
2024-10-05 20:44:32 +03:00
|
|
|
explode(bullet.pos, 1, 0.6, rl.YELLOW)
|
2024-10-04 21:16:58 +03:00
|
|
|
if segment.health == 0 {
|
|
|
|
segment.collider_radius = 1.5
|
2024-10-05 20:44:32 +03:00
|
|
|
explode(segment.pos, 3, 0.7, rl.RED)
|
|
|
|
rl.PlaySound(Res.Sfx.SnakeSegmentExplode)
|
2024-10-04 21:16:58 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-10-05 20:44:32 +03:00
|
|
|
bullet_draw :: proc(bullet: ^Bullet, game: ^Game) {
|
|
|
|
rl.DrawSphere(bullet.pos, 0.5, rl.YELLOW)
|
|
|
|
line_count := 0
|
|
|
|
|
|
|
|
bdraw := slice.clone_to_dynamic(game.bullets[:])
|
|
|
|
|
|
|
|
rand.shuffle(bdraw[:])
|
|
|
|
for &bul in bdraw {
|
|
|
|
if &bul == bullet {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
if line_count > 0 {
|
|
|
|
break
|
|
|
|
}
|
|
|
|
if rl.Vector3LengthSqr(bul.pos - bullet.pos) > 70 {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
line_count += 1
|
|
|
|
|
|
|
|
rl.DrawLine3D(bullet.pos, bul.pos, rl.YELLOW)
|
|
|
|
}
|
2024-10-04 21:16:58 +03:00
|
|
|
}
|