small player speed refactor
This commit is contained in:
@@ -18,7 +18,7 @@ main :: proc() {
|
|||||||
init_world()
|
init_world()
|
||||||
|
|
||||||
player = {
|
player = {
|
||||||
position = {0, 0},
|
position = {300, 300},
|
||||||
camera = {
|
camera = {
|
||||||
zoom = 4,
|
zoom = 4,
|
||||||
offset = {f32(raylib.GetScreenWidth()) / 2, f32(raylib.GetScreenHeight()) / 2},
|
offset = {f32(raylib.GetScreenWidth()) / 2, f32(raylib.GetScreenHeight()) / 2},
|
||||||
|
|||||||
@@ -3,12 +3,15 @@ package main
|
|||||||
import "core:math"
|
import "core:math"
|
||||||
import "vendor:raylib"
|
import "vendor:raylib"
|
||||||
|
|
||||||
PLAYER_SPRINT_SPEED :: 80
|
PLAYER_DEFAULT_SPRINT_SPEED :: 100
|
||||||
PLAYER_SPEED :: 50
|
PLAYER_DEFAULT_SPEED :: 60
|
||||||
PLAYER_WIDTH :: 32
|
PLAYER_WIDTH :: 32
|
||||||
PLAYER_HEIGHT :: 32
|
PLAYER_HEIGHT :: 32
|
||||||
PLAYER_SPRITE_PATH :: "assets/player/player.png"
|
PLAYER_SPRITE_PATH :: "assets/player/player.png"
|
||||||
|
|
||||||
|
player_speed := PLAYER_DEFAULT_SPEED
|
||||||
|
player_sprint_speed := PLAYER_DEFAULT_SPRINT_SPEED
|
||||||
|
|
||||||
spritesheet: raylib.Texture2D
|
spritesheet: raylib.Texture2D
|
||||||
framesX: i32
|
framesX: i32
|
||||||
framesY: i32
|
framesY: i32
|
||||||
@@ -58,7 +61,7 @@ handle_player_input :: proc(p: ^Player, delta: f32) {
|
|||||||
is_sprinting := raylib.IsKeyDown(.LEFT_SHIFT)
|
is_sprinting := raylib.IsKeyDown(.LEFT_SHIFT)
|
||||||
dir = raylib.Vector2Normalize(dir)
|
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
|
p.animator.anim.fps = is_sprinting ? 11 : 6
|
||||||
|
|
||||||
velocity := dir * speed_val * delta
|
velocity := dir * speed_val * delta
|
||||||
@@ -113,6 +116,9 @@ update_player :: proc(p: ^Player, delta: f32) {
|
|||||||
handle_player_input(p, delta)
|
handle_player_input(p, delta)
|
||||||
handle_player_camera(p, delta)
|
handle_player_camera(p, delta)
|
||||||
|
|
||||||
|
// Remove this in release
|
||||||
|
handle_debug_inputs()
|
||||||
|
|
||||||
if (p.state == .IDLE) {
|
if (p.state == .IDLE) {
|
||||||
set_sprite_animation(&p.animator, &idle_animation)
|
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
|
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
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user