[common] config: add bonus spwan interval
This commit is contained in:
@@ -8,6 +8,7 @@ typedef GameConfig = {
|
||||
var levels:Int;
|
||||
var friendlyFire:Bool;
|
||||
@:optional var alignToGrid:Bool;
|
||||
@:optional var bonusSpawnInterval:Null<Int>;
|
||||
}
|
||||
|
||||
typedef SpawnPoint = {
|
||||
|
||||
24
src/common/haxe/ru/m/tankz/core/TimeInterval.hx
Normal file
24
src/common/haxe/ru/m/tankz/core/TimeInterval.hx
Normal 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);
|
||||
}
|
||||
}
|
||||
@@ -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 {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
game:
|
||||
friendlyFire: true
|
||||
bonusSpawnInterval: 10000
|
||||
|
||||
map:
|
||||
cell:
|
||||
|
||||
Reference in New Issue
Block a user