From 0815530717d8838b405b1ccda8bc832c54b18bea Mon Sep 17 00:00:00 2001 From: codegirl-007 Date: Tue, 23 Jun 2026 00:39:18 -0700 Subject: [PATCH] add cannon - no projectiles, no control button --- game/commands.odin | 2 ++ game/controls.odin | 2 +- game/tower.odin | 36 ++++++++++++++++++++++++++++++++++-- 3 files changed, 37 insertions(+), 3 deletions(-) diff --git a/game/commands.odin b/game/commands.odin index 4e45811..a07704e 100644 --- a/game/commands.odin +++ b/game/commands.odin @@ -18,6 +18,8 @@ gather_commands :: proc(world: ^World) -> Command { ui_cmd := poll_controls_command(world) if ui_cmd.kind != .None do return ui_cmd + if rl.IsKeyPressed(.ONE) do world.selected_tower = .Archer + if rl.IsKeyPressed(.TWO) do world.selected_tower = .Cannon if world.phase == .Build && rl.IsKeyPressed(.N) { return Command{kind = .Start_Wave} } diff --git a/game/controls.odin b/game/controls.odin index 55472b7..d4a995a 100644 --- a/game/controls.odin +++ b/game/controls.odin @@ -38,7 +38,7 @@ poll_controls_command :: proc(world: ^World) -> Command { draw_archer_button :: proc(world: ^World, archer: rl.Rectangle) { arch := get_archetype(.Archer) - mouse := game_mouse() + mouse := rl.GetMousePosition() arch_bg := CONTROLS_SHOP_IDLE if world.selected_tower == .Archer do arch_bg = CONTROL_SHOP_SELECTED diff --git a/game/tower.odin b/game/tower.odin index 8f2ae25..4471b5a 100644 --- a/game/tower.odin +++ b/game/tower.odin @@ -12,6 +12,7 @@ Tower :: struct { Tower_Kind :: enum { Archer, + Cannon, } Tower_Archetype :: struct { @@ -34,6 +35,15 @@ TOWER_ARCHETYPES: [Tower_Kind]Tower_Archetype = { footprint_w = 1, footprint_h = 2, }, + .Cannon = { + kind = .Cannon, + range = 110, + damage = 35, + fire_rate = 1.2, + cost = 80, + footprint_w = 2, + footprint_h = 2, + }, } rects_overlap :: proc( @@ -152,22 +162,44 @@ update_towers :: proc(world: ^World, dt: f32) { switch t.kind { case .Archer: spawn_projectile(world, t.position, slot, arch.damage) - t.cooldown = arch.fire_rate + case .Cannon: + if target := enemy_at_slot(world, slot); target != nil { + apply_tower_hit(world, target, arch.damage) + } } + t.cooldown = arch.fire_rate } } +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) + } +} + +enemy_at_slot :: proc(world: ^World, slot: int) -> ^Enemy { + if slot < 0 || slot >= MAX_ENEMIES do return nil + + e := &world.enemies[slot] + if !e.active do return nil + return e +} + render_towers :: proc(world: ^World) { for t in world.towers { archetype := get_archetype(t.kind) pixel_width := f32(archetype.footprint_w * TILE_SIZE) pixel_height := f32(archetype.footprint_h * TILE_SIZE) + color := rl.Color{255, 203, 0, 255} + if t.kind == .Cannon do color = rl.DARKGRAY rl.DrawRectangle( i32(t.position.x - pixel_width * 0.5), i32(t.position.y - pixel_height * 0.5), i32(pixel_width), i32(pixel_height), - rl.Color{255, 203, 0, 255}, + color, ) } }