[client] fix tank destroy zero score label

This commit is contained in:
2019-06-11 15:31:13 +03:00
parent ee5de9f3db
commit a49d673f25
7 changed files with 54 additions and 92 deletions

View File

@@ -187,7 +187,7 @@ class Render extends SpriteView implements IRender {
var item = items[id];
entryLayer.removeChild(item.view);
playAnimate(item.rect.center, AnimateBundle.tankBoom());
if (shot.score != 0) {
if (shot.score != null) {
showScore(item.rect.center, shot.score);
}
items.remove(id);
@@ -206,7 +206,7 @@ class Render extends SpriteView implements IRender {
if (items.exists(id)) {
var item = items[id];
playAnimate(item.rect.center, AnimateBundle.tankBoom());
if (shot.score != 0) {
if (shot.score != null) {
showScore(item.rect.center, shot.score);
}
cast(item, EagleRenderItem).death = true;
@@ -215,7 +215,7 @@ class Render extends SpriteView implements IRender {
if (items.exists(id)) {
var item = items[id];
upperLayer.removeChild(item.view);
if (shot.score != 0) {
if (shot.score != null) {
showScore(item.rect.center, shot.score);
}
items.remove(id);

View File

@@ -55,13 +55,13 @@ typedef TankConfig = {
@:optinal var hits:Int;
@:optinal var upgrade:TankType;
@:optinal var downgrade:TankType;
@:optinal var score:Int;
@:optinal var score:Null<Int>;
}
typedef BonusConfig = {
var type:BonusType;
@:optional var duration:Int;
@:optinal var score:Int;
@:optional var duration:Null<Int>;
@:optinal var score:Null<Int>;
}
typedef TankSpawn = {
@@ -80,7 +80,7 @@ typedef PlayerConfig = {
}
typedef EagleConfig = {
@:optional var score:Int;
@:optional var score:Null<Int>;
}
typedef TeamConfig = {

View File

@@ -32,8 +32,8 @@ enum SpawnEvent {
typedef Shot = {
var tankId:Int;
@:optional var bulletId:Int;
@:optional var score:Int;
@:optional var bulletId:Null<Int>;
@:optional var score:Null<Int>;
}
enum HitEvent {

View File

@@ -68,7 +68,7 @@ class GameRunner extends Game implements EngineListener {
}
gameEventSignal.emit(EventUtil.buildBricksSpawn(engine.map));
gameEventSignal.emit(START(state));
//for (i in 0...10) spawnBonus();
//for (i in 0...10) spawnBonus("grenade");
}
private function spawn(task:SpawnTask):Void {
@@ -138,7 +138,7 @@ class GameRunner extends Game implements EngineListener {
public function onSpawn(entity:EntityType):Void {
}
private static function buildShot(bullet:Bullet, score:Int = 0):Shot {
private static function buildShot(bullet:Bullet, score:Null<Int> = null):Shot {
return {
tankId: bullet.tank.id,
bulletId: bullet.id,
@@ -200,7 +200,7 @@ class GameRunner extends Game implements EngineListener {
emitTankChange(tank);
} else {
var score = tank.config.score;
if (tank.playerId.team == bullet.playerId.team) {
if (score != null && tank.playerId.team == bullet.playerId.team) {
score = Math.round(score * -0.5);
}
gameEventSignal.emit(DESTROY(TANK(tank.id, buildShot(bullet, score))));
@@ -230,8 +230,10 @@ class GameRunner extends Game implements EngineListener {
public function onDestroy(entity:EntityType):Void {
}
private function spawnBonus():Void {
var type = config.bonuses[Math.floor(Math.random() * config.bonuses.length)].type;
private function spawnBonus(type:BonusType = null):Void {
if (type == null) {
type = config.bonuses[Math.floor(Math.random() * config.bonuses.length)].type;
}
var point = {
x: Math.floor(Math.random() * (engine.map.gridWidth - 1)),
y: Math.floor(Math.random() * (engine.map.gridHeight - 1)),
@@ -350,7 +352,7 @@ class GameRunner extends Game implements EngineListener {
case DESTROY(EAGLE(id, shot)):
var eagle:Eagle = engine.getEntity(id);
eagle.death = true;
if (shot.score != 0) {
if (shot.score != null) {
var tank:Tank = engine.getEntity(shot.tankId);
changeScore(tank.playerId, shot.score);
}
@@ -376,7 +378,7 @@ class GameRunner extends Game implements EngineListener {
if (tank.bonus && shot.bulletId != null) {
spawnBonus();
}
if (shot.score != 0) {
if (shot.score != null) {
var shooterTank:Tank = engine.getEntity(shot.tankId);
changeScore(shooterTank.playerId, shot.score);
}
@@ -385,7 +387,7 @@ class GameRunner extends Game implements EngineListener {
var bonus:Bonus = engine.getEntity(id);
var tank:Tank = engine.getEntity(shot.tankId);
applyBonus(tank, bonus);
if (shot.score != 0) {
if (shot.score != null) {
changeScore(tank.playerId, shot.score);
}
engine.destroy(id);

View File

@@ -40,8 +40,7 @@ team:
players:
- {<<: *human, index: 0, color: 0xFFFF00, control: 'null'}
- {<<: *human, index: 1, color: 0x15C040, control: 'null'}
eagle:
score: 0
eagle: {}
points:
- {team: human, type: eagle, index: -1, direction: right, x: 12, y: 24}