From 2183c0710c4b55f00d341bd09359e781fe24cd09 Mon Sep 17 00:00:00 2001 From: shmyga Date: Wed, 14 Mar 2018 22:14:33 +0300 Subject: [PATCH] [render] show scores --- package.json | 3 ++- src/client/haxe/ru/m/tankz/render/Render.hx | 26 ++++++++++++++++++- .../haxe/ru/m/tankz/sound/SoundManager.hx | 5 ++-- src/client/resources/classic/config.yaml | 12 ++++----- .../haxe/ru/m/connect/js/JsConnection.hx | 1 + src/common/haxe/ru/m/tankz/config/Config.hx | 2 ++ src/common/haxe/ru/m/tankz/engine/Engine.hx | 17 ++++++------ src/common/haxe/ru/m/tankz/game/Game.hx | 10 ++++++- 8 files changed, 57 insertions(+), 19 deletions(-) diff --git a/package.json b/package.json index a09716d..a31f238 100755 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "tankz", - "version": "0.7.2", + "version": "0.7.3", "private": true, "devDependencies": { "ansi-colors": "^1.0.1", @@ -34,6 +34,7 @@ "haxeDependencies": { "lime": "6.0.1", "openfl": "7.0.0", + "hxcpp": "3.4.188", "promhx": "1.1.0", "protohx": "0.4.6", "yaml": "1.3.0", diff --git a/src/client/haxe/ru/m/tankz/render/Render.hx b/src/client/haxe/ru/m/tankz/render/Render.hx index fb37eed..fd00e6c 100755 --- a/src/client/haxe/ru/m/tankz/render/Render.hx +++ b/src/client/haxe/ru/m/tankz/render/Render.hx @@ -1,8 +1,13 @@ package ru.m.tankz.render; +import haxework.resources.IResources; +import haxework.provider.Provider; import flash.display.DisplayObjectContainer; import flash.display.Graphics; import flash.display.Sprite; +import flash.text.TextField; +import flash.text.TextFormat; +import haxe.Timer; import haxework.gui.SpriteView; import ru.m.animate.Animate; import ru.m.animate.OnceAnimate; @@ -10,6 +15,7 @@ import ru.m.geom.Point; import ru.m.tankz.core.EntityType; import ru.m.tankz.engine.Engine; import ru.m.tankz.render.RenderItem; +import ru.m.tankz.Type; class Render extends SpriteView { @@ -138,13 +144,16 @@ class Render extends SpriteView { } } - public function onDestroy(entity:EntityType):Void { + public function onDestroy(entity:EntityType, ?playerId:PlayerId):Void { switch entity { case EntityType.TANK(tank): if (items.exists(tank.key)) { entryLayer.removeChild(items.get(tank.key).view); items.remove(tank.key); playAnimate(tank.rect.center, AnimateBundle.tankBoom()); + if (tank.config.score > 0) { + showScore(tank.rect.center, tank.config.score); + } } case EntityType.BULLET(bullet): if (items.exists(bullet.key)) { @@ -157,6 +166,9 @@ class Render extends SpriteView { if (items.exists(bonus.key)) { upperLayer.removeChild(items.get(bonus.key).view); items.remove(bonus.key); + if (bonus.config.score > 0) { + showScore(bonus.rect.center, bonus.config.score); + } } case _: } @@ -171,4 +183,16 @@ class Render extends SpriteView { animate.dispose(); }); } + + private function showScore(point:Point, score:Int):Void { + var view:TextField = new TextField(); + view.embedFonts = true; + var font:String = Provider.get(IResources).text.get('font'); + view.defaultTextFormat = new TextFormat(font, 28, 0xffffff); + view.text = Std.string(score); + view.x = point.x - view.textWidth / 2; + view.y = point.y - view.textHeight / 2; + upperLayer.addChild(view); + Timer.delay(function() upperLayer.removeChild(view), 1000); + } } diff --git a/src/client/haxe/ru/m/tankz/sound/SoundManager.hx b/src/client/haxe/ru/m/tankz/sound/SoundManager.hx index f975994..6513622 100644 --- a/src/client/haxe/ru/m/tankz/sound/SoundManager.hx +++ b/src/client/haxe/ru/m/tankz/sound/SoundManager.hx @@ -1,9 +1,10 @@ package ru.m.tankz.sound; -import ru.m.tankz.engine.Engine; import openfl.media.Sound; import openfl.utils.Assets; import ru.m.tankz.core.EntityType; +import ru.m.tankz.engine.Engine; +import ru.m.tankz.Type; class SoundManager { @@ -57,7 +58,7 @@ class SoundManager { } } - public function onDestroy(entity:EntityType):Void { + public function onDestroy(entity:EntityType, ?playerId:PlayerId):Void { switch entity { case EntityType.TANK(_): play('boom_bot'); diff --git a/src/client/resources/classic/config.yaml b/src/client/resources/classic/config.yaml index f6c8b45..4595e70 100644 --- a/src/client/resources/classic/config.yaml +++ b/src/client/resources/classic/config.yaml @@ -174,9 +174,9 @@ tanks: skin: bd bonuses: - - {type: clock, duration: 10} - - {type: grenade} - - {type: helmet, duration: 20} - - {type: life} - - {type: shovel, duration: 10} - - {type: star} + - {score: 500, type: clock, duration: 10} + - {score: 500, type: grenade} + - {score: 500, type: helmet, duration: 20} + - {score: 500, type: life} + - {score: 500, type: shovel, duration: 10} + - {score: 500, type: star} diff --git a/src/common/haxe/ru/m/connect/js/JsConnection.hx b/src/common/haxe/ru/m/connect/js/JsConnection.hx index 3fc5d4f..db3edab 100644 --- a/src/common/haxe/ru/m/connect/js/JsConnection.hx +++ b/src/common/haxe/ru/m/connect/js/JsConnection.hx @@ -58,6 +58,7 @@ class JsConnection extends BaseConnection { private function onConnect(_):Void { connected = true; handler.emit(ConnectionEvent.CONNECTED); + connectDeferred.resolve(this); } private function onClose(_):Void { diff --git a/src/common/haxe/ru/m/tankz/config/Config.hx b/src/common/haxe/ru/m/tankz/config/Config.hx index 19c3925..010ac20 100644 --- a/src/common/haxe/ru/m/tankz/config/Config.hx +++ b/src/common/haxe/ru/m/tankz/config/Config.hx @@ -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 = { diff --git a/src/common/haxe/ru/m/tankz/engine/Engine.hx b/src/common/haxe/ru/m/tankz/engine/Engine.hx index efe62a1..d97ff12 100755 --- a/src/common/haxe/ru/m/tankz/engine/Engine.hx +++ b/src/common/haxe/ru/m/tankz/engine/Engine.hx @@ -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; public var collisionSignal(default, null):Signal2; - public var destroySignal(default, null):Signal1; + public var destroySignal(default, null):Signal2; public var changeSignal(default, null):Signal2; public function new() { spawnSignal = new Signal1(); collisionSignal = new Signal2(); - destroySignal = new Signal1(); + destroySignal = new Signal2(); changeSignal = new Signal2(); } @@ -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); } } diff --git a/src/common/haxe/ru/m/tankz/game/Game.hx b/src/common/haxe/ru/m/tankz/game/Game.hx index 7cc0d62..8ee63d8 100644 --- a/src/common/haxe/ru/m/tankz/game/Game.hx +++ b/src/common/haxe/ru/m/tankz/game/Game.hx @@ -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 _: }