[common] bonus config duration

This commit is contained in:
2018-02-16 22:19:14 +03:00
parent a93a67161d
commit 5456a01551
10 changed files with 49 additions and 24 deletions

View File

@@ -1,6 +1,6 @@
{ {
"name": "tankz", "name": "tankz",
"version": "0.6.2", "version": "0.6.3",
"private": true, "private": true,
"devDependencies": { "devDependencies": {
"ansi-colors": "^1.0.1", "ansi-colors": "^1.0.1",

View File

@@ -20,6 +20,7 @@
<!--<haxeflag name="-D" value="proto_debug"/>--> <!--<haxeflag name="-D" value="proto_debug"/>-->
<haxeflag name="-dce" value="no"/> <haxeflag name="-dce" value="no"/>
<haxeflag name="-D" value="dom"/> <haxeflag name="-D" value="dom"/>
<haxeflag name="--macro" value="yield.parser.Parser.auto()"/>
<!--<template path="src/client/webapp/index_template.html" rename="index.html"/>--> <!--<template path="src/client/webapp/index_template.html" rename="index.html"/>-->
<section if="build_editor"> <section if="build_editor">

View File

@@ -125,6 +125,8 @@ class Render extends SpriteView implements EngineListener {
} }
} }
public function onChange(entity:EntityType):Void {}
public function onCollision(entity:EntityType, with:EntityType):Void { public function onCollision(entity:EntityType, with:EntityType):Void {
switch [entity, with] { switch [entity, with] {
case [EntityType.BULLET(_), EntityType.EAGLE(eagle)]: case [EntityType.BULLET(_), EntityType.EAGLE(eagle)]:

View File

@@ -278,8 +278,8 @@ class BonusItem extends AnimateItem<Bonus> {
} }
override public function redraw():Void { override public function redraw():Void {
var image = Assets.getBitmapData('resources/image/bonus/${value.bonusType}.png'); var image = Assets.getBitmapData('resources/image/bonus/${value.config.type}.png');
view.frames = AnimateBundle.bonusFrames(value.bonusType); view.frames = AnimateBundle.bonusFrames(value.config.type);
view.playing = true; view.playing = true;
} }
} }

View File

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

View File

@@ -136,9 +136,9 @@ tanks:
skin: bb skin: bb
bonuses: bonuses:
- {type: clock} - {type: clock, duration: 10}
- {type: grenade} - {type: grenade}
- {type: helmet} - {type: helmet, duration: 20}
- {type: life} - {type: life}
- {type: shovel} - {type: shovel, duration: 10}
- {type: star} - {type: star}

View File

@@ -53,6 +53,7 @@ typedef TankConfig = {
typedef BonusConfig = { typedef BonusConfig = {
var type:BonusType; var type:BonusType;
@:optional var duration:Int;
} }
typedef TankSpawn = { typedef TankSpawn = {

View File

@@ -1,15 +1,15 @@
package ru.m.tankz.core; package ru.m.tankz.core;
import ru.m.tankz.config.Config;
import ru.m.geom.Rectangle; import ru.m.geom.Rectangle;
import ru.m.tankz.Type;
class Bonus extends Entity { 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)); super(new Rectangle(0, 0, 44, 44));
this.bonusType = bonusType; this.config = config;
} }
} }

View File

