separate out render methods

This commit is contained in:
2026-06-13 23:46:51 -07:00
parent b9235246c7
commit 042fc9fe62
4 changed files with 45 additions and 35 deletions
+18
View File
@@ -1,5 +1,8 @@
package game
import "core:fmt"
import rl "vendor:raylib"
Enemy :: struct {
position: Vec2,
health: int,
@@ -75,3 +78,18 @@ active_enemy_count :: proc(world: ^World) -> int {
return count
}
render_enemies :: proc(world: ^World) {
for i in 0 ..< MAX_ENEMIES {
e := world.enemies[i]
if !e.active do continue
rl.DrawCircle(i32(e.position.x), i32(e.position.y), 11, rl.MAROON)
rl.DrawText(
fmt.ctprintf("%d", e.health),
i32(e.position.x) - 4,
i32(e.position.y) - 18,
12,
rl.WHITE,
)
}
}
+10
View File
@@ -1,5 +1,7 @@
package game
import rl "vendor:raylib"
Projectile :: struct {
active: bool,
position: Vec2,
@@ -65,3 +67,11 @@ update_projectiles :: proc(world: ^World, dt: f32) {
}
}
render_projectiles :: proc(world: ^World) {
for i in 0 ..< MAX_PROJECTILES {
p := world.projectiles[i]
if !p.active do continue
rl.DrawCircle(i32(p.position.x), i32(p.position.y), 4, rl.GOLD)
}
}
+3 -35
View File
@@ -11,41 +11,9 @@ render_world :: proc(world: ^World) {
}
}
for t in world.towers {
rl.DrawRectangle(
i32(t.position.x - 14),
i32(t.position.y - 14),
28,
28,
rl.Color{255, 203, 0, 255},
)
}
for i in 0 ..< MAX_PROJECTILES {
p := world.projectiles[i]
if !p.active do continue
rl.DrawCircle(i32(p.position.x), i32(p.position.y), 4, rl.GOLD)
}
for i in 0 ..< MAX_ENEMIES {
e := world.enemies[i]
if !e.active do continue
rl.DrawCircle(i32(e.position.x), i32(e.position.y), 11, rl.MAROON)
rl.DrawText(
fmt.ctprintf("%d", e.health),
i32(e.position.x) - 4,
i32(e.position.y) - 18,
12,
rl.WHITE,
)
}
for i in 0 ..< MAX_PROJECTILES {
p := world.projectiles[i]
if !p.active do continue
rl.DrawCircle(i32(p.position.x), i32(p.position.y), 4, rl.GOLD)
}
render_enemies(world)
render_towers(world)
render_projectiles(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
+14
View File
@@ -1,5 +1,7 @@
package game
import rl "vendor:raylib"
Tower :: struct {
position: Vec2,
kind: Tower_Kind,
@@ -81,3 +83,15 @@ update_towers :: proc(world: ^World, dt: f32) {
}
}
render_towers :: proc(world: ^World) {
for t in world.towers {
rl.DrawRectangle(
i32(t.position.x - 14),
i32(t.position.y - 14),
28,
28,
rl.Color{255, 203, 0, 255},
)
}
}