[render] show scores
This commit is contained in:
@@ -58,6 +58,7 @@ class JsConnection<O:Message, I:Message> extends BaseConnection<O, I> {
|
||||
private function onConnect(_):Void {
|
||||
connected = true;
|
||||
handler.emit(ConnectionEvent.CONNECTED);
|
||||
connectDeferred.resolve(this);
|
||||
}
|
||||
|
||||
private function onClose(_):Void {
|
||||
|
||||
@@ -50,11 +50,13 @@ typedef TankConfig = {
|
||||
var skin:String;
|
||||
@:optinal var upgrade:TankType;
|
||||
@:optinal var downgrade:TankType;
|
||||
@:optinal var score:Int;
|
||||
}
|
||||
|
||||
typedef BonusConfig = {
|
||||
var type:BonusType;
|
||||
@:optional var duration:Int;
|
||||
@:optinal var score:Int;
|
||||
}
|
||||
|
||||
typedef TankSpawn = {
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package ru.m.tankz.engine;
|
||||
|
||||
import ru.m.signal.Signal;
|
||||
import ru.m.geom.Line;
|
||||
import ru.m.geom.Point;
|
||||
import ru.m.signal.Signal;
|
||||
import ru.m.tankz.config.Config;
|
||||
import ru.m.tankz.control.Control;
|
||||
import ru.m.tankz.core.Bullet;
|
||||
@@ -11,6 +11,7 @@ import ru.m.tankz.core.EntityType;
|
||||
import ru.m.tankz.core.MobileEntity;
|
||||
import ru.m.tankz.core.Tank;
|
||||
import ru.m.tankz.map.LevelMap;
|
||||
import ru.m.tankz.Type;
|
||||
|
||||
|
||||
enum EntityChange {
|
||||
@@ -24,7 +25,7 @@ enum EntityChange {
|
||||
typedef EngineListener = {
|
||||
public function onSpawn(entity:EntityType):Void;
|
||||
public function onCollision(entity:EntityType, with:EntityType):Void;
|
||||
public function onDestroy(entity:EntityType):Void;
|
||||
public function onDestroy(entity:EntityType, ?playerId:PlayerId):Void;
|
||||
public function onChange(entity:EntityType, change:EntityChange):Void;
|
||||
}
|
||||
|
||||
@@ -44,7 +45,7 @@ class CollisionProcessor {
|
||||
case [EntityType.TANK(tank), EntityType.EAGLE(eagle)]:
|
||||
tank.rect.lean(eagle.rect);
|
||||
case [EntityType.TANK(tank), EntityType.BONUS(bonus)]:
|
||||
engine.destroy(bonus);
|
||||
engine.destroy(bonus, tank.playerId);
|
||||
case [EntityType.TANK(tank), EntityType.BULLET(bullet)] |
|
||||
[EntityType.BULLET(bullet), EntityType.TANK(tank)]:
|
||||
if (bullet.tankId == tank.id || (!engine.config.game.friendlyFire && tank.playerId.team == bullet.playerId.team)) {
|
||||
@@ -58,7 +59,7 @@ class CollisionProcessor {
|
||||
tank.hits--;
|
||||
engine.change(tank, EntityChange.HIT);
|
||||
} else {
|
||||
engine.destroy(tank);
|
||||
engine.destroy(tank, bullet.tank.playerId);
|
||||
}
|
||||
}
|
||||
engine.destroy(bullet);
|
||||
@@ -91,13 +92,13 @@ class CollisionProcessor {
|
||||
class EngineDispatcher {
|
||||
public var spawnSignal(default, null):Signal1<EntityType>;
|
||||
public var collisionSignal(default, null):Signal2<EntityType, EntityType>;
|
||||
public var destroySignal(default, null):Signal1<EntityType>;
|
||||
public var destroySignal(default, null):Signal2<EntityType, PlayerId>;
|
||||
public var changeSignal(default, null):Signal2<EntityType, EntityChange>;
|
||||
|
||||
public function new() {
|
||||
spawnSignal = new Signal1<EntityType>();
|
||||
collisionSignal = new Signal2<EntityType, EntityType>();
|
||||
destroySignal = new Signal1<EntityType>();
|
||||
destroySignal = new Signal2<EntityType, PlayerId>();
|
||||
changeSignal = new Signal2<EntityType, EntityChange>();
|
||||
}
|
||||
|
||||
@@ -143,7 +144,7 @@ class Engine extends EngineDispatcher implements ControlHandler {
|
||||
spawnSignal.emit(type);
|
||||
}
|
||||
|
||||
public function destroy(entity:Entity):Void {
|
||||
public function destroy(entity:Entity, ?playerId:PlayerId):Void {
|
||||
if (entities.exists(entity.id)) {
|
||||
var type = EntityTypeResolver.of(entity);
|
||||
switch (type) {
|
||||
@@ -152,7 +153,7 @@ class Engine extends EngineDispatcher implements ControlHandler {
|
||||
if (tank != null) tank.onDestroyBullet();
|
||||
case _:
|
||||
}
|
||||
destroySignal.emit(type);
|
||||
destroySignal.emit(type, playerId);
|
||||
entities.remove(entity.id);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -192,7 +192,7 @@ class Game {
|
||||
}
|
||||
}
|
||||
|
||||
public function onDestroy(entity:EntityType):Void {
|
||||
public function onDestroy(entity:EntityType, ?playerId:PlayerId):Void {
|
||||
switch (entity) {
|
||||
case EntityType.TANK(tank):
|
||||
var team = getTeam(tank.playerId.team);
|
||||
@@ -209,6 +209,14 @@ class Game {
|
||||
if (tank.bonus) {
|
||||
spawnBonus();
|
||||
}
|
||||
if (tank.config.score > 0 && playerId != null) {
|
||||
getPlayer(playerId).state.score += tank.config.score;
|
||||
}
|
||||
deferred.resolve(state);
|
||||
case EntityType.BONUS(bonus):
|
||||
if (bonus.config.score > 0 && playerId != null) {
|
||||
getPlayer(playerId).state.score += bonus.config.score;
|
||||
}
|
||||
deferred.resolve(state);
|
||||
case _:
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user