From be9fc24cd9346b0aca0f6b22bf45f00f1e654d99 Mon Sep 17 00:00:00 2001 From: codegirl-007 Date: Mon, 29 Jun 2026 00:30:48 -0700 Subject: [PATCH] refactor gold rewards and tower cost; fix wave test leak --- game/constants.odin | 2 -- game/enemy.odin | 4 ++++ game/projectile.odin | 7 +------ game/tower.odin | 4 ++-- game/wave_test.odin | 3 ++- 5 files changed, 9 insertions(+), 11 deletions(-) diff --git a/game/constants.odin b/game/constants.odin index 7ec282b..d7b2406 100644 --- a/game/constants.odin +++ b/game/constants.odin @@ -16,8 +16,6 @@ MAX_ENEMIES :: 64 MAX_WAVES :: 5 MAX_TOWERS :: 32 -TOWER_COST :: 50 - MAX_PROJECTILES :: 64 PROJECTILE_SPEED :: 280 // pixels per second PROJECTILE_HIT_RADIUS :: 10 diff --git a/game/enemy.odin b/game/enemy.odin index eddf54a..9793b0c 100644 --- a/game/enemy.odin +++ b/game/enemy.odin @@ -28,6 +28,7 @@ Enemy_Def :: struct { speed_per_wave: f32, color: rl.Color, draw_radius: f32, + gold_reward: int, } ENEMY_DEF: [Enemy_Kind]Enemy_Def = { @@ -38,6 +39,7 @@ ENEMY_DEF: [Enemy_Kind]Enemy_Def = { speed_per_wave = 5, color = rl.MAROON, draw_radius = 11, + gold_reward = 5, }, .Runner = { base_health = 10, @@ -46,6 +48,7 @@ ENEMY_DEF: [Enemy_Kind]Enemy_Def = { speed_per_wave = 3, color = rl.ORANGE, draw_radius = 11, + gold_reward = 5, }, .Tank = { base_health = 50, @@ -54,6 +57,7 @@ ENEMY_DEF: [Enemy_Kind]Enemy_Def = { speed_per_wave = 2, color = rl.DARKGREEN, draw_radius = 14, + gold_reward = 10, }, } diff --git a/game/projectile.odin b/game/projectile.odin index 1dd21a3..9a51176 100644 --- a/game/projectile.odin +++ b/game/projectile.odin @@ -102,13 +102,8 @@ update_homing_projectile :: proc(world: ^World, p: ^Projectile, dt: f32) { move_toward(&p.position, target.position, p.speed, dt) if distance(p.position, target.position) <= PROJECTILE_HIT_RADIUS { - target.health -= p.damage p.active = false - - if target.health <= 0 { - target.active = false - push_event(world, .Enemy_Killed, gold_reward = 5) - } + apply_tower_hit(world, target, p.damage) } } diff --git a/game/tower.odin b/game/tower.odin index a7f4753..51a92d7 100644 --- a/game/tower.odin +++ b/game/tower.odin @@ -38,7 +38,7 @@ TOWER_ARCHETYPES: [Tower_Kind]Tower_Archetype = { range = 100, damage = 12, fire_rate = 0.45, - cost = TOWER_COST, + cost = 50, footprint_w = 1, footprint_h = 2, max_upgrade = 1, @@ -144,7 +144,7 @@ apply_tower_hit :: proc(world: ^World, target: ^Enemy, damage: int) { target.health -= damage if target.health <= 0 { target.active = false - push_event(world, .Enemy_Killed, gold_reward = 5) + push_event(world, .Enemy_Killed, gold_reward = ENEMY_DEF[target.kind].gold_reward) } } diff --git a/game/wave_test.odin b/game/wave_test.odin index 1fdc85f..621f355 100644 --- a/game/wave_test.odin +++ b/game/wave_test.odin @@ -133,8 +133,9 @@ test_update_phase_from_build_phase :: proc(t: ^testing.T) { } @(test) -test_udpate_phase_from_combat_phase :: proc(t: ^testing.T) { +test_update_phase_from_combat_phase :: proc(t: ^testing.T) { world := World{} + defer delete(world.events) world.phase = .Combat update_phase(&world)