@@ -14,6 +14,7 @@ import ru.m.tankz.map.LevelMap;
interface EngineListener { interface EngineListener {
public function onSpawn(entity:EntityType):Void; public function onSpawn(entity:EntityType):Void;
public function onChange(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):Void;
} }
@@ -28,6 +29,8 @@ class CollisionProcessor implements EngineListener {
public function onSpawn(entity:EntityType):Void {} public function onSpawn(entity:EntityType):Void {}
public function onChange(entity:EntityType):Void {}
public function onCollision(entity:EntityType, with:EntityType):Void { public function onCollision(entity:EntityType, with:EntityType):Void {
switch [entity, with] { switch [entity, with] {
case [EntityType.TANK(tank), EntityType.TANK(other_tank)]: case [EntityType.TANK(tank), EntityType.TANK(other_tank)]:
@@ -44,6 +47,7 @@ class CollisionProcessor implements EngineListener {
if (!tank.protect.active) { if (!tank.protect.active) {
if (tank.hits > 0) { if (tank.hits > 0) {
tank.hits--; tank.hits--;
engine.change(tank);
} else { } else {
engine.destroy(tank); engine.destroy(tank);
} }
@@ -59,6 +63,7 @@ class CollisionProcessor implements EngineListener {
engine.destroy(bullet); engine.destroy(bullet);
if (!eagle.protect.active) { if (!eagle.protect.active) {
eagle.death = true; eagle.death = true;
engine.change(eagle);
} }
case _: case _:
} }
@@ -67,8 +72,7 @@ class CollisionProcessor implements EngineListener {
public function onDestroy(entity:EntityType):Void { } public function onDestroy(entity:EntityType):Void { }
} }
@:build(yield.parser.Parser.run()) @:yield
//@:yield //ToDo: not working
class Engine implements ControlHandler { class Engine implements ControlHandler {
public var config(default, default):Config; public var config(default, default):Config;
@@ -97,6 +101,11 @@ class Engine implements ControlHandler {
for (l in listeners) l.onSpawn(type); 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 { public function destroy(entity:Entity):Void {
if (entities.exists(entity.id)) { if (entities.exists(entity.id)) {
var type = EntityTypeResolver.of(entity); var type = EntityTypeResolver.of(entity);

View File

@@ -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 { public function onCollision(entity:EntityType, with:EntityType):Void {
switch entity { switch entity {
case EntityType.TANK(tank): case EntityType.TANK(tank):
@@ -168,9 +179,6 @@ class Game implements EngineListener {
switch [entity, with] { switch [entity, with] {
case [EntityType.TANK(tank), EntityType.BONUS(bonus)]: case [EntityType.TANK(tank), EntityType.BONUS(bonus)]:
applyBonus(tank, bonus); applyBonus(tank, bonus);
case [EntityType.BULLET(_), EntityType.EAGLE(eagle)]:
lose(eagle.team);
deferred.resolve(state);
case _: case _:
} }
} }
@@ -217,7 +225,7 @@ class Game implements EngineListener {
private function spawnBonus(?type:BonusType):Void { private function spawnBonus(?type:BonusType):Void {
var bonusConfig:BonusConfig = type != null ? config.getBonus(type) : config.bonuses[Math.floor(Math.random() * config.bonuses.length)]; 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.x = Math.random() * engine.map.width;
bonus.rect.y = Math.random() * engine.map.height; bonus.rect.y = Math.random() * engine.map.height;
engine.spawn(bonus); engine.spawn(bonus);
@@ -228,8 +236,7 @@ class Game implements EngineListener {
} }
private function applyBonus(tank:Tank, bonus:Bonus):Void { private function applyBonus(tank:Tank, bonus:Bonus):Void {
L.e('XXX', 'applyBonus: ${bonus.bonusType}'); switch (bonus.config.type) {
switch (bonus.bonusType) {
case 'life': case 'life':
getPlayer(tank.playerId).life++; getPlayer(tank.playerId).life++;
case 'star': case 'star':
@@ -238,21 +245,26 @@ class Game implements EngineListener {
} else { } else {
tank.hits++; tank.hits++;
} }
engine.change(tank);
case 'grenade': case 'grenade':
for (t in engine.iterTanks(alienTank(tank.playerId.team))) { for (t in engine.iterTanks(alienTank(tank.playerId.team))) {
engine.destroy(t); engine.destroy(t);
} }
case 'helmet': case 'helmet':
tank.protect.on(20); tank.protect.on(bonus.config.duration);
engine.change(tank);
case 'clock': case 'clock':
for (t in engine.iterTanks(alienTank(tank.playerId.team))) { for (t in engine.iterTanks(alienTank(tank.playerId.team))) {
t.freezing.on(10); t.freezing.on(bonus.config.duration);
engine.change(t);
} }
case 'shovel': case 'shovel':
// ToDo: protect eagle/area // ToDo: protect eagle/area
var team:Team = teams[tank.playerId.team]; var team:Team = teams[tank.playerId.team];
if (team.eagleId > 0) { 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 _: case _:
engine.destroy(tank); // :-D engine.destroy(tank); // :-D