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

41 lines
706 B
Odin

package game
import rl "vendor:raylib"
Command_Kind :: enum {
None,
Place_Tower,
Spawn_Test,
}
Command :: struct {
kind: Command_Kind,
gx: int,
gy: int,
}
gather_commands :: proc(world: ^World) -> Command {
if rl.IsMouseButtonPressed(.LEFT) {
mouse := rl.GetMousePosition()
gx, gy := screen_to_grid(mouse.x, mouse.y)
return Command{kind = .Place_Tower, gx = gx, gy = gy}
}
if rl.IsKeyPressed(.SPACE) {
return Command{kind = .Spawn_Test}
}
return Command{kind = .None}
}
execute_command :: proc(world: ^World, cmd: Command) {
switch cmd.kind {
case .None:
case .Spawn_Test:
spawn_group(world, 3)
case .Place_Tower:
try_place_tower(world, cmd.gx, cmd.gy, .Archer)
}
}