[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

@@ -126,11 +126,15 @@ class Render extends SpriteView implements EngineListener {
}
public function onCollision(entity:EntityType, with:EntityType):Void {
switch [entity, with] {
case [EntityType.BULLET(_), EntityType.EAGLE(eagle)]:
playTankBoom(eagle.rect.center);
case _:
}
}
public function onDestroy(entity:EntityType):Void {
switch(entity) {
switch entity {
case EntityType.TANK(tank):
if (items.exists(tank.key)) {
entryLayer.removeChild(items.get(tank.key).view);
@@ -143,12 +147,6 @@ class Render extends SpriteView implements EngineListener {
items.remove(bullet.key);
playBulletBoom(bullet.rect.center.add(new Point(bullet.rect.width * bullet.rect.direction.x, bullet.rect.height * bullet.rect.direction.y)));
}
case EntityType.EAGLE(eagle):
if (items.exists(eagle.key)) {
cast(items.get(eagle.key), EagleItem).destoyed = true;
items.get(eagle.key).redraw();
playTankBoom(eagle.rect.center);
}
case EntityType.BONUS(bonus):
if (items.exists(bonus.key)) {
entryLayer.removeChild(items.get(bonus.key).view);

View File

@@ -227,10 +227,19 @@ class BulletItem extends BitmapItem<Bullet> {
class EagleItem extends BitmapItem<Eagle> {
public var destoyed(default, default):Bool;
private var death:Bool;
override public function update():Void {
super.update();
var d = value.death;
if (d != death) {
death = d;
redraw();
}
}
override private function getImage():String {
return 'resources/images/eagle/eagle-${destoyed ? 1 : 0}.png';
return 'resources/image/eagle/eagle${value.death ? '-death' : ''}.png';
}
}

View File

Before

Width:  |  Height:  |  Size: 374 B

After

Width:  |  Height:  |  Size: 374 B

View File

Before

Width:  |  Height:  |  Size: 737 B

After

Width:  |  Height:  |  Size: 737 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 93 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 307 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 969 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 598 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 531 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 598 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 304 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 279 B

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):
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(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):
}
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):
case [EntityType.TANK(tank), EntityType.BONUS(bonus)]:
applyBonus(tank, bonus);
case x:
}
case x:
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 _:
}
}