96 lines
2.4 KiB
Odin
96 lines
2.4 KiB
Odin
package game
|
|
|
|
import "core:fmt"
|
|
import rl "vendor:raylib"
|
|
|
|
bottom_bar_y :: proc() -> i32 {
|
|
return SCREEN_H - CONTROL_BAR_H
|
|
}
|
|
|
|
build_controls_layout :: proc() -> (archer, start_wave_btn: rl.Rectangle) {
|
|
bar_y := f32(bottom_bar_y())
|
|
arch_w: f32 = 120
|
|
wave_w: f32 = 110
|
|
gap: f32 = 12
|
|
|
|
x := f32((SCREEN_W - int(arch_w + gap + wave_w)) / 2)
|
|
archer = {x, bar_y + 8, arch_w, 24}
|
|
start_wave_btn = {x + arch_w + gap, bar_y + 8, wave_w, 24}
|
|
return
|
|
}
|
|
|
|
poll_controls_command :: proc(world: ^World) -> Command {
|
|
if world.phase != .Build do return Command{kind = .None}
|
|
|
|
mouse := game_mouse()
|
|
if rl.IsMouseButtonPressed(.LEFT) {
|
|
archer, start_wave := build_controls_layout()
|
|
if rl.CheckCollisionPointRec(mouse, archer) {
|
|
world.selected_tower = .Archer
|
|
}
|
|
if rl.CheckCollisionPointRec(mouse, start_wave) {
|
|
return Command{kind = .Start_Wave}
|
|
}
|
|
}
|
|
|
|
return Command{kind = .None}
|
|
}
|
|
|
|
draw_archer_button :: proc(world: ^World, archer: rl.Rectangle) {
|
|
arch := get_archetype(.Archer)
|
|
mouse := game_mouse()
|
|
|
|
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()
|
|
|
|
bar_y := bottom_bar_y()
|
|
rl.DrawRectangle(0, bar_y, SCREEN_W, CONTROL_BAR_H, CONTROL_BAR_BG)
|
|
|
|
archer, start_wave_rect := build_controls_layout()
|
|
draw_archer_button(world, archer)
|
|
draw_start_wave_button(start_wave_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() {
|
|
bar_y := bottom_bar_y()
|
|
rl.DrawRectangle(0, 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,
|
|
bar_y + (CONTROL_BAR_H - font) / 2,
|
|
font,
|
|
rl.Color{255, 220, 220, 255},
|
|
)
|
|
}
|
|
|