package game import rl "vendor:raylib" Command_Kind :: enum { None, Place_Tower, Start_Wave, Upgrade_Tower, } Command :: struct { kind: Command_Kind, gx: int, gy: int, } gather_commands :: proc(world: ^World) -> Command { ui_cmd := poll_controls_command(world) if ui_cmd.kind != .None do return ui_cmd if rl.IsKeyPressed(.ONE) do world.selected_tower = .Archer if rl.IsKeyPressed(.TWO) do world.selected_tower = .Cannon if rl.IsKeyPressed(.THREE) do world.selected_tower = .Ice if world.phase == .Build && rl.IsKeyPressed(.N) { return Command{kind = .Start_Wave} } if rl.IsMouseButtonPressed(.RIGHT) { mouse := game_mouse() gx, gy := screen_to_grid(mouse.x, mouse.y) return Command{kind = .Upgrade_Tower, gx = gx, gy = gy} } if world.phase == .Build && rl.IsMouseButtonPressed(.LEFT) { mouse := game_mouse() gx, gy := screen_to_grid(mouse.x, mouse.y) return Command{kind = .Place_Tower, gx = gx, gy = gy} } return Command{kind = .None} } execute_command :: proc(world: ^World, cmd: Command) { switch cmd.kind { case .None: case .Place_Tower: try_place_tower(world, cmd.gx, cmd.gy, world.selected_tower) case .Start_Wave: start_wave(world) case .Upgrade_Tower: try_upgrade_tower(world, cmd.gx, cmd.gy) } }