From 678c14b680b92cebafaf6d72cf18808213bb4e20 Mon Sep 17 00:00:00 2001 From: WiseNoodle Date: Sun, 15 Feb 2026 22:16:16 -0500 Subject: [PATCH] Add player sprint and anim change while sprinting --- src/main.odin | 2 +- src/player.odin | 21 +++++++++++++++++++-- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/src/main.odin b/src/main.odin index e362287..3cbbd3d 100644 --- a/src/main.odin +++ b/src/main.odin @@ -21,7 +21,7 @@ main :: proc() { TILEMAP_TILE_SIZE, TILEMAP_TILE_SIZE, ) - grid = create_tile_grid(100, 100) + grid = create_tile_grid(300, 300) player = { position = {20, 20}, diff --git a/src/player.odin b/src/player.odin index b40809f..9e35948 100644 --- a/src/player.odin +++ b/src/player.odin @@ -4,7 +4,8 @@ import "core:fmt" import "core:strings" import "vendor:raylib" -PLAYER_SPEED :: 2 +PLAYER_SPRINT_SPEED :: 2.5 +PLAYER_SPEED :: 1.5 PLAYER_WIDTH :: 32 PLAYER_HEIGHT :: 32 PLAYER_SPRITE_PATH :: "assets/player/player.png" @@ -58,8 +59,24 @@ handle_player_input :: proc(p: ^Player, delta: f32) { is_moving := dir.x != 0 || dir.y != 0 if (is_moving) { + is_sprinting:= false + + if raylib.IsKeyDown(.LEFT_SHIFT) { + is_sprinting = true + } else { + is_sprinting = false + } + dir = raylib.Vector2Normalize(dir) - dir = dir * PLAYER_SPEED + + if is_sprinting{ + dir = dir * PLAYER_SPRINT_SPEED + p.animator.anim.fps = 11 + } else { + dir = dir * PLAYER_SPEED + p.animator.anim.fps = 6 + } + p.position = p.position + dir if dir.x < 0 {