[common] config: add bonus spwan interval

This commit is contained in:
2019-08-19 20:57:36 +03:00
parent 2d70a5652b
commit d47be9ea8a
4 changed files with 32 additions and 0 deletions

View File

@@ -8,6 +8,7 @@ typedef GameConfig = {
var levels:Int;
var friendlyFire:Bool;
@:optional var alignToGrid:Bool;
@:optional var bonusSpawnInterval:Null<Int>;
}
typedef SpawnPoint = {

View File

@@ -0,0 +1,24 @@
package ru.m.tankz.core;
abstract TimeInterval(Array<Int>) {
public function new(min:Int, ?max:Null<Int>) {
this = [min, max != null ? max : min]
}
public function resolve():Int {
return this[0] + (this[1] - this[0]) * Math.random();
}
@:from public static function fromArray(value:Array<Int>):TimeInterval {
return new TimeInterval(value[0], value[1]);
}
@:from public static function fromInt(value:Int):TimeInterval {
return new TimeInterval(value);
}
@:from public static function fromFloat(value:Float):TimeInterval {
return new TimeInterval(value * 1000);
}
}

View File

@@ -84,6 +84,9 @@ class GameRunner extends Game implements EngineListener {
}
gameEventSignal.emit(EventUtil.buildBricksSpawn(engine.map));
//for (i in 0...10) spawnBonus();
if (config.game.bonusSpawnInterval != null) {
ticker.emit(function() spawnBonus(), config.game.bonusSpawnInterval, "bonus");
}
}
private function spawn(task:SpawnTask):Void {
@@ -233,6 +236,9 @@ class GameRunner extends Game implements EngineListener {
var bonus = builder.buildBonus(point, type);
engine.spawn(bonus);
gameEventSignal.emit(EventUtil.buildBonusSpawn(bonus));
if (config.game.bonusSpawnInterval != null) {
ticker.emit(function() spawnBonus(), config.game.bonusSpawnInterval, "bonus");
}
}
private function applyBonus(tank:Tank, bonus:Bonus):Void {

View File

@@ -1,5 +1,6 @@
game:
friendlyFire: true
bonusSpawnInterval: 10000
map:
cell: