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

77 lines
1.9 KiB
Odin

package game
import "core:fmt"
import rl "vendor:raylib"
poll_controls_command :: proc(world: ^World) -> Command {
if world.phase != .Build do return Command{kind = .None}
mouse := game_mouse()
if rl.IsMouseButtonPressed(.LEFT) {
if rl.CheckCollisionPointRec(mouse, ARCHER_BUTTON_RECT) {
world.selected_tower = .Archer
}
if rl.CheckCollisionPointRec(mouse, START_WAVE_BUTTON_RECT) {
return Command{kind = .Start_Wave}
}
}
return Command{kind = .None}
}
draw_archer_button :: proc(world: ^World, archer: rl.Rectangle) {
arch := TOWER_ARCHETYPES[.Archer]
mouse := rl.GetMousePosition()
arch_bg := CONTROLS_SHOP_IDLE
if world.selected_tower == .Archer do arch_bg = CONTROL_SHOP_SELECTED
if rl.CheckCollisionPointRec(mouse, archer) do arch_bg = CONTROLS_SHOP_HOVER
label := fmt.ctprintf("Archer - %dg", arch.cost)
draw_button(archer, label, arch_bg, 14, OVERLAY_TEXT_COLOR)
}
draw_start_wave_button :: proc(start_wave_rect: rl.Rectangle, mouse: rl.Vector2) {
bg := CONTROL_BUTTON_COLOR
if rl.CheckCollisionPointRec(mouse, start_wave_rect) do bg = CONTROL_BUTTON_HOVER
draw_button(start_wave_rect, "Start Wave", bg, 16, OVERLAY_TEXT_COLOR)
}
draw_build_controls :: proc(world: ^World) {
if world.phase != .Build do return
mouse := game_mouse()
rl.DrawRectangle(0, BOTTOM_BAR_Y, SCREEN_W, CONTROL_BAR_H, CONTROL_BAR_BG)
draw_archer_button(world, ARCHER_BUTTON_RECT)
draw_start_wave_button(START_WAVE_BUTTON_RECT, mouse)
}
render_controls :: proc(world: ^World) {
switch world.phase {
case .Build:
draw_build_controls(world)
case .Combat:
draw_combat_banner()
case .Game_Over, .Victory:
}
}
draw_combat_banner :: proc() {
rl.DrawRectangle(0, BOTTOM_BAR_Y, SCREEN_W, CONTROL_BAR_H, rl.Color{120, 40, 40, 200})
text: cstring = "Combat!"
font: i32 = 16
tw := rl.MeasureText(text, font)
rl.DrawText(
text,
(SCREEN_W - tw) / 2,
BOTTOM_BAR_Y + (CONTROL_BAR_H - font) / 2,
font,
rl.Color{255, 220, 220, 255},
)
}