From b86e0ddd20f4306a8406eb2807c7da86ff975a29 Mon Sep 17 00:00:00 2001 From: shmyga Date: Fri, 19 Apr 2019 16:20:01 +0300 Subject: [PATCH] [comon] remove change signal from engine --- .../haxe/ru/m/tankz/control/HumanControl.hx | 3 - src/client/haxe/ru/m/tankz/render/Render.hx | 2 - .../haxe/ru/m/tankz/sound/SoundManager.hx | 15 +-- src/common/haxe/ru/m/tankz/control/Control.hx | 1 - src/common/haxe/ru/m/tankz/engine/Engine.hx | 49 -------- src/common/haxe/ru/m/tankz/game/Game.hx | 115 +++++++++--------- 6 files changed, 62 insertions(+), 123 deletions(-) diff --git a/src/client/haxe/ru/m/tankz/control/HumanControl.hx b/src/client/haxe/ru/m/tankz/control/HumanControl.hx index 1ce540b..568d2bf 100644 --- a/src/client/haxe/ru/m/tankz/control/HumanControl.hx +++ b/src/client/haxe/ru/m/tankz/control/HumanControl.hx @@ -42,9 +42,6 @@ class HumanControl extends Control { } case _: } - if (event.keyCode == Keyboard.U) { - action(TankAction.UPGRADE); - } } private function onKeyUp(event:KeyboardEvent):Void { diff --git a/src/client/haxe/ru/m/tankz/render/Render.hx b/src/client/haxe/ru/m/tankz/render/Render.hx index b3bcb29..8736861 100755 --- a/src/client/haxe/ru/m/tankz/render/Render.hx +++ b/src/client/haxe/ru/m/tankz/render/Render.hx @@ -126,8 +126,6 @@ class Render extends SpriteView { } } - public function onChange(entity:EntityType, change:EntityChange):Void {} - public function onCollision(entity:EntityType, with:EntityType):Void { switch [entity, with] { case [BULLET(_), EAGLE(eagle)]: diff --git a/src/client/haxe/ru/m/tankz/sound/SoundManager.hx b/src/client/haxe/ru/m/tankz/sound/SoundManager.hx index c3f230d..59fffb7 100644 --- a/src/client/haxe/ru/m/tankz/sound/SoundManager.hx +++ b/src/client/haxe/ru/m/tankz/sound/SoundManager.hx @@ -6,7 +6,6 @@ import flash.media.SoundChannel; import flash.media.SoundTransform; import openfl.utils.Assets; import ru.m.tankz.core.EntityType; -import ru.m.tankz.engine.Engine; import ru.m.tankz.Type; class SoundManager { @@ -85,22 +84,12 @@ class SoundManager { } } - public function onChange(entity:EntityType, change:EntityChange):Void { - switch [entity, change] { - case [TANK(_), HIT]: - play('bullet_hit'); - //case [TANK(_), LIVE_UP]: - // play('live'); - case [EAGLE(_), DEATH(_)]: - play('boom_player'); - case _: - } - } - public function onCollision(entity:EntityType, with:EntityType):Void { switch [entity, with] { case [BULLET(_), CELL(cell)]: //play('bullet_wall'); + case [BULLET(_), EAGLE(_)]: + play('boom_player'); case _: } } diff --git a/src/common/haxe/ru/m/tankz/control/Control.hx b/src/common/haxe/ru/m/tankz/control/Control.hx index 46a83bd..8baaa53 100644 --- a/src/common/haxe/ru/m/tankz/control/Control.hx +++ b/src/common/haxe/ru/m/tankz/control/Control.hx @@ -8,7 +8,6 @@ import ru.m.tankz.Type; enum TankAction { MOVE(direction:Direction); - UPGRADE; STOP; SHOT; } diff --git a/src/common/haxe/ru/m/tankz/engine/Engine.hx b/src/common/haxe/ru/m/tankz/engine/Engine.hx index 63b345a..a187c23 100755 --- a/src/common/haxe/ru/m/tankz/engine/Engine.hx +++ b/src/common/haxe/ru/m/tankz/engine/Engine.hx @@ -14,20 +14,10 @@ import ru.m.tankz.map.Grid; import ru.m.tankz.map.LevelMap; import ru.m.tankz.Type; - -enum EntityChange { - HIT; - TYPE; - DEATH(playerId:PlayerId); - PROTECT; - FREEZING; -} - typedef EngineListener = { public function onSpawn(entity:EntityType):Void; public function onCollision(entity:EntityType, with:EntityType):Void; public function onDestroy(entity:EntityType, ?playerId:PlayerId):Void; - public function onChange(entity:EntityType, change:EntityChange):Void; } class CollisionProcessor { @@ -45,26 +35,6 @@ class CollisionProcessor { tank.rect.lean(other_tank.rect); case [TANK(tank), EAGLE(eagle)]: tank.rect.lean(eagle.rect); - case [TANK(tank), BONUS(bonus)]: - engine.destroy(bonus, tank.playerId); - case [TANK(tank), BULLET(bullet)] | - [BULLET(bullet), TANK(tank)]: - if (bullet.tankId == tank.id || (!engine.config.game.friendlyFire && tank.playerId.team == bullet.playerId.team)) { - // Nothing - } else { - if (!tank.protect.active) { - if (tank.hits > 0) { - tank.hits--; - engine.change(tank, HIT); - } else if (tank.config.downgrade != null) { - tank.config = engine.config.getTank(tank.config.downgrade); - engine.change(tank, TYPE); - } else { - engine.destroy(tank, bullet.tank.playerId); - } - } - engine.destroy(bullet); - } case [BULLET(bullet), BULLET(other_bullet)]: engine.destroy(bullet); engine.destroy(other_bullet); @@ -72,11 +42,6 @@ class CollisionProcessor { engine.destroy(bullet); case [BULLET(bullet), EAGLE(eagle)]: engine.destroy(bullet); - if (!eagle.protect.active) { - eagle.death = true; - // ToDo: change - engine.change(eagle, DEATH(bullet.playerId)); - } case _: } } @@ -94,27 +59,23 @@ class EngineDispatcher { public var spawnSignal(default, null):Signal1; public var collisionSignal(default, null):Signal2; public var destroySignal(default, null):Signal2; - public var changeSignal(default, null):Signal2; public function new() { spawnSignal = new Signal1(); collisionSignal = new Signal2(); destroySignal = new Signal2(); - changeSignal = new Signal2(); } public function connect(listener:EngineListener) { spawnSignal.connect(listener.onSpawn); collisionSignal.connect(listener.onCollision); destroySignal.connect(listener.onDestroy); - changeSignal.connect(listener.onChange); } public function disconnect(listener:EngineListener) { spawnSignal.disconnect(listener.onSpawn); collisionSignal.disconnect(listener.onCollision); destroySignal.disconnect(listener.onDestroy); - changeSignal.disconnect(listener.onChange); } } @@ -165,11 +126,6 @@ class Engine extends EngineDispatcher implements ControlHandler { switch (action) { case MOVE(direction): tank.move(direction); - case UPGRADE: - if (tank.config.upgrade != null) { - tank.config = config.getTank(tank.config.upgrade); - change(tank, TYPE); - } case STOP: tank.stop(); case SHOT: @@ -180,11 +136,6 @@ class Engine extends EngineDispatcher implements ControlHandler { } } - public function change(entity:Entity, change:EntityChange):Void { - var type = EntityTypeResolver.of(entity); - changeSignal.emit(type, change); - } - public function update():Void { var newTime:Float = Date.now().getTime(); var d:Float = newTime - time; diff --git a/src/common/haxe/ru/m/tankz/game/Game.hx b/src/common/haxe/ru/m/tankz/game/Game.hx index 9db9428..5f3ad93 100644 --- a/src/common/haxe/ru/m/tankz/game/Game.hx +++ b/src/common/haxe/ru/m/tankz/game/Game.hx @@ -1,6 +1,5 @@ package ru.m.tankz.game; -import ru.m.tankz.control.Controller.AController; import haxe.ds.Option; import haxe.Timer; import haxework.signal.Signal; @@ -8,6 +7,7 @@ import ru.m.geom.Point; import ru.m.tankz.bundle.IConfigBundle; import ru.m.tankz.config.Config; import ru.m.tankz.control.Control; +import ru.m.tankz.control.Controller; import ru.m.tankz.control.IControlFactory; import ru.m.tankz.core.Bonus; import ru.m.tankz.core.Eagle; @@ -49,7 +49,7 @@ class GameDispatcher { class Game extends GameDispatcher { - private static var TAG(default, never):String = 'Game'; + private static var TAG(default, never):String = "Game"; public var type(default, null):GameType; public var teams(default, null):Map; @@ -133,7 +133,7 @@ class Game extends GameDispatcher { team.spawner.push(player.id, player.state.tank); } } - var eaglePoint = team.spawner.getPoint('eagle'); + var eaglePoint = team.spawner.getPoint("eagle"); if (eaglePoint != null) { var eagle = new Eagle(team.id, team.config.eagle); eagle.color = config.getColor(new PlayerId(eagle.team, -1)); @@ -202,25 +202,6 @@ class Game extends GameDispatcher { } } - public function onChange(entity:EntityType, change:EntityChange):Void { - switch [entity, change] { - case [EAGLE(eagle), DEATH(playerId)]: - if (eagle.death) { - getPlayer(playerId).state.score += eagle.score * (eagle.team == playerId.team ? 0 : 1); - checkComplete(); - onGameChange.emit(state); - } - case [TANK(tank), HIT]: - if (tank.bonus) { - tank.bonus = false; - spawnBonus(); - } - case [TANK(tank), TYPE]: - getPlayer(tank.playerId).state.tank = tank.config.type; - case _: - } - } - public function onCollision(entity:EntityType, with:EntityType):Void { switch entity { case EntityType.TANK(tank): @@ -231,8 +212,36 @@ class Game extends GameDispatcher { switch [entity, with] { case [TANK(tank), BONUS(bonus)]: applyBonus(tank, bonus); - case [BULLET(bullet), TANK(tank)]: - getPlayer(bullet.playerId).state.hits++; + engine.destroy(bonus, tank.playerId); + case [BULLET(bullet), TANK(tank)]/* | [TANK(tank), BULLET(bullet)]*/: + if (bullet.tankId == tank.id || (!engine.config.game.friendlyFire && tank.playerId.team == bullet.playerId.team)) { + // Nothing + } else { + if (!tank.protect.active) { + if (tank.hits > 0) { + tank.hits--; + if (tank.bonus) { + tank.bonus = false; + spawnBonus(); + } + } else if (tank.config.downgrade != null) { + tank.config = engine.config.getTank(tank.config.downgrade); + } else { + engine.destroy(tank, bullet.tank.playerId); + } + } + engine.destroy(bullet); + } + case [BULLET(bullet), EAGLE(eagle)]: + engine.destroy(bullet); + if (!eagle.protect.active) { + eagle.death = true; + if (bullet.playerId.team != eagle.team) { + getPlayer(bullet.playerId).state.score += eagle.score; + } + checkComplete(); + onGameChange.emit(state); + } case _: } } @@ -260,11 +269,6 @@ class Game extends GameDispatcher { getPlayer(playerId).state.score += tank.config.score * (tank.playerId.team == playerId.team ? 0 : 1); } onGameChange.emit(state); - case BONUS(bonus): - if (bonus.config.score > 0 && playerId != null) { - getPlayer(playerId).state.score += bonus.config.score; - } - onGameChange.emit(state); case _: } } @@ -310,48 +314,49 @@ class Game extends GameDispatcher { private function applyBonus(tank:Tank, bonus:Bonus):Void { switch (bonus.config.type) { - case 'life': + case "life": getPlayer(tank.playerId).state.life++; - case 'star': - if (tank.config.upgrade != null) { - tank.config = config.getTank(tank.config.upgrade); - engine.change(tank, EntityChange.TYPE); - } else { - tank.hits++; - engine.change(tank, EntityChange.HIT); - } - case 'grenade': + case "star": + upgradeTank(tank); + case "grenade": for (t in engine.iterTanks(alienTank(tank.playerId.team))) { engine.destroy(t); } - case 'helmet': + case "helmet": tank.protect.on(bonus.config.duration); - engine.change(tank, EntityChange.PROTECT); - case 'clock': + case "clock": for (t in engine.iterTanks(alienTank(tank.playerId.team))) { t.freezing.on(bonus.config.duration); - engine.change(t, EntityChange.FREEZING); } - case 'shovel': + case "shovel": // ToDo: protect eagle/area var team:Team = teams[tank.playerId.team]; if (team.eagleId > 0) { var eagle:Eagle = cast(engine.entities[team.eagleId], Eagle); eagle.protect.on(bonus.config.duration); - engine.change(eagle, EntityChange.PROTECT); - } - case 'gun': - if (tank.config.upgrade != null) { - while (tank.config.upgrade != null) { - tank.config = config.getTank(tank.config.upgrade); - } - engine.change(tank, EntityChange.TYPE); - } else { - tank.hits++; - engine.change(tank, EntityChange.HIT); } + case "gun": + upgradeTank(tank, 5); case _: engine.destroy(tank); // :-D } + if (bonus.config.score > 0) { + getPlayer(tank.playerId).state.score += bonus.config.score; + } + onGameChange.emit(state); + } + + public function upgradeTank(tank:Tank, level:Int = 1):Void { + if (tank.config.upgrade != null) { + while (level-- > 0 && tank.config.upgrade != null) { + tank.config = config.getTank(tank.config.upgrade); + } + } else { + tank.hits++; + } + } + + public function hitTank(tank:Tank):Void { + } }