diff --git a/game/game b/game/game index 165654d..cdf8827 100755 Binary files a/game/game and b/game/game differ diff --git a/game/game.odin b/game/game.odin index aaff83a..1d5b546 100644 --- a/game/game.odin +++ b/game/game.odin @@ -9,7 +9,6 @@ player : Player world : World main :: proc() { - if !os.is_dir("data") { os.make_directory("data") } diff --git a/game/interactions.odin b/game/interactions.odin new file mode 100644 index 0000000..8ac3b45 --- /dev/null +++ b/game/interactions.odin @@ -0,0 +1,8 @@ +package game + +import "core:fmt" + +handle_tree_interaction :: proc(w:^World, p:^Player, pos:Vec2i) { + set_tile(w, nothing_tile, pos) + fmt.printfln("Collected Tree from %v", pos) +} diff --git a/game/player.odin b/game/player.odin index 88f06aa..e3d5c05 100644 --- a/game/player.odin +++ b/game/player.odin @@ -15,8 +15,10 @@ Player :: struct { InteractMode :: enum { INTERACT, ATTACK, + STEAL, } +@(private="file") handle_player_camera :: proc(p:^Player) { p.camera.target = {p.position.x + (CELL_SIZE / 2), p.position.y + (CELL_SIZE / 2)} @@ -34,6 +36,7 @@ player_update :: proc(p : ^Player, w: ^World) { } } +@(private="file") player_update_chunks :: proc(p: ^Player, w: ^World) { player_grid_pos := get_player_grid_position(p) current_player_chunk := get_chunk_from_world_pos(w, player_grid_pos) @@ -82,12 +85,13 @@ player_update_chunks :: proc(p: ^Player, w: ^World) { } } +@(private="file") handle_player_input :: proc(p:^Player, w:^World) { + + // Movement target_pos := get_player_grid_position(p) - dt := rl.GetFrameTime() move_delay : f32 = 0.2 - if p.move_timer > 0 { p.move_timer -= dt } @@ -129,9 +133,64 @@ handle_player_input :: proc(p:^Player, w:^World) { } } + // Interactions + if rl.IsKeyPressed(.UP) { + if p.mode == .INTERACT { handle_interact(.UP, p, w) } + if p.mode == .ATTACK { handle_attack(.UP, p, w) } + } + + if rl.IsKeyPressed(.DOWN) { + if p.mode == .INTERACT { handle_interact(.DOWN, p, w) } + if p.mode == .ATTACK { handle_attack(.DOWN, p, w) } + } + + if rl.IsKeyPressed(.LEFT) { + if p.mode == .INTERACT { handle_interact(.LEFT, p, w) } + if p.mode == .ATTACK { handle_attack(.LEFT, p, w) } + } + + if rl.IsKeyPressed(.RIGHT) { + if p.mode == .INTERACT { handle_interact(.RIGHT, p, w) } + if p.mode == .ATTACK { handle_attack(.RIGHT, p, w) } + } + + if rl.IsKeyPressed(.ONE) { p.mode = .INTERACT } + if rl.IsKeyPressed(.TWO) { p.mode = .ATTACK } + if rl.IsKeyPressed(.THREE) { p.mode = .STEAL } } } +@(private="file") +InteractDirection :: enum { + UP, DOWN, LEFT, RIGHT +} + +@(private="file") +handle_interact :: proc(direction:InteractDirection, p:^Player, w:^World) { + tile, pos := get_tile_in_direction(direction, p, w) + + if tile.interaction == .RESOURCE && tile.resource != .NOTHING { + if tile.resource == .TREE { handle_tree_interaction(w, p, pos) } + } +} + +@(private="file") +handle_attack :: proc(direction:InteractDirection, p:^Player, w:^World) { + tile, pos := get_tile_in_direction(direction, p, w) +} + +@(private="file") +get_tile_in_direction :: proc(direction:InteractDirection, p:^Player, w:^World) -> (^Tile, Vec2i) { + grid_pos := get_player_grid_position(p) + + if direction == .UP { grid_pos.y -= 1 } + if direction == .DOWN { grid_pos.y += 1 } + if direction == .LEFT { grid_pos.x -= 1 } + if direction == .RIGHT { grid_pos.x += 1 } + + return get_world_tile(w, vec2_to_vec2i(grid_pos)), vec2_to_vec2i(grid_pos) +} + 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 @@ -143,6 +202,7 @@ draw_player :: proc(player:^Player) { draw_tile({27,0}, player.position, rl.DARKBLUE) } + will_collide :: proc(w:^World, pos:rl.Vector2) -> bool { world_grid_pos := vec2_to_vec2i(pos) chunk_pos := world_pos_to_chunk_pos(pos) @@ -152,7 +212,7 @@ will_collide :: proc(w:^World, pos:rl.Vector2) -> bool { tile := get_chunk_tile(chunk, local_pos) #partial switch tile.type { - case .WALL: + case .SOLID: return true } diff --git a/game/tiles.odin b/game/tiles.odin index 36fffe6..b18e1a6 100644 --- a/game/tiles.odin +++ b/game/tiles.odin @@ -13,7 +13,7 @@ Tile :: struct #packed { TileType :: enum u8 { NOTHING, - WALL, + SOLID, FOLIAGE, } @@ -37,7 +37,7 @@ nothing_tile := Tile { } tree_tile := Tile { - type = .WALL, + type = .SOLID, tilemap_pos = {0,1}, color = {17,87,30,255}, resource = .TREE,