Testing basic basic attack animation on player.

This commit is contained in:
2026-08-03 06:39:28 +02:00
parent c4e5cdc9e6
commit 5a0256d60d
7 changed files with 19 additions and 23 deletions
+2 -2
View File
@@ -18,9 +18,9 @@ AnimationState :: struct {
finished: bool,
}
animation_play :: proc(state: ^AnimationState, clip: ^AnimationClip) {
animation_play :: proc(state: ^AnimationState, clip: ^AnimationClip, restart := false) {
// already playing, do not reset
if state.clip == clip do return
if state.clip == clip && !restart do return
state.clip = clip
state.current_frame = 0
state.timer = 0
+5 -1
View File
@@ -32,13 +32,17 @@ asset_manager_init :: proc() -> Asset_Manager {
init_player_assets :: proc(clip_array: ^[Player_State]AnimationClip) {
idle_tex := rl.LoadTexture("assets/textures/player/player_idle.png")
walk_tex := rl.LoadTexture("assets/textures/player/player_walk.png")
attk_tex := rl.LoadTexture("assets/textures/player/player_attack_one.png")
clip_array[.IDLE] = AnimationClip {
texture = idle_tex, frame_count = 6, frame_width = 32, frame_height = 32, frame_time = 0.14, looping = true,
texture = idle_tex, frame_count = 8, frame_width = 32, frame_height = 32, frame_time = 0.14, looping = true,
}
clip_array[.WALK] = AnimationClip {
texture = walk_tex, frame_count = 8, frame_width = 32, frame_height = 32, frame_time = 0.14, looping = true,
}
clip_array[.ATTACK] = AnimationClip {
texture = attk_tex, frame_count = 4, frame_width = 64, frame_height = 32, frame_time = 0.12, looping = false,
}
}
init_enemy_assets :: proc(clip_array: ^[Enemy_State]AnimationClip) {
+2 -2
View File
@@ -12,14 +12,14 @@ WINDOW_WIDTH :: 1920
WINDOW_HEIGHT :: 1080
GAME_WIDTH :: 480
GAME_HEIGHT :: 270
MAX_ENEMIES :: 300
MAX_ENEMIES :: 0
MAX_PROPS :: 64
TILE_SIZE :: 32
// -----------------------------------------------------------------------------
main :: proc() {
context.logger = log.create_console_logger()
context.logger = log.create_console_logger()
defer log.destroy_console_logger(context.logger)
when DEBUG_MODE {
+10 -18
View File
@@ -128,28 +128,21 @@ update_player :: proc(
player.velocity.y = 0
}
// @TESTING
if rl.IsMouseButtonPressed(.LEFT) {
mouse_pos := rl.GetMousePosition()
screen_space := window_to_screen(mouse_pos)
if is_attacking {
player.velocity = rl.Vector2MoveTowards(player.velocity, rl.Vector2{0,0}, player.friction * dt)
}
x := screen_to_world(screen_space, camera)
fmt.printf("Mouse pos -> world pos: %v\n", x)
v := world_to_screen(x, camera)
fmt.printf("world pos -> screen pos: %v\n", v)
y := world_to_grid(x)
fmt.printf("Mouse pos -> grid coord: %v\n", y)
z := grid_to_world(y[0], y[1])
fmt.printf("grid pos -> world pos: %v\n", z)
}
player.state = moving ? .WALK : .IDLE
animation_play(&player.animation, &assets.clips[player.state])
if attack_pressed {
player.state = .ATTACK
animation_play(&player.animation, &assets.clips[.ATTACK], restart = true)
} else if !is_attacking {
player.state = moving ? .WALK : .IDLE
animation_play(&player.animation, &assets.clips[player.state])
}
animation_update(&player.animation, dt)
}
update_player_flow_field :: proc(player: ^Player, game_map: ^Game_Map) {
// Use the collider's center (not the sprite anchor/top-left) so the
// grid cell reflects where the player physically is
collider := get_player_collider(player, player.position)
@@ -170,7 +163,6 @@ update_player_flow_field :: proc(player: ^Player, game_map: ^Game_Map) {
}
}
draw_player :: proc(player: ^Player) {
clip := player.animation.clip
src_rect := animation_frame_rect(&player.animation)