Снаряды
Снаряд на основе триггера
Damageable :: class : Component {
health: float = 100 @ao_serialize;
take_damage :: method(amount: float) {
health -= amount;
}
}
Projectile :: class : Component {
direction: v2;
owner: Entity;
speed: float = 12 @ao_serialize;
damage: float = 25 @ao_serialize;
lifetime: float = 3 @ao_serialize;
spent: bool;
ao_start :: method() {
collider := entity.get_component(Circle_Collider);
collider.is_trigger = true;
collider.on_trigger_start = proc(self: Collider, other: Collider) {
projectile := self.entity.get_component(Projectile);
projectile.hit(other.entity);
};
entity.queue_for_destruction(lifetime);
}
ao_update :: method(dt: float) {
entity.add_local_position(direction * speed * dt);
}
hit :: method(other: Entity) {
if spent return;
if other == owner return;
target := other.get_component(Damageable);
if target == null return;
spent = true;
target.take_damage(damage);
entity.destroy();
}
}Быстрые снаряды
Последнее обновление