diff --git a/game/game b/game/game index 0faf6ac..77ea0fd 100755 Binary files a/game/game and b/game/game differ diff --git a/game/game.odin b/game/game.odin index aa216c6..f405e7a 100644 --- a/game/game.odin +++ b/game/game.odin @@ -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() diff --git a/game/player.odin b/game/player.odin index 9a5c1d2..40e4b4f 100644 --- a/game/player.odin +++ b/game/player.odin @@ -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 { diff --git a/game/tiles.odin b/game/tiles.odin index d096885..ac610ba 100644 --- a/game/tiles.odin +++ b/game/tiles.odin @@ -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 } } diff --git a/game/world.odin b/game/world.odin index 2fc67da..616e2af 100644 --- a/game/world.odin +++ b/game/world.odin @@ -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 }