diff --git a/src/client/haxe/ru/m/tankz/render/Render.hx b/src/client/haxe/ru/m/tankz/render/Render.hx index 93122e0..29fc348 100755 --- a/src/client/haxe/ru/m/tankz/render/Render.hx +++ b/src/client/haxe/ru/m/tankz/render/Render.hx @@ -89,6 +89,11 @@ class Render extends SpriteView implements EngineListener { items.set(bullet.key, item); entryLayer.addChild(item.view); item.update(); + case EntityType.EAGLE(eagle): + var item = new EagleItem(eagle); + items.set(eagle.key, item); + entryLayer.addChild(item.view); + item.update(); case _: } } @@ -109,6 +114,11 @@ class Render extends SpriteView implements EngineListener { entryLayer.removeChild(items.get(bullet.key).view); items.remove(bullet.key); } + case EntityType.EAGLE(eagle): + if (items.exists(eagle.key)) { + cast(items.get(eagle.key), EagleItem).destoyed = true; + items.get(eagle.key).redraw(); + } case _: } } diff --git a/src/client/haxe/ru/m/tankz/render/RenderItem.hx b/src/client/haxe/ru/m/tankz/render/RenderItem.hx index 984d794..c61271c 100644 --- a/src/client/haxe/ru/m/tankz/render/RenderItem.hx +++ b/src/client/haxe/ru/m/tankz/render/RenderItem.hx @@ -1,5 +1,6 @@ package ru.m.tankz.render; +import ru.m.tankz.core.Eagle; import flash.display.DisplayObject; import flash.display.Shape; import ru.m.geom.Direction; @@ -133,3 +134,13 @@ class BulletItem extends RenderItem { return 'resources/images/bullet/bullet_${value.config.piercing > 1 ? 1 : 0}.png'; } } + + +class EagleItem extends RenderItem { + + public var destoyed(default, default):Bool; + + override private function getImage():String { + return 'resources/images/eagle/eagle-${destoyed ? 1 : 0}.png'; + } +} diff --git a/src/client/resources/config/classic.yaml b/src/client/resources/config/classic.yaml index 5d3048f..622c7cf 100644 --- a/src/client/resources/config/classic.yaml +++ b/src/client/resources/config/classic.yaml @@ -44,7 +44,7 @@ teams: index: -1 x: 12 y: 24 - direction: top + direction: right - type: tank index: 0 x: 8 diff --git a/src/common/haxe/ru/m/tankz/core/Eagle.hx b/src/common/haxe/ru/m/tankz/core/Eagle.hx index 0f856ba..e1fb93b 100644 --- a/src/common/haxe/ru/m/tankz/core/Eagle.hx +++ b/src/common/haxe/ru/m/tankz/core/Eagle.hx @@ -6,6 +6,6 @@ import ru.m.geom.Rectangle; class Eagle extends Entity { public function new() { - super(new Rectangle(0, 0, 10, 10)); + super(new Rectangle(0, 0, 44, 44)); } } diff --git a/src/common/haxe/ru/m/tankz/game/Game.hx b/src/common/haxe/ru/m/tankz/game/Game.hx index 06ea91f..63ee8e0 100644 --- a/src/common/haxe/ru/m/tankz/game/Game.hx +++ b/src/common/haxe/ru/m/tankz/game/Game.hx @@ -1,14 +1,17 @@ package ru.m.tankz.game; -import haxe.Timer; -import ru.m.tankz.core.EntityType; +import ru.m.tankz.game.Spawner; +import ru.m.tankz.core.Entity; +import ru.m.tankz.core.Eagle; import ru.m.geom.Direction; import ru.m.geom.Point; import ru.m.tankz.config.Config; import ru.m.tankz.control.Control; +import ru.m.tankz.core.EntityType; import ru.m.tankz.core.Tank; import ru.m.tankz.engine.Engine; + typedef GameType = String; typedef TeamId = String; @@ -19,74 +22,6 @@ typedef PlayerId = { } -typedef SpawnTask = { - var point:SpawnPoint; - var playerId:PlayerId; -} - - -class Spawner { - - private var config:TeamConfig; - private var runner:SpawnTask -> Void; - private var queue:Array; - private var timer:Timer; - - private var indexedPoints:Map; - private var anyPoints:Array; - private var index:Int; - - public function new(config:TeamConfig, runner:SpawnTask -> Void) { - this.config = config; - this.runner = runner; - queue = []; - indexedPoints = new Map(); - anyPoints = []; - for (point in config.points) { - if (point.type == 'tank') { - if (point.index > -1) { - indexedPoints.set(point.index, point); - } else { - anyPoints.push(point); - } - } - } - } - - public function push(playerId:PlayerId):Void { - var point:SpawnPoint = null; - if (indexedPoints.exists(playerId.index)) { - point = indexedPoints.get(playerId.index); - } else { - point = anyPoints[index++]; - if (index >= anyPoints.length) index = 0; - } - if (point != null) { - queue.push({playerId:playerId, point:point}); - run(); - } - } - - private function run():Void { - if (timer == null) { - timer = new Timer(config.spawnInterval); - timer.run = spawn; - } - } - - private function spawn():Void { - if (queue.length == 0) { - if (timer != null) { - timer.stop(); - timer = null; - } - } else { - runner(queue.shift()); - } - } -} - - class Game implements EngineListener implements ControlListener { public var type(default, null):GameType; @@ -109,11 +44,15 @@ class Game implements EngineListener implements ControlListener { private function buildTank(playerId:PlayerId, config:TankConfig, point:SpawnPoint):Tank { var tank = new Tank(playerId, config); - tank.rect.center = new Point((point.x + 1) * engine.map.cellWidth, (point.y + 1) * engine.map.cellHeight); - tank.rect.direction = Direction.fromString(point.direction); + applyPoint(tank, point); return tank; } + private function applyPoint(entity:Entity, point:SpawnPoint):Void { + entity.rect.center = new Point((point.x + 1) * engine.map.cellWidth, (point.y + 1) * engine.map.cellHeight); + entity.rect.direction = Direction.fromString(point.direction); + } + public function start():Void { teams = new Map(); spawners = new Map(); @@ -129,9 +68,14 @@ class Game implements EngineListener implements ControlListener { for (team in teams) { for (player in team.players) { - var point = team.config.points[0]; spawners.get(team.id).push(player.id); } + var eaglePoint = spawners.get(team.id).getPoint('eagle'); + if (eaglePoint != null) { + var eagle = new Eagle(); + applyPoint(eagle, eaglePoint); + engine.spawn(eagle); + } } } diff --git a/src/common/haxe/ru/m/tankz/game/Spawner.hx b/src/common/haxe/ru/m/tankz/game/Spawner.hx new file mode 100644 index 0000000..7db2992 --- /dev/null +++ b/src/common/haxe/ru/m/tankz/game/Spawner.hx @@ -0,0 +1,83 @@ +package ru.m.tankz.game; + + +import haxe.Timer; +import ru.m.tankz.game.Game; +import ru.m.tankz.config.Config; + + +typedef SpawnTask = { + var point:SpawnPoint; + var playerId:PlayerId; +} + + +class Spawner { + + private var config:TeamConfig; + private var runner:SpawnTask -> Void; + private var queue:Array; + private var timer:Timer; + + private var indexedPoints:Map; + private var anyPoints:Array; + private var index:Int; + + public function new(config:TeamConfig, runner:SpawnTask -> Void) { + this.config = config; + this.runner = runner; + queue = []; + indexedPoints = new Map(); + anyPoints = []; + for (point in config.points) { + if (point.type == 'tank') { + if (point.index > -1) { + indexedPoints.set(point.index, point); + } else { + anyPoints.push(point); + } + } + } + } + + public function getPoint(type:String, index:Int=-1):Null { + for (point in config.points) { + if (point.type == type && point.index == index) { + return point; + } + } + return null; + } + + public function push(playerId:PlayerId):Void { + var point:SpawnPoint = null; + if (indexedPoints.exists(playerId.index)) { + point = indexedPoints.get(playerId.index); + } else { + point = anyPoints[index++]; + if (index >= anyPoints.length) index = 0; + } + if (point != null) { + queue.push({playerId:playerId, point:point}); + run(); + } + } + + private function run():Void { + if (timer == null) { + timer = new Timer(config.spawnInterval); + timer.run = spawn; + } + } + + private function spawn():Void { + if (queue.length == 0) { + if (timer != null) { + timer.stop(); + timer = null; + } + } else { + runner(queue.shift()); + } + } +} \ No newline at end of file