Collision detection, better camera stuff, random trees, etc
This commit is contained in:
@@ -7,22 +7,39 @@ Player :: struct {
|
||||
position : rl.Vector2,
|
||||
}
|
||||
|
||||
handle_player_input :: proc(p : ^Player) {
|
||||
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) {
|
||||
p.position.x += CELL_SIZE
|
||||
target_pos.x += 1
|
||||
if !will_collide(target_pos, w) {
|
||||
player.position.x += CELL_SIZE
|
||||
}
|
||||
}
|
||||
|
||||
if rl.IsKeyPressed(.LEFT) {
|
||||
p.position.x -= CELL_SIZE
|
||||
target_pos.x -= 1
|
||||
if !will_collide(target_pos, w) {
|
||||
player.position.x -= CELL_SIZE
|
||||
}
|
||||
}
|
||||
|
||||
if rl.IsKeyPressed(.UP) {
|
||||
p.position.y -= CELL_SIZE
|
||||
target_pos.y -= 1
|
||||
if !will_collide(target_pos, w) {
|
||||
player.position.y -= CELL_SIZE
|
||||
}
|
||||
}
|
||||
|
||||
if rl.IsKeyPressed(.DOWN) {
|
||||
p.position.y += CELL_SIZE
|
||||
target_pos.y += 1
|
||||
if !will_collide(target_pos, w) {
|
||||
player.position.y += CELL_SIZE
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -37,3 +54,18 @@ get_player_grid_position :: proc(player:^Player) -> rl.Vector2 {
|
||||
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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user