72 lines
1.5 KiB
Odin
72 lines
1.5 KiB
Odin
package game
|
|
|
|
import rl "vendor:raylib"
|
|
import "core:fmt"
|
|
|
|
Player :: struct {
|
|
position : rl.Vector2,
|
|
}
|
|
|
|
handle_player_input :: proc(p : ^Player, w: ^World) {
|
|
|
|
target_pos := get_player_grid_position(p)
|
|
|
|
// fmt.printfln("MOVING TO: %v : %v", target_pos, get_grid_tile(w, vec2_to_vec2i(target_pos)).type)
|
|
|
|
|
|
if rl.IsKeyPressed(.RIGHT) {
|
|
target_pos.x += 1
|
|
if !will_collide(target_pos, w) {
|
|
player.position.x += 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 {
|
|
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
|
|
}
|