From d47be9ea8a72f426e0300664ddec7eb0c6231e80 Mon Sep 17 00:00:00 2001 From: shmyga Date: Mon, 19 Aug 2019 20:57:36 +0300 Subject: [PATCH] [common] config: add bonus spwan interval --- src/common/haxe/ru/m/tankz/config/Config.hx | 1 + .../haxe/ru/m/tankz/core/TimeInterval.hx | 24 +++++++++++++++++++ src/common/haxe/ru/m/tankz/game/GameRunner.hx | 6 +++++ src/common/resources/config/dota.yaml | 1 + 4 files changed, 32 insertions(+) create mode 100644 src/common/haxe/ru/m/tankz/core/TimeInterval.hx diff --git a/src/common/haxe/ru/m/tankz/config/Config.hx b/src/common/haxe/ru/m/tankz/config/Config.hx index 9445a37..b8c034d 100644 --- a/src/common/haxe/ru/m/tankz/config/Config.hx +++ b/src/common/haxe/ru/m/tankz/config/Config.hx @@ -8,6 +8,7 @@ typedef GameConfig = { var levels:Int; var friendlyFire:Bool; @:optional var alignToGrid:Bool; + @:optional var bonusSpawnInterval:Null; } typedef SpawnPoint = { diff --git a/src/common/haxe/ru/m/tankz/core/TimeInterval.hx b/src/common/haxe/ru/m/tankz/core/TimeInterval.hx new file mode 100644 index 0000000..e34e9a9 --- /dev/null +++ b/src/common/haxe/ru/m/tankz/core/TimeInterval.hx @@ -0,0 +1,24 @@ +package ru.m.tankz.core; + +abstract TimeInterval(Array) { + + public function new(min:Int, ?max:Null) { + 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):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); + } +} diff --git a/src/common/haxe/ru/m/tankz/game/GameRunner.hx b/src/common/haxe/ru/m/tankz/game/GameRunner.hx index 1697533..f231777 100644 --- a/src/common/haxe/ru/m/tankz/game/GameRunner.hx +++ b/src/common/haxe/ru/m/tankz/game/GameRunner.hx @@ -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 { diff --git a/src/common/resources/config/dota.yaml b/src/common/resources/config/dota.yaml index 18942f7..90b72e7 100644 --- a/src/common/resources/config/dota.yaml +++ b/src/common/resources/config/dota.yaml @@ -1,5 +1,6 @@ game: friendlyFire: true + bonusSpawnInterval: 10000 map: cell: