Add player sprint and anim change while sprinting

This commit is contained in:
WiseNoodle
2026-02-15 22:16:16 -05:00
parent 7f7cbc567b
commit 678c14b680
2 changed files with 20 additions and 3 deletions

View File

@@ -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},

View File

@@ -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 {