improve Unit and utilities

This commit is contained in:
Morrígan 2025-06-28 15:21:52 +02:00
parent 60d71ae1c0
commit 1a24af7230
Signed by: morrigan
GPG key ID: CACB010F463A77D0
3 changed files with 36 additions and 35 deletions

View file

@ -4,19 +4,18 @@ import "core:fmt"
import "util"
import "vendor:sdl3"
DEFAULT_VELOCITY: util.Velocity : util.Velocity{x = 0, y = 0}
SPEED: f32 : 200
HandleInput :: proc(game: ^Game, event: sdl3.Event) {
effect := event.type == sdl3.EventType.KEY_DOWN ? true : false
game.input_state[event.key.scancode] = effect
}
MovePlayer :: proc(game: ^Game) {
y: f32 = game.input_state[sdl3.Scancode.W] ? -SPEED : 0
y += game.input_state[sdl3.Scancode.S] ? SPEED : 0
x: f32 = game.input_state[sdl3.Scancode.A] ? -SPEED : 0
x += game.input_state[sdl3.Scancode.D] ? SPEED : 0
speed := game.player.speed
y: f32 = game.input_state[sdl3.Scancode.W] ? -speed : 0
y += game.input_state[sdl3.Scancode.S] ? speed : 0
x: f32 = game.input_state[sdl3.Scancode.A] ? -speed : 0
x += game.input_state[sdl3.Scancode.D] ? speed : 0
game.player.velocity = util.Velocity{x, y}
game.player.position.y += y * game.delta