From 042fc9fe6268216d8bccaefc54e01743b7091e43 Mon Sep 17 00:00:00 2001 From: codegirl-007 Date: Sat, 13 Jun 2026 23:46:51 -0700 Subject: [PATCH] separate out render methods --- game/enemy.odin | 18 ++++++++++++++++++ game/projectile.odin | 10 ++++++++++ game/render.odin | 38 +++----------------------------------- game/tower.odin | 14 ++++++++++++++ 4 files changed, 45 insertions(+), 35 deletions(-) diff --git a/game/enemy.odin b/game/enemy.odin index 221d54d..0e90100 100644 --- a/game/enemy.odin +++ b/game/enemy.odin @@ -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, + ) + } +} + diff --git a/game/projectile.odin b/game/projectile.odin index 345cee6..c1617ea 100644 --- a/game/projectile.odin +++ b/game/projectile.odin @@ -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) + } +} + diff --git a/game/render.odin b/game/render.odin index 0de875c..b6f9698 100644 --- a/game/render.odin +++ b/game/render.odin @@ -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 diff --git a/game/tower.odin b/game/tower.odin index 7b0e40d..75e5797 100644 --- a/game/tower.odin +++ b/game/tower.odin @@ -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}, + ) + } +} +