clean up get_archtype for towers and build_controls_layout function, replacing with constants
This commit is contained in:
+26
-24
@@ -3,20 +3,26 @@ package game
|
||||
import "core:fmt"
|
||||
import rl "vendor:raylib"
|
||||
|
||||
bottom_bar_y :: proc() -> i32 {
|
||||
return SCREEN_H - CONTROL_BAR_H
|
||||
BOTTOM_BAR_Y :: SCREEN_H - CONTROL_BAR_H
|
||||
ARCHER_BUTTON_W :: 120
|
||||
START_WAVE_BUTTON_W :: 110
|
||||
CONTROLS_BUTTON_GAP :: 12
|
||||
CONTROLS_BUTTON_H :: 24
|
||||
CONTROLS_BUTTON_Y :: BOTTOM_BAR_Y + 8
|
||||
CONTROLS_BUTTON_X :: (SCREEN_W - (ARCHER_BUTTON_W + CONTROLS_BUTTON_GAP + START_WAVE_BUTTON_W)) / 2
|
||||
|
||||
ARCHER_BUTTON_RECT :: rl.Rectangle {
|
||||
f32(CONTROLS_BUTTON_X),
|
||||
f32(CONTROLS_BUTTON_Y),
|
||||
ARCHER_BUTTON_W,
|
||||
CONTROLS_BUTTON_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
|
||||
START_WAVE_BUTTON_RECT :: rl.Rectangle {
|
||||
f32(CONTROLS_BUTTON_X + ARCHER_BUTTON_W + CONTROLS_BUTTON_GAP),
|
||||
f32(CONTROLS_BUTTON_Y),
|
||||
START_WAVE_BUTTON_W,
|
||||
CONTROLS_BUTTON_H,
|
||||
}
|
||||
|
||||
poll_controls_command :: proc(world: ^World) -> Command {
|
||||
@@ -24,11 +30,10 @@ poll_controls_command :: proc(world: ^World) -> Command {
|
||||
|
||||
mouse := game_mouse()
|
||||
if rl.IsMouseButtonPressed(.LEFT) {
|
||||
archer, start_wave := build_controls_layout()
|
||||
if rl.CheckCollisionPointRec(mouse, archer) {
|
||||
if rl.CheckCollisionPointRec(mouse, ARCHER_BUTTON_RECT) {
|
||||
world.selected_tower = .Archer
|
||||
}
|
||||
if rl.CheckCollisionPointRec(mouse, start_wave) {
|
||||
if rl.CheckCollisionPointRec(mouse, START_WAVE_BUTTON_RECT) {
|
||||
return Command{kind = .Start_Wave}
|
||||
}
|
||||
}
|
||||
@@ -37,7 +42,7 @@ poll_controls_command :: proc(world: ^World) -> Command {
|
||||
}
|
||||
|
||||
draw_archer_button :: proc(world: ^World, archer: rl.Rectangle) {
|
||||
arch := get_archetype(.Archer)
|
||||
arch := TOWER_ARCHETYPES[.Archer]
|
||||
mouse := rl.GetMousePosition()
|
||||
|
||||
arch_bg := CONTROLS_SHOP_IDLE
|
||||
@@ -59,12 +64,10 @@ 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)
|
||||
rl.DrawRectangle(0, BOTTOM_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)
|
||||
draw_archer_button(world, ARCHER_BUTTON_RECT)
|
||||
draw_start_wave_button(START_WAVE_BUTTON_RECT, mouse)
|
||||
}
|
||||
|
||||
render_controls :: proc(world: ^World) {
|
||||
@@ -78,8 +81,7 @@ render_controls :: proc(world: ^World) {
|
||||
}
|
||||
|
||||
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})
|
||||
rl.DrawRectangle(0, BOTTOM_BAR_Y, SCREEN_W, CONTROL_BAR_H, rl.Color{120, 40, 40, 200})
|
||||
|
||||
text: cstring = "Combat!"
|
||||
font: i32 = 16
|
||||
@@ -87,7 +89,7 @@ draw_combat_banner :: proc() {
|
||||
rl.DrawText(
|
||||
text,
|
||||
(SCREEN_W - tw) / 2,
|
||||
bar_y + (CONTROL_BAR_H - font) / 2,
|
||||
BOTTOM_BAR_Y + (CONTROL_BAR_H - font) / 2,
|
||||
font,
|
||||
rl.Color{255, 220, 220, 255},
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user