diff --git a/assets/textures/player/player_attack_one.png b/assets/textures/player/player_attack_one.png new file mode 100644 index 0000000..97e0da7 Binary files /dev/null and b/assets/textures/player/player_attack_one.png differ diff --git a/assets/textures/player/player_idle.png b/assets/textures/player/player_idle.png index d9be6af..dcd88de 100644 Binary files a/assets/textures/player/player_idle.png and b/assets/textures/player/player_idle.png differ diff --git a/assets/textures/player/player_walk.png b/assets/textures/player/player_walk.png index 105f2fa..0fb9a22 100644 Binary files a/assets/textures/player/player_walk.png and b/assets/textures/player/player_walk.png differ diff --git a/src/animator.odin b/src/animator.odin index 72c83c5..ed2fd4d 100644 --- a/src/animator.odin +++ b/src/animator.odin @@ -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 diff --git a/src/asset_manager.odin b/src/asset_manager.odin index 358187a..803dffc 100644 --- a/src/asset_manager.odin +++ b/src/asset_manager.odin @@ -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) { diff --git a/src/main.odin b/src/main.odin index 85b868f..9ab02fa 100644 --- a/src/main.odin +++ b/src/main.odin @@ -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 { diff --git a/src/player.odin b/src/player.odin index 3c33fa9..e23753d 100644 --- a/src/player.odin +++ b/src/player.odin @@ -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)