Beginning interaction stuff

This commit is contained in:
2025-02-26 09:34:26 -06:00
parent 3914d6c1a7
commit 22f9af5417
5 changed files with 50 additions and 31 deletions

View File

@@ -5,43 +5,62 @@ import "core:fmt"
Player :: struct {
position : rl.Vector2,
move_timer: f32,
mode: InteractMode
}
InteractMode :: enum {
INTERACT,
ATTACK,
}
handle_player_input :: proc(p : ^Player, w: ^World) {
target_pos := get_player_grid_position(p)
dt := rl.GetFrameTime()
move_delay : f32 = 0.15
if p.move_timer > 0 {
p.move_timer -= dt
}
// fmt.printfln("MOVING TO: %v : %v", target_pos, get_grid_tile(w, vec2_to_vec2i(target_pos)).type)
if p.move_timer <= 0 {
if rl.IsKeyDown(.D) {
target_pos.x += 1
if !will_collide(target_pos, w) {
player.position.x += CELL_SIZE
p.move_timer = move_delay
}
}
if rl.IsKeyPressed(.RIGHT) {
target_pos.x += 1
if !will_collide(target_pos, w) {
player.position.x += CELL_SIZE
if rl.IsKeyDown(.A) {
target_pos.x -= 1
if !will_collide(target_pos, w) {
player.position.x -= CELL_SIZE
p.move_timer = move_delay
}
}
if rl.IsKeyDown(.W) {
target_pos.y -= 1
if !will_collide(target_pos, w) {
player.position.y -= CELL_SIZE
p.move_timer = move_delay
}
}
if rl.IsKeyDown(.S) {
target_pos.y += 1
if !will_collide(target_pos, w) {
p.move_timer = move_delay
player.position.y += CELL_SIZE
}
}
}
if rl.IsKeyPressed(.LEFT) {
target_pos.x -= 1
if !will_collide(target_pos, w) {
player.position.x -= CELL_SIZE
}
}
if rl.IsKeyPressed(.UP) {
target_pos.y -= 1
if !will_collide(target_pos, w) {
player.position.y -= CELL_SIZE
}
}
if rl.IsKeyPressed(.DOWN) {
target_pos.y += 1
if !will_collide(target_pos, w) {
player.position.y += CELL_SIZE
}
}
}
get_player_grid_position :: proc(player:^Player) -> rl.Vector2 {