91 lines
2.0 KiB
Odin
91 lines
2.0 KiB
Odin
package game
|
|
|
|
import rl "vendor:raylib"
|
|
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.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
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
get_player_grid_position :: proc(player:^Player) -> rl.Vector2 {
|
|
grid_pos_x := player.position.x / CELL_SIZE
|
|
grid_pos_y := player.position.y / CELL_SIZE
|
|
|
|
return {grid_pos_x, grid_pos_y}
|
|
}
|
|
|
|
draw_player :: proc(player:^Player) {
|
|
draw_tile({27,0}, player.position, rl.DARKBLUE)
|
|
}
|
|
|
|
will_collide :: proc(pos:rl.Vector2, w:^World) -> bool {
|
|
if pos.y > WORLD_SIZE * CELL_SIZE || pos.x > WORLD_SIZE * CELL_SIZE {
|
|
return false
|
|
}
|
|
|
|
tile := get_grid_tile(w, vec2_to_vec2i(pos))
|
|
|
|
#partial switch tile.type {
|
|
case .WALL:
|
|
return true
|
|
}
|
|
|
|
return false
|
|
}
|