Snake shot angle fix

This commit is contained in:
Vlad Rud 2024-10-04 21:29:39 +03:00
parent ade25af03a
commit 281a9ee400
2 changed files with 18 additions and 13 deletions

View File

@ -119,6 +119,7 @@ game_draw :: proc(state: ^GameState) {
rl.DrawText(rl.TextFormat("STATE: %s", Head.state), 0, 20, 20, rl.BLACK) rl.DrawText(rl.TextFormat("STATE: %s", Head.state), 0, 20, 20, rl.BLACK)
if stack_top() == game {
hb_text : cstring = "Jörmungandr" hb_text : cstring = "Jörmungandr"
height := 30 * (WSize.y / 480) height := 30 * (WSize.y / 480)
hb_health : f32 = f32(snake_health) / f32(snake_max_health) hb_health : f32 = f32(snake_health) / f32(snake_max_health)
@ -130,6 +131,7 @@ game_draw :: proc(state: ^GameState) {
hb_width := hb_health * WSize.x hb_width := hb_health * WSize.x
rl.DrawRectangleV({WSize.x / 2 - hb_width / 2, WSize.y - height - 7}, {hb_width, height + 4}, rl.RED) rl.DrawRectangleV({WSize.x / 2 - hb_width / 2, WSize.y - height - 7}, {hb_width, height + 4}, rl.RED)
draw_text_centered(FontTitle, hb_text, {WSize.x / 2, WSize.y - height / 2}, height) draw_text_centered(FontTitle, hb_text, {WSize.x / 2, WSize.y - height / 2}, height)
}
} }

View File

@ -88,6 +88,8 @@ snake_clear :: proc() {
} }
snake_process :: proc(game: ^Game, delta: f32) { snake_process :: proc(game: ^Game, delta: f32) {
// Head.state = .Shot
// Head.state_timer = 200
switch Head.state { switch Head.state {
case .Chasing: case .Chasing:
snake_chase_smooth(game, delta) snake_chase_smooth(game, delta)
@ -232,10 +234,11 @@ snake_shot :: proc(game: ^Game, delta: f32) {
if Head.state_timer < 8 && Head.state_timer > 3 { if Head.state_timer < 8 && Head.state_timer > 3 {
Head.is_shooting = true Head.is_shooting = true
} }
diff := game.player.pos - Head.pos
angle := math.atan2(-diff.y, diff.x)
Head.dir = angle_rotate(Head.dir, angle, angle_cycle(abs(angle - Head.dir), -math.PI, math.PI) * delta * 2) diff := game.player.pos - Head.pos
target_angle := math.atan2(-diff.y, diff.x)
dir_diff := angle_cycle(target_angle - Head.dir, -math.PI, math.PI)
Head.dir = angle_rotate(Head.dir, target_angle, abs(dir_diff) * delta * 1.5)
Head.vel = rl.Vector3MoveTowards(Head.vel, {}, 30 * delta) Head.vel = rl.Vector3MoveTowards(Head.vel, {}, 30 * delta)
Head.pos += Head.vel * delta Head.pos += Head.vel * delta
} }