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,17 +119,19 @@ game_draw :: proc(state: ^GameState) {
rl.DrawText(rl.TextFormat("STATE: %s", Head.state), 0, 20, 20, rl.BLACK)
hb_text : cstring = "Jörmungandr"
height := 30 * (WSize.y / 480)
hb_health : f32 = f32(snake_health) / f32(snake_max_health)
if snake_health == 0 {
hb_health = f32(Head.health) / f32(Head.max_health)
hb_text = "Jörmungandr's head"
if stack_top() == game {
hb_text : cstring = "Jörmungandr"
height := 30 * (WSize.y / 480)
hb_health : f32 = f32(snake_health) / f32(snake_max_health)
if snake_health == 0 {
hb_health = f32(Head.health) / f32(Head.max_health)
hb_text = "Jörmungandr's head"
}
rl.DrawRectangleV({0, WSize.y - height - 10}, {WSize.x, height + 10}, rl.WHITE)
hb_width := hb_health * WSize.x
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)
}
rl.DrawRectangleV({0, WSize.y - height - 10}, {WSize.x, height + 10}, rl.WHITE)
hb_width := hb_health * WSize.x
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)
}

View File

@ -88,6 +88,8 @@ snake_clear :: proc() {
}
snake_process :: proc(game: ^Game, delta: f32) {
// Head.state = .Shot
// Head.state_timer = 200
switch Head.state {
case .Chasing:
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 {
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.pos += Head.vel * delta
}