Files
tower-defense-prototype/game/commands.odin
T

44 lines
831 B
Odin

package game
import rl "vendor:raylib"
Command_Kind :: enum {
None,
Place_Tower,
Start_Wave,
}
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 world.phase == .Build && rl.IsKeyPressed(.N) {
return Command{kind = .Start_Wave}
}
if world.phase == .Build && rl.IsMouseButtonPressed(.LEFT) {
mouse := rl.GetMousePosition()
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, .Archer)
case .Start_Wave:
start_wave(world)
}
}