[render] show scores

This commit is contained in:
2018-03-14 22:14:33 +03:00
parent e9212a889d
commit 2183c0710c
8 changed files with 57 additions and 19 deletions

View File

@@ -1,6 +1,6 @@
{ {
"name": "tankz", "name": "tankz",
"version": "0.7.2", "version": "0.7.3",
"private": true, "private": true,
"devDependencies": { "devDependencies": {
"ansi-colors": "^1.0.1", "ansi-colors": "^1.0.1",
@@ -34,6 +34,7 @@
"haxeDependencies": { "haxeDependencies": {
"lime": "6.0.1", "lime": "6.0.1",
"openfl": "7.0.0", "openfl": "7.0.0",
"hxcpp": "3.4.188",
"promhx": "1.1.0", "promhx": "1.1.0",
"protohx": "0.4.6", "protohx": "0.4.6",
"yaml": "1.3.0", "yaml": "1.3.0",

View File

@@ -1,8 +1,13 @@
package ru.m.tankz.render; package ru.m.tankz.render;
import haxework.resources.IResources;
import haxework.provider.Provider;
import flash.display.DisplayObjectContainer; import flash.display.DisplayObjectContainer;
import flash.display.Graphics; import flash.display.Graphics;
import flash.display.Sprite; import flash.display.Sprite;
import flash.text.TextField;
import flash.text.TextFormat;
import haxe.Timer;
import haxework.gui.SpriteView; import haxework.gui.SpriteView;
import ru.m.animate.Animate; import ru.m.animate.Animate;
import ru.m.animate.OnceAnimate; import ru.m.animate.OnceAnimate;
@@ -10,6 +15,7 @@ import ru.m.geom.Point;
import ru.m.tankz.core.EntityType; import ru.m.tankz.core.EntityType;
import ru.m.tankz.engine.Engine; import ru.m.tankz.engine.Engine;
import ru.m.tankz.render.RenderItem; import ru.m.tankz.render.RenderItem;
import ru.m.tankz.Type;
class Render extends SpriteView { 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 { switch entity {
case EntityType.TANK(tank): case EntityType.TANK(tank):
if (items.exists(tank.key)) { if (items.exists(tank.key)) {
entryLayer.removeChild(items.get(tank.key).view); entryLayer.removeChild(items.get(tank.key).view);
items.remove(tank.key); items.remove(tank.key);
playAnimate(tank.rect.center, AnimateBundle.tankBoom()); playAnimate(tank.rect.center, AnimateBundle.tankBoom());
if (tank.config.score > 0) {
showScore(tank.rect.center, tank.config.score);
}
} }
case EntityType.BULLET(bullet): case EntityType.BULLET(bullet):
if (items.exists(bullet.key)) { if (items.exists(bullet.key)) {
@@ -157,6 +166,9 @@ class Render extends SpriteView {
if (items.exists(bonus.key)) { if (items.exists(bonus.key)) {
upperLayer.removeChild(items.get(bonus.key).view); upperLayer.removeChild(items.get(bonus.key).view);
items.remove(bonus.key); items.remove(bonus.key);
if (bonus.config.score > 0) {
showScore(bonus.rect.center, bonus.config.score);
}
} }
case _: case _:
} }
@@ -171,4 +183,16 @@ class Render extends SpriteView {
animate.dispose(); 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);
}
} }

View File

@@ -1,9 +1,10 @@
package ru.m.tankz.sound; package ru.m.tankz.sound;
import ru.m.tankz.engine.Engine;
import openfl.media.Sound; import openfl.media.Sound;
import openfl.utils.Assets; import openfl.utils.Assets;
import ru.m.tankz.core.EntityType; import ru.m.tankz.core.EntityType;
import ru.m.tankz.engine.Engine;
import ru.m.tankz.Type;
class SoundManager { class SoundManager {
@@ -57,7 +58,7 @@ class SoundManager {
} }
} }
public function onDestroy(entity:EntityType):Void { public function onDestroy(entity:EntityType, ?playerId:PlayerId):Void {
switch entity { switch entity {
case EntityType.TANK(_): case EntityType.TANK(_):
play('boom_bot'); play('boom_bot');

View File

@@ -174,9 +174,9 @@ tanks:
skin: bd skin: bd
bonuses: bonuses:
- {type: clock, duration: 10} - {score: 500, type: clock, duration: 10}
- {type: grenade} - {score: 500, type: grenade}
- {type: helmet, duration: 20} - {score: 500, type: helmet, duration: 20}
- {type: life} - {score: 500, type: life}
- {type: shovel, duration: 10} - {score: 500, type: shovel, duration: 10}
- {type: star} - {score: 500, type: star}

View File

@@ -58,6 +58,7 @@ class JsConnection<O:Message, I:Message> extends BaseConnection<O, I> {
private function onConnect(_):Void { private function onConnect(_):Void {
connected = true; connected = true;
handler.emit(ConnectionEvent.CONNECTED); handler.emit(ConnectionEvent.CONNECTED);
connectDeferred.resolve(this);
} }
private function onClose(_):Void { private function onClose(_):Void {

View File

@@ -50,11 +50,13 @@ typedef TankConfig = {
var skin:String; var skin:String;
@:optinal var upgrade:TankType; @:optinal var upgrade:TankType;
@:optinal var downgrade:TankType; @:optinal var downgrade:TankType;
@:optinal var score:Int;
} }
typedef BonusConfig = { typedef BonusConfig = {
var type:BonusType; var type:BonusType;
@:optional var duration:Int; @:optional var duration:Int;
@:optinal var score:Int;
} }
typedef TankSpawn = { typedef TankSpawn = {

View File

@@ -1,8 +1,8 @@
package ru.m.tankz.engine; package ru.m.tankz.engine;
import ru.m.signal.Signal;
import ru.m.geom.Line; import ru.m.geom.Line;
import ru.m.geom.Point; import ru.m.geom.Point;
import ru.m.signal.Signal;
import ru.m.tankz.config.Config; import ru.m.tankz.config.Config;
import ru.m.tankz.control.Control; import ru.m.tankz.control.Control;
import ru.m.tankz.core.Bullet; 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.MobileEntity;
import ru.m.tankz.core.Tank; import ru.m.tankz.core.Tank;
import ru.m.tankz.map.LevelMap; import ru.m.tankz.map.LevelMap;
import ru.m.tankz.Type;
enum EntityChange { enum EntityChange {
@@ -24,7 +25,7 @@ enum EntityChange {
typedef EngineListener = { typedef EngineListener = {
public function onSpawn(entity:EntityType):Void; public function onSpawn(entity:EntityType):Void;
public function onCollision(entity:EntityType, with: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; public function onChange(entity:EntityType, change:EntityChange):Void;
} }
@@ -44,7 +45,7 @@ class CollisionProcessor {
case [EntityType.TANK(tank), EntityType.EAGLE(eagle)]: case [EntityType.TANK(tank), EntityType.EAGLE(eagle)]:
tank.rect.lean(eagle.rect); tank.rect.lean(eagle.rect);
case [EntityType.TANK(tank), EntityType.BONUS(bonus)]: case [EntityType.TANK(tank), EntityType.BONUS(bonus)]:
engine.destroy(bonus); engine.destroy(bonus, tank.playerId);
case [EntityType.TANK(tank), EntityType.BULLET(bullet)] | case [EntityType.TANK(tank), EntityType.BULLET(bullet)] |
[EntityType.BULLET(bullet), EntityType.TANK(tank)]: [EntityType.BULLET(bullet), EntityType.TANK(tank)]:
if (bullet.tankId == tank.id || (!engine.config.game.friendlyFire && tank.playerId.team == bullet.playerId.team)) { if (bullet.tankId == tank.id || (!engine.config.game.friendlyFire && tank.playerId.team == bullet.playerId.team)) {
@@ -58,7 +59,7 @@ class CollisionProcessor {
tank.hits--; tank.hits--;
engine.change(tank, EntityChange.HIT); engine.change(tank, EntityChange.HIT);
} else { } else {
engine.destroy(tank); engine.destroy(tank, bullet.tank.playerId);
} }
} }
engine.destroy(bullet); engine.destroy(bullet);
@@ -91,13 +92,13 @@ class CollisionProcessor {
class EngineDispatcher { class EngineDispatcher {
public var spawnSignal(default, null):Signal1<EntityType>; public var spawnSignal(default, null):Signal1<EntityType>;
public var collisionSignal(default, null):Signal2<EntityType, 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 var changeSignal(default, null):Signal2<EntityType, EntityChange>;
public function new() { public function new() {
spawnSignal = new Signal1<EntityType>(); spawnSignal = new Signal1<EntityType>();
collisionSignal = new Signal2<EntityType, EntityType>(); collisionSignal = new Signal2<EntityType, EntityType>();
destroySignal = new Signal1<EntityType>(); destroySignal = new Signal2<EntityType, PlayerId>();
changeSignal = new Signal2<EntityType, EntityChange>(); changeSignal = new Signal2<EntityType, EntityChange>();
} }
@@ -143,7 +144,7 @@ class Engine extends EngineDispatcher implements ControlHandler {
spawnSignal.emit(type); spawnSignal.emit(type);
} }
public function destroy(entity:Entity):Void { public function destroy(entity:Entity, ?playerId:PlayerId):Void {
if (entities.exists(entity.id)) { if (entities.exists(entity.id)) {
var type = EntityTypeResolver.of(entity); var type = EntityTypeResolver.of(entity);
switch (type) { switch (type) {
@@ -152,7 +153,7 @@ class Engine extends EngineDispatcher implements ControlHandler {
if (tank != null) tank.onDestroyBullet(); if (tank != null) tank.onDestroyBullet();
case _: case _:
} }
destroySignal.emit(type); destroySignal.emit(type, playerId);
entities.remove(entity.id); entities.remove(entity.id);
} }
} }

View File

@@ -192,7 +192,7 @@ class Game {
} }
} }
public function onDestroy(entity:EntityType):Void { public function onDestroy(entity:EntityType, ?playerId:PlayerId):Void {
switch (entity) { switch (entity) {
case EntityType.TANK(tank): case EntityType.TANK(tank):
var team = getTeam(tank.playerId.team); var team = getTeam(tank.playerId.team);
@@ -209,6 +209,14 @@ class Game {
if (tank.bonus) { if (tank.bonus) {
spawnBonus(); 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); deferred.resolve(state);
case _: case _:
} }