small player speed refactor

This commit is contained in:
2026-02-16 13:17:51 -06:00
parent 4876b486a8
commit c7cfd5eac0
2 changed files with 15 additions and 4 deletions

View File

@@ -18,7 +18,7 @@ main :: proc() {
init_world()
player = {
position = {0, 0},
position = {300, 300},
camera = {
zoom = 4,
offset = {f32(raylib.GetScreenWidth()) / 2, f32(raylib.GetScreenHeight()) / 2},

View File

@@ -3,12 +3,15 @@ package main
import "core:math"
import "vendor:raylib"
PLAYER_SPRINT_SPEED :: 80
PLAYER_SPEED :: 50
PLAYER_DEFAULT_SPRINT_SPEED :: 100
PLAYER_DEFAULT_SPEED :: 60
PLAYER_WIDTH :: 32
PLAYER_HEIGHT :: 32
PLAYER_SPRITE_PATH :: "assets/player/player.png"
player_speed := PLAYER_DEFAULT_SPEED
player_sprint_speed := PLAYER_DEFAULT_SPRINT_SPEED
spritesheet: raylib.Texture2D
framesX: i32
framesY: i32
@@ -58,7 +61,7 @@ handle_player_input :: proc(p: ^Player, delta: f32) {
is_sprinting := raylib.IsKeyDown(.LEFT_SHIFT)
dir = raylib.Vector2Normalize(dir)
speed_val := f32(is_sprinting ? PLAYER_SPRINT_SPEED : PLAYER_SPEED)
speed_val := f32(is_sprinting ? player_sprint_speed : player_speed)
p.animator.anim.fps = is_sprinting ? 11 : 6
velocity := dir * speed_val * delta
@@ -113,6 +116,9 @@ update_player :: proc(p: ^Player, delta: f32) {
handle_player_input(p, delta)
handle_player_camera(p, delta)
// Remove this in release
handle_debug_inputs()
if (p.state == .IDLE) {
set_sprite_animation(&p.animator, &idle_animation)
}
@@ -150,3 +156,8 @@ is_wall_at :: proc(world_pos: raylib.Vector2) -> bool {
return tile != nil && tile.type == .WALL
}
handle_debug_inputs :: proc() {
if (raylib.IsKeyPressed(.KP_ADD)) do player_sprint_speed += 10
if (raylib.IsKeyPressed(.KP_SUBTRACT)) do player_sprint_speed -= 10
}