Beginning interaction stuff
This commit is contained in:
parent
3914d6c1a7
commit
22f9af5417
@ -23,6 +23,7 @@ main :: proc() {
|
||||
|
||||
player.position.x = CELL_SIZE * 5
|
||||
player.position.y = CELL_SIZE * 5
|
||||
player.mode = .INTERACT
|
||||
|
||||
camera.target = {player.position.x + (CELL_SIZE / 2), player.position.y + (CELL_SIZE / 2)}
|
||||
camera.zoom = 2
|
||||
@ -59,9 +60,9 @@ game_loop :: proc() {
|
||||
|
||||
player_grid_pos := get_player_grid_position(&player)
|
||||
player_grid_pos_tile := get_grid_tile(&world, vec2_to_vec2i(player_grid_pos))
|
||||
pos_string := rl.TextFormat("POS: %v : %v", player_grid_pos, player_grid_pos_tile.type)
|
||||
status_string := rl.TextFormat("POS: %v : %v | MODE: %v", player_grid_pos, player_grid_pos_tile.type, player.mode)
|
||||
|
||||
rl.DrawText(pos_string, 5, 25, 20, rl.RED)
|
||||
rl.DrawText(status_string, 5, 25, 20, rl.RED)
|
||||
|
||||
|
||||
rl.EndDrawing()
|
||||
|
@ -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 {
|
||||
|
@ -15,7 +15,7 @@ place_random_trees :: proc(w:^World) {
|
||||
|
||||
chance := rand.int_max(100)
|
||||
|
||||
if chance <= 10 {
|
||||
if chance <= 5 {
|
||||
w.grid[x][y] = tree_tile
|
||||
}
|
||||
}
|
||||
|
@ -5,7 +5,7 @@ import "core:fmt"
|
||||
|
||||
|
||||
CELL_SIZE :: 16
|
||||
WORLD_SIZE :: 50
|
||||
WORLD_SIZE :: 100
|
||||
|
||||
World :: struct {
|
||||
grid: [WORLD_SIZE][WORLD_SIZE]Tile
|
||||
@ -24,7 +24,6 @@ TileType :: enum {
|
||||
FLOOR,
|
||||
}
|
||||
|
||||
|
||||
set_grid_tile :: proc(w:^World, pos:Vec2i, t:Tile) {
|
||||
w.grid[pos.x][pos.y] = t
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user