add cannon - no projectiles, no control button
This commit is contained in:
+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