diff --git a/package.json b/package.json
index 790b45d..b57039e 100755
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "tankz",
- "version": "0.6.2",
+ "version": "0.6.3",
"private": true,
"devDependencies": {
"ansi-colors": "^1.0.1",
diff --git a/project.xml b/project.xml
index a684dfc..daf00ba 100755
--- a/project.xml
+++ b/project.xml
@@ -20,6 +20,7 @@
+
diff --git a/src/client/haxe/ru/m/tankz/render/Render.hx b/src/client/haxe/ru/m/tankz/render/Render.hx
index a5ffb53..d3f76e5 100755
--- a/src/client/haxe/ru/m/tankz/render/Render.hx
+++ b/src/client/haxe/ru/m/tankz/render/Render.hx
@@ -125,6 +125,8 @@ class Render extends SpriteView implements EngineListener {
}
}
+ public function onChange(entity:EntityType):Void {}
+
public function onCollision(entity:EntityType, with:EntityType):Void {
switch [entity, with] {
case [EntityType.BULLET(_), EntityType.EAGLE(eagle)]:
diff --git a/src/client/haxe/ru/m/tankz/render/RenderItem.hx b/src/client/haxe/ru/m/tankz/render/RenderItem.hx
index 1107be7..82a734a 100644
--- a/src/client/haxe/ru/m/tankz/render/RenderItem.hx
+++ b/src/client/haxe/ru/m/tankz/render/RenderItem.hx
@@ -278,8 +278,8 @@ class BonusItem extends AnimateItem {
}
override public function redraw():Void {
- var image = Assets.getBitmapData('resources/image/bonus/${value.bonusType}.png');
- view.frames = AnimateBundle.bonusFrames(value.bonusType);
+ var image = Assets.getBitmapData('resources/image/bonus/${value.config.type}.png');
+ view.frames = AnimateBundle.bonusFrames(value.config.type);
view.playing = true;
}
}
diff --git a/src/client/resources/classic/config.yaml b/src/client/resources/classic/config.yaml
index 2912337..edc7629 100644
--- a/src/client/resources/classic/config.yaml
+++ b/src/client/resources/classic/config.yaml
@@ -173,9 +173,9 @@ tanks:
skin: bd
bonuses:
- - {type: clock}
+ - {type: clock, duration: 10}
- {type: grenade}
- - {type: helmet}
+ - {type: helmet, duration: 20}
- {type: life}
- - {type: shovel}
+ - {type: shovel, duration: 10}
- {type: star}
diff --git a/src/client/resources/dota/config.yaml b/src/client/resources/dota/config.yaml
index 9b7c1cc..084c28d 100644
--- a/src/client/resources/dota/config.yaml
+++ b/src/client/resources/dota/config.yaml
@@ -136,9 +136,9 @@ tanks:
skin: bb
bonuses:
- - {type: clock}
+ - {type: clock, duration: 10}
- {type: grenade}
- - {type: helmet}
+ - {type: helmet, duration: 20}
- {type: life}
- - {type: shovel}
+ - {type: shovel, duration: 10}
- {type: star}
diff --git a/src/common/haxe/ru/m/tankz/config/Config.hx b/src/common/haxe/ru/m/tankz/config/Config.hx
index bf4e3b0..5890d36 100644
--- a/src/common/haxe/ru/m/tankz/config/Config.hx
+++ b/src/common/haxe/ru/m/tankz/config/Config.hx
@@ -53,6 +53,7 @@ typedef TankConfig = {
typedef BonusConfig = {
var type:BonusType;
+ @:optional var duration:Int;
}
typedef TankSpawn = {
diff --git a/src/common/haxe/ru/m/tankz/core/Bonus.hx b/src/common/haxe/ru/m/tankz/core/Bonus.hx
index d9b7740..85c5dd0 100644
--- a/src/common/haxe/ru/m/tankz/core/Bonus.hx
+++ b/src/common/haxe/ru/m/tankz/core/Bonus.hx
@@ -1,15 +1,15 @@
package ru.m.tankz.core;
+import ru.m.tankz.config.Config;
import ru.m.geom.Rectangle;
-import ru.m.tankz.Type;
class Bonus extends Entity {
- public var bonusType(default, null):BonusType;
+ public var config(default, null):BonusConfig;
- public function new(bonusType:BonusType) {
+ public function new(config:BonusConfig) {
super(new Rectangle(0, 0, 44, 44));
- this.bonusType = bonusType;
+ this.config = config;
}
}
diff --git a/src/common/haxe/ru/m/tankz/engine/Engine.hx b/src/common/haxe/ru/m/tankz/engine/Engine.hx
index 53ea0aa..21c2c1e 100755
--- a/src/common/haxe/ru/m/tankz/engine/Engine.hx
+++ b/src/common/haxe/ru/m/tankz/engine/Engine.hx
@@ -14,6 +14,7 @@ import ru.m.tankz.map.LevelMap;
interface EngineListener {
public function onSpawn(entity:EntityType):Void;
+ public function onChange(entity:EntityType):Void;
public function onCollision(entity:EntityType, with:EntityType):Void;
public function onDestroy(entity:EntityType):Void;
}
@@ -28,6 +29,8 @@ class CollisionProcessor implements EngineListener {
public function onSpawn(entity:EntityType):Void {}
+ public function onChange(entity:EntityType):Void {}
+
public function onCollision(entity:EntityType, with:EntityType):Void {
switch [entity, with] {
case [EntityType.TANK(tank), EntityType.TANK(other_tank)]:
@@ -44,6 +47,7 @@ class CollisionProcessor implements EngineListener {
if (!tank.protect.active) {
if (tank.hits > 0) {
tank.hits--;
+ engine.change(tank);
} else {
engine.destroy(tank);
}
@@ -59,6 +63,7 @@ class CollisionProcessor implements EngineListener {
engine.destroy(bullet);
if (!eagle.protect.active) {
eagle.death = true;
+ engine.change(eagle);
}
case _:
}
@@ -67,8 +72,7 @@ class CollisionProcessor implements EngineListener {
public function onDestroy(entity:EntityType):Void { }
}
-@:build(yield.parser.Parser.run())
-//@:yield //ToDo: not working
+@:yield
class Engine implements ControlHandler {
public var config(default, default):Config;
@@ -97,6 +101,11 @@ class Engine implements ControlHandler {
for (l in listeners) l.onSpawn(type);
}
+ public function change(entity:Entity):Void {
+ var type = EntityTypeResolver.of(entity);
+ for (l in listeners) l.onChange(type);
+ }
+
public function destroy(entity:Entity):Void {
if (entities.exists(entity.id)) {
var type = EntityTypeResolver.of(entity);
diff --git a/src/common/haxe/ru/m/tankz/game/Game.hx b/src/common/haxe/ru/m/tankz/game/Game.hx
index c0fd207..081e966 100644
--- a/src/common/haxe/ru/m/tankz/game/Game.hx
+++ b/src/common/haxe/ru/m/tankz/game/Game.hx
@@ -158,6 +158,17 @@ class Game implements EngineListener {
}
}
+ public function onChange(entity:EntityType):Void {
+ switch (entity) {
+ case EntityType.EAGLE(eagle):
+ if (eagle.death) {
+ lose(eagle.team);
+ deferred.resolve(state);
+ }
+ case _:
+ }
+ }
+
public function onCollision(entity:EntityType, with:EntityType):Void {
switch entity {
case EntityType.TANK(tank):
@@ -168,9 +179,6 @@ class Game implements EngineListener {
switch [entity, with] {
case [EntityType.TANK(tank), EntityType.BONUS(bonus)]:
applyBonus(tank, bonus);
- case [EntityType.BULLET(_), EntityType.EAGLE(eagle)]:
- lose(eagle.team);
- deferred.resolve(state);
case _:
}
}
@@ -217,7 +225,7 @@ class Game implements EngineListener {
private function spawnBonus(?type:BonusType):Void {
var bonusConfig:BonusConfig = type != null ? config.getBonus(type) : config.bonuses[Math.floor(Math.random() * config.bonuses.length)];
- var bonus = new Bonus(bonusConfig.type);
+ var bonus = new Bonus(bonusConfig);
bonus.rect.x = Math.random() * engine.map.width;
bonus.rect.y = Math.random() * engine.map.height;
engine.spawn(bonus);
@@ -228,8 +236,7 @@ class Game implements EngineListener {
}
private function applyBonus(tank:Tank, bonus:Bonus):Void {
- L.e('XXX', 'applyBonus: ${bonus.bonusType}');
- switch (bonus.bonusType) {
+ switch (bonus.config.type) {
case 'life':
getPlayer(tank.playerId).life++;
case 'star':
@@ -238,21 +245,26 @@ class Game implements EngineListener {
} else {
tank.hits++;
}
+ engine.change(tank);
case 'grenade':
for (t in engine.iterTanks(alienTank(tank.playerId.team))) {
engine.destroy(t);
}
case 'helmet':
- tank.protect.on(20);
+ tank.protect.on(bonus.config.duration);
+ engine.change(tank);
case 'clock':
for (t in engine.iterTanks(alienTank(tank.playerId.team))) {
- t.freezing.on(10);
+ t.freezing.on(bonus.config.duration);
+ engine.change(t);
}
case 'shovel':
// ToDo: protect eagle/area
var team:Team = teams[tank.playerId.team];
if (team.eagleId > 0) {
- cast(engine.entities[team.eagleId], Eagle).protect.on(10);
+ var eagle:Eagle = cast(engine.entities[team.eagleId], Eagle);
+ eagle.protect.on(bonus.config.duration);
+ engine.change(eagle);
}
case _:
engine.destroy(tank); // :-D