[common] added Eagle death flag

This commit is contained in:
2018-02-13 16:59:01 +03:00
parent 05b6fe4a56
commit 592e59e01f
15 changed files with 49 additions and 59 deletions

View File

@@ -7,9 +7,11 @@ import ru.m.tankz.Type;
class Eagle extends Entity {
public var team(default, null):TeamId;
public var death(default, default):Bool;
public function new(team:TeamId) {
super(new Rectangle(0, 0, 44, 44));
this.team = team;
this.death = false;
}
}

View File

@@ -12,14 +12,12 @@ import ru.m.tankz.core.Tank;
import ru.m.tankz.map.LevelMap;
interface EngineListener {
public function onSpawn(entity:EntityType):Void;
public function onCollision(entity:EntityType, with:EntityType):Void;
public function onDestroy(entity:EntityType):Void;
}
class CollisionProcessor implements EngineListener {
private var engine:Engine;
@@ -44,40 +42,27 @@ class CollisionProcessor implements EngineListener {
}
public function onCollision(entity:EntityType, with:EntityType):Void {
switch (entity) {
case EntityType.TANK(tank1):
switch (with) {
case EntityType.TANK(tank2):
tank1.rect.lean(tank2.rect);
case EntityType.BULLET(bullet2):
if (checkTankBullet(tank1, bullet2)) {
hitTank(tank1);
engine.destroy(bullet2);
}
case EntityType.EAGLE(eagle):
tank1.rect.lean(eagle.rect);
case EntityType.CELL(cell):
tank1.rect.lean(cell.rect);
case EntityType.BONUS(bonus):
engine.destroy(bonus);
}
case EntityType.BULLET(bullet1):
switch (with) {
case EntityType.TANK(tank2):
if (checkTankBullet(tank2, bullet1)) {
engine.destroy(bullet1);
hitTank(tank2);
}
case EntityType.BULLET(bullet2):
engine.destroy(bullet1);
engine.destroy(bullet2);
case EntityType.EAGLE(eagle):
engine.destroy(bullet1);
engine.destroy(eagle);
case EntityType.CELL(cell):
engine.destroy(bullet1);
case EntityType.BONUS(bonus):
switch [entity, with] {
case [EntityType.TANK(tank), EntityType.TANK(other_tank)]:
tank.rect.lean(other_tank.rect);
case [EntityType.TANK(tank), EntityType.EAGLE(eagle)]:
tank.rect.lean(eagle.rect);
case [EntityType.TANK(tank), EntityType.BONUS(bonus)]:
engine.destroy(bonus);
case [EntityType.TANK(tank), EntityType.BULLET(bullet)] |
[EntityType.BULLET(bullet), EntityType.TANK(tank)]:
if (checkTankBullet(tank, bullet)) {
hitTank(tank);
engine.destroy(bullet);
}
case [EntityType.BULLET(bullet), EntityType.BULLET(other_bullet)]:
engine.destroy(bullet);
engine.destroy(other_bullet);
case [EntityType.BULLET(bullet), EntityType.CELL(cell)]:
engine.destroy(bullet);
case [EntityType.BULLET(bullet), EntityType.EAGLE(eagle)]:
engine.destroy(bullet);
eagle.death = true;
case _:
}
}
@@ -85,7 +70,6 @@ class CollisionProcessor implements EngineListener {
public function onDestroy(entity:EntityType):Void { }
}
class Engine implements ControlHandler {
public var config(default, default):Config;

View File

@@ -150,21 +150,21 @@ class Game implements EngineListener {
switch (entity) {
case EntityType.TANK(tank):
getPlayer(tank.playerId).control.start();
case x:
case _:
}
}
public function onCollision(entity:EntityType, with:EntityType):Void {
switch (entity) {
case EntityType.TANK(tank):
switch [entity, with] {
case [EntityType.TANK(tank), _]:
var control = getPlayer(tank.playerId).control;
if (control != null) control.onCollision(with);
switch (with) {
case EntityType.BONUS(bonus):
applyBonus(tank, bonus);
case x:
}
case x:
case [EntityType.TANK(tank), EntityType.BONUS(bonus)]:
applyBonus(tank, bonus);
case [EntityType.BULLET(_), EntityType.EAGLE(eagle)]:
lose(eagle.team);
deferred.resolve(state);
case _:
}
}
@@ -184,10 +184,7 @@ class Game implements EngineListener {
}
if (tank.bonus) spawnBonus();
deferred.resolve(state);
case EntityType.EAGLE(eagle):
lose(eagle.team);
deferred.resolve(state);
case x:
case _:
}
}