From 3d876e7ef20aef7d15dedb722d6c86c382c80290 Mon Sep 17 00:00:00 2001 From: shmyga Date: Sat, 6 Jan 2018 22:01:27 +0300 Subject: [PATCH] [map] load --- WORK.md | 14 +- src/client/haxe/ru/m/tankz/Client.hx | 118 +++++---- .../haxe/ru/m/tankz/core/PlayerControl.hx | 2 +- src/client/haxe/ru/m/tankz/render/IRender.hx | 1 + src/client/haxe/ru/m/tankz/render/Render.hx | 236 +++++++++++++----- .../haxe/ru/m/tankz/view/frames/GameFrame.hx | 3 +- src/client/resources/images/map/map_3.png | Bin 0 -> 598 bytes src/client/resources/levels/level000.txt | 28 +-- src/common/haxe/ru/m/tankz/config/Config.hx | 17 +- src/common/haxe/ru/m/tankz/core/Entity.hx | 5 + src/common/haxe/ru/m/tankz/core/IEntity.hx | 2 +- src/common/haxe/ru/m/tankz/core/IKey.hx | 5 + .../haxe/ru/m/tankz/core/MobileEntity.hx | 4 + src/common/haxe/ru/m/tankz/map/Brick.hx | 31 +++ src/common/haxe/ru/m/tankz/map/ILevelMap.hx | 11 +- src/common/haxe/ru/m/tankz/map/LevelMap.hx | 23 +- 16 files changed, 330 insertions(+), 170 deletions(-) create mode 100644 src/client/resources/images/map/map_3.png create mode 100644 src/common/haxe/ru/m/tankz/core/IKey.hx create mode 100644 src/common/haxe/ru/m/tankz/map/Brick.hx diff --git a/WORK.md b/WORK.md index 5e24e5a..d7cbe18 100644 --- a/WORK.md +++ b/WORK.md @@ -1,8 +1,8 @@ * build - * gulp + * gulp 100% * deploy - * capistrano + * capistrano 100% * ui * login frame @@ -11,10 +11,10 @@ * game frame * engine - * config - * map - * tanks - * bullets + * config 50% + * map 50% + * tanks 2% + * bullets 2% * boxes * map changes * bonuses @@ -22,4 +22,4 @@ * proto * common - * single game \ No newline at end of file + * single game 2% \ No newline at end of file diff --git a/src/client/haxe/ru/m/tankz/Client.hx b/src/client/haxe/ru/m/tankz/Client.hx index bd9d807..c219dc7 100755 --- a/src/client/haxe/ru/m/tankz/Client.hx +++ b/src/client/haxe/ru/m/tankz/Client.hx @@ -1,5 +1,7 @@ package ru.m.tankz; +import flash.ui.Keyboard; +import flash.events.KeyboardEvent; import flash.text.Font; import ru.m.tankz.view.frames.StartFrame; import haxework.log.SocketLogger; @@ -25,64 +27,70 @@ class MainView extends VGroupView implements ViewBuilder {} class Client implements IConnectionHandler { - private static inline var TAG = "Tankz"; + private static inline var TAG = "Tankz"; - public static function main() { - L.push(new TraceLogger()); - #if flash - L.push(new JSLogger()); - #end - #if debug - L.push(new SocketLogger()); - #end - Const.init(); - L.d(TAG, "Debug: " + Const.DEBUG); - L.i(TAG, "Version: " + Const.VERSION); - L.i(TAG, "Build: " + Const.BUILD); - new Client(); - } - - - private var view:MainView; - - public function new() { - Provider.setFactory(IResources, Resources); - - var font:Font = Font.enumerateFonts()[0]; - Provider.get(IResources).text.put("font", "Bookman Old Style"); - Provider.get(IResources).text.put("version", 'v${Const.VERSION} b${Const.BUILD}'); - - Provider.set(IPacketBuilder, new PacketBuilder()); - #if flash - Provider.set(IConnection, new ru.m.core.connect.flash.FlashConnection("localhost", 5001)); - #elseif html5 - Provider.set(IConnection, new ru.m.core.connect.js.JsConnection("localhost", 5001)); - #end - - Provider.get(IConnection).handler.addListener(this); - - view = new MainView(); - Provider.set(IFrameSwitcher, view.switcher); - Root.bind(view); - //view.logout.onPress = this; - view.switcher.change(StartFrame.ID); - } - - public function onPress(view:ButtonView):Void { - switch (view.id) { - case "logout": - Provider.get(IConnection).disconnect(); + public static function main() { + L.push(new TraceLogger()); + #if flash + L.push(new JSLogger()); + #end + #if debug + L.push(new SocketLogger()); + #end + Const.init(); + L.d(TAG, "Debug: " + Const.DEBUG); + L.i(TAG, "Version: " + Const.VERSION); + L.i(TAG, "Build: " + Const.BUILD); + new Client(); } - } - public function onConnected():Void {} - public function onDisconnected():Void { - //view.switcher.change(AuthFrame.ID); - } + private var view:MainView; - public function onError(error:Dynamic):Void { - L.e(TAG, "", error); - //view.switcher.change(AuthFrame.ID); - } + public function new() { + Provider.setFactory(IResources, Resources); + + var font:Font = Font.enumerateFonts()[0]; + Provider.get(IResources).text.put("font", "Bookman Old Style"); + Provider.get(IResources).text.put("version", 'v${Const.VERSION} b${Const.BUILD}'); + + Provider.set(IPacketBuilder, new PacketBuilder()); + #if flash + Provider.set(IConnection, new ru.m.core.connect.flash.FlashConnection("localhost", 5001)); + #elseif html5 + Provider.set(IConnection, new ru.m.core.connect.js.JsConnection("localhost", 5001)); + #end + + Provider.get(IConnection).handler.addListener(this); + + view = new MainView(); + Provider.set(IFrameSwitcher, view.switcher); + Root.bind(view); + //view.logout.onPress = this; + view.switcher.change(StartFrame.ID); + + view.content.stage.addEventListener(KeyboardEvent.KEY_UP, function(event:KeyboardEvent):Void { + if (event.keyCode == Keyboard.ESCAPE) { + view.switcher.change(StartFrame.ID); + } + }); + } + + public function onPress(view:ButtonView):Void { + switch (view.id) { + case "logout": + Provider.get(IConnection).disconnect(); + } + } + + public function onConnected():Void {} + + public function onDisconnected():Void { + //view.switcher.change(AuthFrame.ID); + } + + public function onError(error:Dynamic):Void { + L.e(TAG, "", error); + //view.switcher.change(AuthFrame.ID); + } } diff --git a/src/client/haxe/ru/m/tankz/core/PlayerControl.hx b/src/client/haxe/ru/m/tankz/core/PlayerControl.hx index 8632804..505eee1 100644 --- a/src/client/haxe/ru/m/tankz/core/PlayerControl.hx +++ b/src/client/haxe/ru/m/tankz/core/PlayerControl.hx @@ -22,7 +22,7 @@ class PlayerControl { moveQueue = new Array(); Lib.current.stage.addEventListener(KeyboardEvent.KEY_DOWN, onKeyDown); Lib.current.stage.addEventListener(KeyboardEvent.KEY_UP, onKeyUp); - Lib.current.stage.addEventListener(FocusEvent.FOCUS_OUT, onFocusOut); + //Lib.current.stage.addEventListener(FocusEvent.FOCUS_OUT, onFocusOut); } private function onKeyDown(event:KeyboardEvent):Void { diff --git a/src/client/haxe/ru/m/tankz/render/IRender.hx b/src/client/haxe/ru/m/tankz/render/IRender.hx index 6ddc8da..9fc25a0 100755 --- a/src/client/haxe/ru/m/tankz/render/IRender.hx +++ b/src/client/haxe/ru/m/tankz/render/IRender.hx @@ -5,4 +5,5 @@ import ru.m.tankz.engine.IEngine; interface IRender extends IView { public function draw(game:IEngine):Void; + public function reset():Void; } diff --git a/src/client/haxe/ru/m/tankz/render/Render.hx b/src/client/haxe/ru/m/tankz/render/Render.hx index 2c8a799..d771f7b 100755 --- a/src/client/haxe/ru/m/tankz/render/Render.hx +++ b/src/client/haxe/ru/m/tankz/render/Render.hx @@ -1,5 +1,7 @@ package ru.m.tankz.render; +import ru.m.tankz.core.Entity; +import ru.m.tankz.map.Brick; import ru.m.tankz.core.Direction; import flash.geom.Matrix; import openfl.Assets; @@ -10,78 +12,188 @@ import flash.display.Graphics; import haxework.gui.SpriteView; import ru.m.tankz.engine.IEngine; + +interface IState { + public function update(object:T):Bool; +} + +class BrickState implements IState { + private var type:BrickType; + + public function new() {} + + public function update(object:Brick):Bool { + if (type != object.type) { + type = object.type; + return true; + } + return false; + } +} + +class EntityState implements IState { + private var x:Float; + private var y:Float; + + public function new() {} + + public function update(object:Entity):Bool { + if (x != object.x || y != object.y) { + x = object.x; + y = object.y; + return true; + } + return false; + } +} + + class Render extends SpriteView implements IRender { - private var mapLayer:Sprite; - private var tankLayer:Sprite; + private static var GROUND_BRICKS:Array = [ + BrickType.BRICK, BrickType.ARMOR, BrickType.WATER, BrickType.ACE + ]; - public function new() { - super(); - mapLayer = new Sprite(); - tankLayer = new Sprite(); - contentAsSprite.addChild(mapLayer); - contentAsSprite.addChild(tankLayer); - } + private static var UP_BRICKS:Array = [ + BrickType.BUSH + ]; - public function draw(game:IEngine):Void { - var mapWidth = game.map.gridWidth * game.map.cellWidth; - var mapHeight = game.map.gridHeight * game.map.cellHeight; + private var backgroundLayer:Sprite; + private var groundLayer:Sprite; + private var entryLayer:Sprite; + private var upLayer:Sprite; - if (contentSize) { - width = mapWidth; - height = mapHeight; + private var layersForUpdate:Map; + private var states:Map>; + + public function new() { + super(); + layersForUpdate = new Map(); + backgroundLayer = new Sprite(); + groundLayer = new Sprite(); + entryLayer = new Sprite(); + upLayer = new Sprite(); + contentAsSprite.addChild(backgroundLayer); + contentAsSprite.addChild(groundLayer); + contentAsSprite.addChild(entryLayer); + contentAsSprite.addChild(upLayer); + reset(); } - var g:Graphics = mapLayer.graphics; - g.clear(); - g.beginFill(0x00ff00); - g.drawRect(0, 0, mapWidth, mapHeight); - g.endFill(); - - g.lineStyle(1, 0x000000); - for (i in 0...game.map.gridWidth + 1) { - g.moveTo(i * game.map.cellWidth, 0); - g.lineTo(i * game.map.cellWidth, mapHeight); + private function invalidateLayers(game:IEngine):Void { + for (brick in game.map.bricks) { + if (!states.exists(brick.key)) { + states[brick.key] = new BrickState(); + } + if (states.get(brick.key).update(brick)) { + layersForUpdate[groundLayer] = true; + layersForUpdate[upLayer] = true; + } + } + for (entry in game.mobileEntities) { + if (!states.exists(entry.key)) { + states[entry.key] = new EntityState(); + } + if (states.get(entry.key).update(entry)) { + layersForUpdate[entryLayer] = true; + } + } } - for (i in 0...game.map.gridHeight + 1) { - g.moveTo(0, i * game.map.cellHeight); - g.lineTo(mapWidth, i * game.map.cellHeight); + + private function drawBackground(game:IEngine):Void { + var mapWidth = game.map.gridWidth * game.map.cellWidth; + var mapHeight = game.map.gridHeight * game.map.cellHeight; + + if (layersForUpdate[backgroundLayer]) { + var g:Graphics = backgroundLayer.graphics; + g.clear(); + g.beginFill(0x000000); + g.drawRect(0, 0, mapWidth, mapHeight); + g.endFill(); + if (contentSize) { + width = mapWidth; + height = mapHeight; + } + layersForUpdate[backgroundLayer] = false; + } } - g.lineStyle(); - var g:Graphics = tankLayer.graphics; - g.clear(); - - for (e in game.mobileEntities) { - if (Std.is(e, Tank)) { - var m = new Matrix(); - m.rotate(calcRotate(e.direction)); - m.translate(e.x, e.y); - g.beginBitmapFill(Assets.getBitmapData("resources/images/tank/player/tank_p0_0-0.png"), m); - g.drawRect(e.x, e.y, e.width, e.height); - g.endFill(); - } else if (Std.is(e, Bullet)) { - var m = new Matrix(); - m.rotate(calcRotate(e.direction)); - m.translate(e.x, e.y); - g.beginBitmapFill(Assets.getBitmapData("resources/images/bullet/bullet_0.png"), m); - g.drawRect(e.x, e.y, e.width, e.height); - g.endFill(); - } + private function drawMap(game:IEngine):Void { + if (layersForUpdate[groundLayer] || layersForUpdate[upLayer]) { + groundLayer.graphics.clear(); + upLayer.graphics.clear(); + for (brick in game.map.bricks) { + var g:Graphics = null; + if (GROUND_BRICKS.indexOf(brick.type) > -1) { + g = groundLayer.graphics; + } else if (UP_BRICKS.indexOf(brick.type) > -1) { + g = upLayer.graphics; + } + if (g != null) { + g.beginFill(0x00ff00); + g.beginBitmapFill(Assets.getBitmapData('resources/images/map/map_${brick.type}.png')); + g.drawRect( + brick.cellX * game.map.cellWidth, + brick.cellY * game.map.cellHeight, + game.map.cellWidth, + game.map.cellHeight + ); + g.endFill(); + } + } + layersForUpdate[groundLayer] = false; + layersForUpdate[upLayer] = false; + } } - } - private function calcRotate(direction:Direction):Float { - return (if (direction == Direction.RIGHT) { - 0; - } else if (direction == Direction.LEFT) { - 180; - } else if (direction == Direction.TOP) { - 270; - } else if (direction == Direction.BOTTOM) { - 90; - } else { - 0; - }) * (Math.PI / 180); - } + public function drawEntries(game:IEngine):Void { + if (layersForUpdate[entryLayer]) { + var g:Graphics = entryLayer.graphics; + g.clear(); + for (e in game.mobileEntities) { + if (Std.is(e, Tank)) { + var m = new Matrix(); + m.rotate(calcRotate(e.direction)); + m.translate(e.x, e.y); + g.beginBitmapFill(Assets.getBitmapData("resources/images/tank/player/tank_p0_0-0.png"), m); + g.drawRect(e.x, e.y, e.width, e.height); + g.endFill(); + } else if (Std.is(e, Bullet)) { + var m = new Matrix(); + m.rotate(calcRotate(e.direction)); + m.translate(e.x, e.y); + g.beginBitmapFill(Assets.getBitmapData("resources/images/bullet/bullet_0.png"), m); + g.drawRect(e.x, e.y, e.width, e.height); + g.endFill(); + } + } + layersForUpdate[entryLayer] = false; + } + } + + public function draw(game:IEngine):Void { + invalidateLayers(game); + drawBackground(game); + drawMap(game); + drawEntries(game); + } + + public function reset():Void { + states = new Map>(); + layersForUpdate[backgroundLayer] = true; + } + + private function calcRotate(direction:Direction):Float { + return (if (direction == Direction.RIGHT) { + 0; + } else if (direction == Direction.LEFT) { + 180; + } else if (direction == Direction.TOP) { + 270; + } else if (direction == Direction.BOTTOM) { + 90; + } else { + 0; + }) * (Math.PI / 180); + } } diff --git a/src/client/haxe/ru/m/tankz/view/frames/GameFrame.hx b/src/client/haxe/ru/m/tankz/view/frames/GameFrame.hx index 5e624a8..82b33ea 100755 --- a/src/client/haxe/ru/m/tankz/view/frames/GameFrame.hx +++ b/src/client/haxe/ru/m/tankz/view/frames/GameFrame.hx @@ -31,7 +31,7 @@ class GameFrame extends VGroupView implements ViewBuilder implements IPacketHand public function onShow():Void { var game:Game = Provider.get(Game); - engine.init(ConfigBundle.get(GameType.CLASSIC)); + engine.init(ConfigBundle.get(GameType.CLASSIC, 0)); engine.initTanks(game.players); content.addEventListener(Event.ENTER_FRAME, updateGame); for (index in 0...game.players.length) { @@ -46,6 +46,7 @@ class GameFrame extends VGroupView implements ViewBuilder implements IPacketHand Provider.get(IConnection).packetHandler.removeListener(this); content.removeEventListener(Event.ENTER_FRAME, updateGame); engine.clear(); + render.reset(); } private function updateGame(_):Void { diff --git a/src/client/resources/images/map/map_3.png b/src/client/resources/images/map/map_3.png new file mode 100644 index 0000000000000000000000000000000000000000..2151ef8a73c5c384558957ae2a5369a828e096c6 GIT binary patch literal 598 zcmV-c0;&CpP)?E_n1xk}C=> zz6N|b2#{tnnT7{@lBXXWs;=0IxataWMZKohlw=FBiXZMtYEAj40*CAK8%Ew{#M8;* zcSvkV4N_?sZCLS-qkvSJP>R_EglS&Y6+C|JEG#wihLQeMZuG|(FW78 z;+^YnO>CWi(1THbvAR-SP^vF)=&EtC%*U%_X}5f?&-L%gG`#rakShv?eZ|LTKC@U8 z<-%&<@>KEW{tYMlwgipm(eJgG#d1YKZO)==12S(Tud7zh8A&cqmFm zHwn;P9rSFEf^L=}1(;3X>@c9}MsZJN^d=+EKIvMat~!cg>{2>A46G+;>E`7NrC3L9 kDxbHQ(bnrK>+&)94b;8i&`iJaP5=M^07*qoM6N<$g4VPmkN^Mx literal 0 HcmV?d00001 diff --git a/src/client/resources/levels/level000.txt b/src/client/resources/levels/level000.txt index e82f25b..7339dae 100644 --- a/src/client/resources/levels/level000.txt +++ b/src/client/resources/levels/level000.txt @@ -1,27 +1 @@ -00000000000000000000000000 -00000000000000000000000000 -00055500055500005000555000 -00550550550550055005505500 -00000050500050555005000500 -00000550500050505005000500 -00055500500050005005000500 -00550000550550055005505500 -00555550055500555500555000 -00000000000000000000000000 -22222222222222222222222222 -22222222222222222222222222 -44111111111144111111111144 -44111111111144111111111144 -00000000005522550000000000 -00000000005522550000000000 -11442255225555552255224411 -11442255225555552255224411 -00000055000044000055000000 -00000055000044000055000000 -33335555005500550055553333 -33335555005500550055553333 -11111111000000000011111111 -11111111000555500011111111 -00000000000500500000000000 -00000000000500500000000000 - +00000000000000000000000000 00000000000000000000000000 00055500055500005000555000 00550550550550055005505500 00000050500050555005000500 00000550500050505000555000 00055500500050005005000500 00550000550550055005505500 00555550055500555500555000 00000000000000000000000000 22222222222222222222222222 22222222222222222222222222 44111111111144111111111144 44111111111144111111111144 00000000005522550000000000 00000000005522550000000000 11442255225555552255224411 11442255225555552255224411 00000055000044000055000000 00000055000044000055000000 33335555005500550055553333 33335555005500550055553333 11111111000000000011111111 11111111000555500011111111 00000000000500500000000000 00000000000500500000000000 \ No newline at end of file diff --git a/src/common/haxe/ru/m/tankz/config/Config.hx b/src/common/haxe/ru/m/tankz/config/Config.hx index 932ac56..50e550a 100644 --- a/src/common/haxe/ru/m/tankz/config/Config.hx +++ b/src/common/haxe/ru/m/tankz/config/Config.hx @@ -1,5 +1,7 @@ package ru.m.tankz.config; +import openfl.utils.Assets; +import ru.m.tankz.map.Brick.BrickType; import ru.m.tankz.proto.core.GameType; import ru.m.tankz.core.Direction; @@ -8,6 +10,8 @@ typedef MapConfig = { var cellHeight:Float; var gridWidth:Int; var gridHeight:Int; + + var bricks:Array; } enum SpawnPointType { @@ -53,7 +57,8 @@ class ConfigBundle { cellWidth: 22, cellHeight: 22, gridWidth: 26, - gridHeight: 26 + gridHeight: 26, + bricks: null }, [ { @@ -73,9 +78,17 @@ class ConfigBundle { ] ); - public static function get(type:Int):Config { + public static function get(type:Int, level:Int):Config { switch (type) { case GameType.CLASSIC: + var bricksData:String = Assets.getText('resources/levels/level00${level}.txt'); + var bricks:Array = []; + for (line in ~/\s+/g.split(bricksData)) { + for (c in line.split('')) { + bricks.push(Std.parseInt(c)); + } + } + CLASSIC.map.bricks = bricks; // ToDo: return CLASSIC; case _: return null; diff --git a/src/common/haxe/ru/m/tankz/core/Entity.hx b/src/common/haxe/ru/m/tankz/core/Entity.hx index 60939de..8debb0f 100755 --- a/src/common/haxe/ru/m/tankz/core/Entity.hx +++ b/src/common/haxe/ru/m/tankz/core/Entity.hx @@ -7,9 +7,14 @@ class Entity implements IEntity { public var width(default, default):Float; public var height(default, default):Float; + public var key(get, null):String; public function new(x:Float, y:Float) { this.x = x; this.y = y; } + + private function get_key():String { + return '${Type.getClassName(Type.getClass(this))}'; + } } diff --git a/src/common/haxe/ru/m/tankz/core/IEntity.hx b/src/common/haxe/ru/m/tankz/core/IEntity.hx index 7f518fc..ea58e34 100755 --- a/src/common/haxe/ru/m/tankz/core/IEntity.hx +++ b/src/common/haxe/ru/m/tankz/core/IEntity.hx @@ -1,6 +1,6 @@ package ru.m.tankz.core; -interface IEntity { +interface IEntity extends IKey { public var x(default, default):Float; public var y(default, default):Float; diff --git a/src/common/haxe/ru/m/tankz/core/IKey.hx b/src/common/haxe/ru/m/tankz/core/IKey.hx new file mode 100644 index 0000000..56e61ec --- /dev/null +++ b/src/common/haxe/ru/m/tankz/core/IKey.hx @@ -0,0 +1,5 @@ +package ru.m.tankz.core; + +interface IKey { + public var key(get, null):String; +} diff --git a/src/common/haxe/ru/m/tankz/core/MobileEntity.hx b/src/common/haxe/ru/m/tankz/core/MobileEntity.hx index 8451111..b35adcc 100755 --- a/src/common/haxe/ru/m/tankz/core/MobileEntity.hx +++ b/src/common/haxe/ru/m/tankz/core/MobileEntity.hx @@ -28,4 +28,8 @@ class MobileEntity extends Entity implements IMobileEntity { mx = 0; my = 0; } + + override private function get_key():String { + return '${super.get_key()}:${id}'; + } } diff --git a/src/common/haxe/ru/m/tankz/map/Brick.hx b/src/common/haxe/ru/m/tankz/map/Brick.hx new file mode 100644 index 0000000..d8463b7 --- /dev/null +++ b/src/common/haxe/ru/m/tankz/map/Brick.hx @@ -0,0 +1,31 @@ +package ru.m.tankz.map; + +import ru.m.tankz.core.IKey; + + +@:enum abstract BrickType(Int) from Int to Int { + var NONE = 0; + var ACE = 1; + var BUSH = 2; + var WATER = 3; + var ARMOR = 4; + var BRICK = 5; +} + + +class Brick implements IKey { + public var cellX(default, null):Int; + public var cellY(default, null):Int; + public var type(default, null):BrickType; + public var key(get, null):String; + + public function new(type:BrickType, cellX:Int, cellY:Int) { + this.cellX = cellX; + this.cellY = cellY; + this.type = type; + } + + public function get_key():String { + return 'brick:${cellX}:${cellY}'; + } +} diff --git a/src/common/haxe/ru/m/tankz/map/ILevelMap.hx b/src/common/haxe/ru/m/tankz/map/ILevelMap.hx index 69c14e7..3d38d3a 100755 --- a/src/common/haxe/ru/m/tankz/map/ILevelMap.hx +++ b/src/common/haxe/ru/m/tankz/map/ILevelMap.hx @@ -1,8 +1,11 @@ package ru.m.tankz.map; + interface ILevelMap { - public var cellWidth(default, null):Float; - public var cellHeight(default, null):Float; - public var gridWidth(default, null):Int; - public var gridHeight(default, null):Int; + public var cellWidth(default, null):Float; + public var cellHeight(default, null):Float; + public var gridWidth(default, null):Int; + public var gridHeight(default, null):Int; + + public var bricks(default, null):Array; } diff --git a/src/common/haxe/ru/m/tankz/map/LevelMap.hx b/src/common/haxe/ru/m/tankz/map/LevelMap.hx index 37883b6..a20d12c 100755 --- a/src/common/haxe/ru/m/tankz/map/LevelMap.hx +++ b/src/common/haxe/ru/m/tankz/map/LevelMap.hx @@ -4,15 +4,18 @@ import ru.m.tankz.config.Config.MapConfig; class LevelMap implements ILevelMap { - public var cellWidth(default, null):Float; - public var cellHeight(default, null):Float; - public var gridWidth(default, null):Int; - public var gridHeight(default, null):Int; + public var cellWidth(default, null):Float; + public var cellHeight(default, null):Float; + public var gridWidth(default, null):Int; + public var gridHeight(default, null):Int; - public function new(config:MapConfig) { - cellWidth = config.cellWidth; - cellHeight = config.cellHeight; - gridWidth = config.gridWidth; - gridHeight = config.gridHeight; - } + public var bricks(default, null):Array; + + public function new(config:MapConfig) { + cellWidth = config.cellWidth; + cellHeight = config.cellHeight; + gridWidth = config.gridWidth; + gridHeight = config.gridHeight; + bricks = Lambda.array(Lambda.mapi(config.bricks, function(i, type):Brick return new Brick(type, Std.int(i % gridWidth), Std.int(Math.floor(i / gridHeight))))); + } }