add cannon - no projectiles, no control button
This commit is contained in:
@@ -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}
|
||||
}
|
||||
|
||||
+1
-1
@@ -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
|
||||
|
||||
+34
-2
@@ -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,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user