diff --git a/game/commands.odin b/game/commands.odin index 9869ce3..d3633e7 100644 --- a/game/commands.odin +++ b/game/commands.odin @@ -15,6 +15,9 @@ Command :: struct { } gather_commands :: proc(world: ^World) -> Command { + overlay_cmd := poll_overlay_command() + if overlay_cmd.kind != .None do return overlay_cmd + if world.phase == .Build && rl.IsKeyPressed(.N) { return Command{kind = .Start_Wave} } @@ -25,12 +28,6 @@ gather_commands :: proc(world: ^World) -> Command { return Command{kind = .Place_Tower, gx = gx, gy = gy} } - 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} - } - return Command{kind = .None} } diff --git a/game/constants.odin b/game/constants.odin index 176fd21..97c3a99 100644 --- a/game/constants.odin +++ b/game/constants.odin @@ -1,5 +1,7 @@ package game +import clay "../clay-odin" + MAP_W :: 30 // map width in tiles MAP_H :: 20 // map height in tiles TILE_SIZE :: 32 // size of tiles in pixels @@ -17,3 +19,9 @@ MAX_PROJECTILES :: 64 PROJECTILE_SPEED :: 280 // pixels per second PROJECTILE_HIT_RADIUS :: 10 +UI_BAR_COLOR :: clay.Color{20, 40, 20, 200} +UI_TEXT_COLOR :: clay.Color{240, 240, 230, 255} +UI_GOLD_COLOR :: clay.Color{255, 215, 80, 255} +UI_BUTTON_COLOR :: clay.Color{60, 120, 60, 255} +UI_BUTTON_HOVER :: clay.Color{80, 150, 80, 255} + diff --git a/game/hud.odin b/game/hud.odin deleted file mode 100644 index eb9623e..0000000 --- a/game/hud.odin +++ /dev/null @@ -1,50 +0,0 @@ -package game - -import clay "../clay-odin" -import "core:fmt" -import rl "vendor:raylib" - -UI_BAR_COLOR :: clay.Color{20, 40, 20, 200} -UI_TEXT_COLOR :: clay.Color{240, 240, 230, 255} -UI_GOLD_COLOR :: clay.Color{255, 215, 80, 255} - -ui_text_scratch: [64]u8 - -build_hud :: proc(world: ^World) { - if clay.UI(clay.ID("HudBar"))( - { - layout = { - layoutDirection = .LeftToRight, - sizing = {width = clay.SizingGrow({}), height = clay.SizingFixed(28)}, - padding = clay.PaddingAll(6), - childGap = 8, - childAlignment = {y = .Center}, - }, - backgroundColor = UI_BAR_COLOR, - }, - ) { - gold_text := fmt.bprintf(ui_text_scratch[:], "Gold: %d", world.gold) - clay.Text( - gold_text, - clay.TextElementConfig{textColor = UI_GOLD_COLOR, fontId = UI_FONT_ID, fontSize = 18}, - ) - } -} - -render_hud :: proc(world: ^World) { - rl.DrawText(fmt.ctprintf("Base HP: %d", world.base_health), 10, 32, 22, rl.BLACK) - rl.DrawText(fmt.ctprintf("Enemies: %d", active_enemy_count(world)), 10, 54, 22, rl.BLACK) - rl.DrawText(fmt.ctprintf("Wave: %d / %d", world.wave, MAX_WAVES), 10, 76, 22, rl.BLACK) - - switch world.phase { - case .Build: - rl.DrawText("Build - click towers, N = start wave", 10, 98, 22, rl.BLACK) - case .Combat: - rl.DrawText("Combat!", 10, 98, 22, rl.MAROON) - case .Game_Over: - rl.DrawText("GAME_OVER", 260, 280, 40, rl.RED) - case .Victory: - rl.DrawText("Victory!", 260, 280, 40, rl.GREEN) - } -} - diff --git a/game/overlay.odin b/game/overlay.odin new file mode 100644 index 0000000..48b1ef7 --- /dev/null +++ b/game/overlay.odin @@ -0,0 +1,89 @@ +package game + +import clay "../clay-odin" +import "core:fmt" +import rl "vendor:raylib" + +ui_hud_scratch: struct { + gold: [64]u8, + hp: [64]u8, + wave: [64]u8, +} + +build_overlay :: proc(world: ^World) { + if clay.UI(clay.ID("HudBar"))( + { + layout = { + layoutDirection = .LeftToRight, + sizing = {width = clay.SizingGrow({}), height = clay.SizingFixed(28)}, + padding = clay.PaddingAll(6), + childGap = 8, + childAlignment = {y = .Center}, + }, + backgroundColor = UI_BAR_COLOR, + }, + ) { + gold_text := fmt.bprintf(ui_hud_scratch.gold[:], "Gold: %d", world.gold) + clay.Text( + gold_text, + clay.TextElementConfig{textColor = UI_GOLD_COLOR, fontId = UI_FONT_ID, fontSize = 18}, + ) + + hp_text := fmt.bprintf(ui_hud_scratch.hp[:], "Base HP: %d", world.base_health) + clay.Text( + hp_text, + clay.TextElementConfig{textColor = UI_TEXT_COLOR, fontId = UI_FONT_ID, fontSize = 18}, + ) + + wave_text := fmt.bprintf(ui_hud_scratch.wave[:], "Wave: %d / %d", world.wave, MAX_WAVES) + clay.Text( + wave_text, + clay.TextElementConfig{textColor = UI_TEXT_COLOR, fontId = UI_FONT_ID, fontSize = 18}, + ) + + if world.phase == .Build { + if clay.UI(clay.ID("StartWaveBtn"))( + { + layout = { + sizing = {width = clay.SizingFixed(110), height = clay.SizingFixed(22)}, + padding = clay.PaddingAll(4), + childAlignment = {x = .Center, y = .Center}, + }, + backgroundColor = clay.Hovered() ? UI_BUTTON_HOVER : UI_BUTTON_COLOR, + }, + ) { + clay.Text( + "Start Wave", + clay.TextElementConfig { + textColor = UI_TEXT_COLOR, + fontId = UI_FONT_ID, + fontSize = 16, + }, + ) + } + } + } +} + +render_overlay :: proc(world: ^World) { + switch world.phase { + case .Build: + case .Combat: + rl.DrawText("Combat!", 10, 98, 22, rl.MAROON) + case .Game_Over: + rl.DrawText("GAME_OVER", 260, 280, 40, rl.RED) + case .Victory: + rl.DrawText("Victory!", 260, 280, 40, rl.GREEN) + } +} + +poll_overlay_command :: proc() -> Command { + if clay.PointerOver(clay.ID("StartWaveBtn")) { + ptr := clay.GetPointerState() + if ptr.state == .PressedThisFrame { + return Command{kind = .Start_Wave} + } + } + return Command{kind = .None} +} + diff --git a/game/render.odin b/game/render.odin index 708e026..dc3fe1b 100644 --- a/game/render.odin +++ b/game/render.odin @@ -5,5 +5,6 @@ render_world :: proc(world: ^World) { render_enemies(world) render_towers(world) render_projectiles(world) + render_overlay(world) } diff --git a/game/ui.odin b/game/ui.odin index 95ebe2f..14af682 100644 --- a/game/ui.odin +++ b/game/ui.odin @@ -33,7 +33,7 @@ ui_prepare_frame :: proc(world: ^World, dt: f32) { clay.UpdateScrollContainers(false, {}, dt) clay.BeginLayout() - build_hud(world) + build_overlay(world) ui_render_commands = clay.EndLayout(dt) }