Remove Clay and associated changes

This commit is contained in:
2026-06-18 00:56:44 -07:00
committed by GitHub
parent d097e36419
commit c8d191e7c7
14 changed files with 32 additions and 819 deletions
+2 -5
View File
@@ -7,26 +7,23 @@ run :: proc() {
defer rl.CloseWindow()
rl.SetTargetFPS(60)
init_ui()
defer destroy_ui()
world := init_world()
for !rl.WindowShouldClose() {
dt := rl.GetFrameTime()
ui_prepare_frame(&world, dt)
update_world(&world, dt)
rl.BeginDrawing()
rl.ClearBackground(rl.Color{34, 139, 34, 255})
render_world(&world)
render_ui()
rl.EndDrawing()
}
delete(world.path)
delete(world.towers)
delete(world.events)
}
+6 -3
View File
@@ -15,9 +15,6 @@ 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}
}
@@ -28,6 +25,12 @@ 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}
}
-8
View File
@@ -1,7 +1,5 @@
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
@@ -19,9 +17,3 @@ 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}
+23
View File
@@ -0,0 +1,23 @@
package game
import "core:fmt"
import rl "vendor:raylib"
render_hud :: proc(world: ^World) {
rl.DrawText(fmt.ctprintf("Gold: %d", world.gold), 10, 10, 22, rl.BLACK) // Gold HUD
rl.DrawText(fmt.ctprintf("Base HP: %d", world.base_health), 10, 32, 22, rl.BLACK) // HP HUD
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)
}
}
-89
View File
@@ -1,89 +0,0 @@
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}
}
+1 -1
View File
@@ -5,6 +5,6 @@ render_world :: proc(world: ^World) {
render_enemies(world)
render_towers(world)
render_projectiles(world)
render_overlay(world)
render_hud(world)
}
-43
View File
@@ -1,43 +0,0 @@
package game
import clay "../clay-odin"
import rl "vendor:raylib"
ui_memory: [^]u8
ui_arena: clay.Arena
ui_render_commands: clay.ClayArray(clay.RenderCommand)
ui_error_handler :: proc "c" (data: clay.ErrorData) {
_ = data
}
init_ui :: proc() {
ui_register_font()
min_size := clay.MinMemorySize()
ui_memory = make([^]u8, min_size)
ui_arena = clay.CreateArenaWithCapacityAndMemory(uint(min_size), ui_memory)
clay.Initialize(ui_arena, {f32(SCREEN_W), f32(SCREEN_H)}, {handler = ui_error_handler})
clay.SetMeasureTextFunction(measure_text, nil)
}
destroy_ui :: proc() {
free(ui_memory)
}
ui_prepare_frame :: proc(world: ^World, dt: f32) {
mouse := rl.GetMousePosition()
clay.SetLayoutDimensions({f32(SCREEN_W), f32(SCREEN_H)})
clay.SetPointerState({mouse.x, mouse.y}, rl.IsMouseButtonDown(.LEFT))
clay.UpdateScrollContainers(false, {}, dt)
clay.BeginLayout()
build_overlay(world)
ui_render_commands = clay.EndLayout(dt)
}
render_ui :: proc() {
clay_raylib_render(&ui_render_commands)
}
-69
View File
@@ -1,69 +0,0 @@
package game
import clay "../clay-odin"
import "core:math"
import "core:strings"
import rl "vendor:raylib"
UI_FONT_ID :: 0
ui_font: rl.Font
ui_register_font :: proc() {
ui_font = rl.GetFontDefault()
}
clay_color_to_rl :: proc(c: clay.Color) -> rl.Color {
return {u8(c.r), u8(c.g), u8(c.b), u8(c.a)}
}
measure_text :: proc "c" (
text: clay.StringSlice,
config: ^clay.TextElementConfig,
_: rawptr,
) -> clay.Dimensions {
return {width = f32(text.length) * f32(config.fontSize) * 0.55, height = f32(config.fontSize)}
}
clay_raylib_render :: proc(commands: ^clay.ClayArray(clay.RenderCommand)) {
for i in 0 ..< commands.length {
cmd := clay.RenderCommandArray_Get(commands, i)
bounds := cmd.boundingBox
#partial switch cmd.commandType {
case .None:
case .Text:
cfg := cmd.renderData.text
text := string(cfg.stringContents.chars[:cfg.stringContents.length])
cstr := strings.clone_to_cstring(text, context.temp_allocator)
rl.DrawTextEx(
ui_font,
cstr,
{bounds.x, bounds.y},
f32(cfg.fontSize),
f32(cfg.letterSpacing),
clay_color_to_rl(cfg.textColor),
)
case .Rectangle:
cfg := cmd.renderData.rectangle
rl.DrawRectangle(
i32(math.round(bounds.x)),
i32(math.round(bounds.y)),
i32(math.round(bounds.width)),
i32(math.round(bounds.height)),
clay_color_to_rl(cfg.backgroundColor),
)
case .ScissorStart:
rl.BeginScissorMode(
i32(math.round(bounds.x)),
i32(math.round(bounds.y)),
i32(math.round(bounds.width)),
i32(math.round(bounds.height)),
)
case .ScissorEnd:
rl.EndScissorMode()
}
}
}