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
Binary file not shown.

After

Width:  |  Height:  |  Size: 847 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.0 KiB

After

Width:  |  Height:  |  Size: 769 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.4 KiB

After

Width:  |  Height:  |  Size: 1.0 KiB

+2 -2
View File
@@ -18,9 +18,9 @@ AnimationState :: struct {
finished: bool, finished: bool,
} }
animation_play :: proc(state: ^AnimationState, clip: ^AnimationClip) { animation_play :: proc(state: ^AnimationState, clip: ^AnimationClip, restart := false) {
// already playing, do not reset // already playing, do not reset
if state.clip == clip do return if state.clip == clip && !restart do return
state.clip = clip state.clip = clip
state.current_frame = 0 state.current_frame = 0
state.timer = 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) { init_player_assets :: proc(clip_array: ^[Player_State]AnimationClip) {
idle_tex := rl.LoadTexture("assets/textures/player/player_idle.png") idle_tex := rl.LoadTexture("assets/textures/player/player_idle.png")
walk_tex := rl.LoadTexture("assets/textures/player/player_walk.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 { 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 { clip_array[.WALK] = AnimationClip {
texture = walk_tex, frame_count = 8, frame_width = 32, frame_height = 32, frame_time = 0.14, looping = true, 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) { init_enemy_assets :: proc(clip_array: ^[Enemy_State]AnimationClip) {
+1 -1
View File
@@ -12,7 +12,7 @@ WINDOW_WIDTH :: 1920
WINDOW_HEIGHT :: 1080 WINDOW_HEIGHT :: 1080
GAME_WIDTH :: 480 GAME_WIDTH :: 480
GAME_HEIGHT :: 270 GAME_HEIGHT :: 270
MAX_ENEMIES :: 300 MAX_ENEMIES :: 0
MAX_PROPS :: 64 MAX_PROPS :: 64
TILE_SIZE :: 32 TILE_SIZE :: 32
+7 -15
View File
@@ -128,28 +128,21 @@ update_player :: proc(
player.velocity.y = 0 player.velocity.y = 0
} }
// @TESTING if is_attacking {
if rl.IsMouseButtonPressed(.LEFT) { player.velocity = rl.Vector2MoveTowards(player.velocity, rl.Vector2{0,0}, player.friction * dt)
mouse_pos := rl.GetMousePosition()
screen_space := window_to_screen(mouse_pos)
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)
} }
if attack_pressed {
player.state = .ATTACK
animation_play(&player.animation, &assets.clips[.ATTACK], restart = true)
} else if !is_attacking {
player.state = moving ? .WALK : .IDLE player.state = moving ? .WALK : .IDLE
animation_play(&player.animation, &assets.clips[player.state]) animation_play(&player.animation, &assets.clips[player.state])
}
animation_update(&player.animation, dt) animation_update(&player.animation, dt)
} }
update_player_flow_field :: proc(player: ^Player, game_map: ^Game_Map) { update_player_flow_field :: proc(player: ^Player, game_map: ^Game_Map) {
// Use the collider's center (not the sprite anchor/top-left) so the // Use the collider's center (not the sprite anchor/top-left) so the
// grid cell reflects where the player physically is // grid cell reflects where the player physically is
collider := get_player_collider(player, player.position) 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) { draw_player :: proc(player: ^Player) {
clip := player.animation.clip clip := player.animation.clip
src_rect := animation_frame_rect(&player.animation) src_rect := animation_frame_rect(&player.animation)