diff --git a/gulpfile.js b/gulpfile.js index f12ab13..b62604d 100755 --- a/gulpfile.js +++ b/gulpfile.js @@ -120,7 +120,7 @@ const editor = new Project( height: 850, }, flags: [ - //'dev_layout', + 'dev_layout', ] }) ).bind(module, gulp); diff --git a/src/client/haxe/ru/m/tankz/render/IRender.hx b/src/client/haxe/ru/m/tankz/render/IRender.hx index 1bcd37b..f0464a1 100644 --- a/src/client/haxe/ru/m/tankz/render/IRender.hx +++ b/src/client/haxe/ru/m/tankz/render/IRender.hx @@ -6,6 +6,7 @@ import ru.m.tankz.game.IGame; interface IRender extends IView extends GameListener { public var config(default, set):Config; + public var gridSize(default, set):GridSize; public function draw():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 5e46989..1863614 100755 --- a/src/client/haxe/ru/m/tankz/render/Render.hx +++ b/src/client/haxe/ru/m/tankz/render/Render.hx @@ -26,6 +26,10 @@ using ru.m.display.DisplayObjectContainerExtender; class Render extends SpriteView implements IRender { public var config(default, set):Config; + public var gridSize(default, set):GridSize; + + private var mapWidth(get, null):Float; + private var mapHeight(get, null):Float; private var backgroundLayer:Sprite; private var groundLayer:Sprite; @@ -51,18 +55,33 @@ class Render extends SpriteView implements IRender { reset(); } + private function get_mapWidth():Float { + return config.map.cell.width * (gridSize != null ? gridSize.width : config.map.grid.width); + } + + private function get_mapHeight():Float { + return config.map.cell.height * (gridSize != null ? gridSize.height : config.map.grid.height); + } + private function set_config(value:Config):Config { config = value; - setContentSize(config.mapWidth, config.mapHeight); + setContentSize(mapWidth, mapHeight, "render"); drawBackground(); return config; } + private function set_gridSize(value:GridSize):GridSize { + gridSize = value; + setContentSize(mapWidth, mapHeight, "render"); + drawBackground(); + return gridSize; + } + private function drawBackground():Void { var g:Graphics = backgroundLayer.graphics; g.clear(); g.beginFill(0x000000); - g.drawRect(0, 0, config.mapWidth, config.mapHeight); + g.drawRect(0, 0, mapWidth, mapHeight); g.endFill(); } diff --git a/src/client/haxe/ru/m/tankz/view/GameFrame.hx b/src/client/haxe/ru/m/tankz/view/GameFrame.hx index ac22042..159b923 100644 --- a/src/client/haxe/ru/m/tankz/view/GameFrame.hx +++ b/src/client/haxe/ru/m/tankz/view/GameFrame.hx @@ -34,6 +34,7 @@ import ru.m.tankz.view.game.GameView; gameView.type = game.type; soundManager.config = game.config; gameView.render.config = game.config; + gameView.render.gridSize = game.state.level.size; game.connect(gameView.render); game.connect(soundManager); if (gameView.panel != null) { diff --git a/src/common/haxe/ru/m/tankz/config/Config.hx b/src/common/haxe/ru/m/tankz/config/Config.hx index 9d8e045..17cce70 100644 --- a/src/common/haxe/ru/m/tankz/config/Config.hx +++ b/src/common/haxe/ru/m/tankz/config/Config.hx @@ -23,11 +23,19 @@ typedef SpawnPoint = { var direction:String; } +typedef CellSize = { + var width:Float; + var height:Float; +} + +typedef GridSize = { + var width:Int; + var height:Int; +} + typedef MapConfig = { - var cellWidth:Float; - var cellHeight:Float; - var gridWidth:Int; - var gridHeight:Int; + var cell:CellSize; + var grid:GridSize; } typedef BrickConfig = { @@ -103,6 +111,7 @@ typedef LevelConfig = { var data:Array; @:optional var name:String; @:optional var points:Array; + @:optional var size:{width:Int, height:Int}; } typedef PlayerControl = { @@ -139,8 +148,6 @@ class Config { public var controls(default, null):Array; public var points(default, null):Array; public var bonuses(default, null):Array; - public var mapWidth(get, null):Float; - public var mapHeight(get, null):Float; private var brickMap:Map; private var brickMapByIndex:Map; @@ -208,14 +215,6 @@ class Config { } } - private function get_mapWidth():Float { - return map.cellWidth * map.gridWidth; - } - - private function get_mapHeight():Float { - return map.cellHeight * map.gridHeight; - } - public function getBrick(type:BrickType):BrickConfig { return brickMap.get(type); } diff --git a/src/common/haxe/ru/m/tankz/engine/Engine.hx b/src/common/haxe/ru/m/tankz/engine/Engine.hx index 1cb27a4..6036b71 100755 --- a/src/common/haxe/ru/m/tankz/engine/Engine.hx +++ b/src/common/haxe/ru/m/tankz/engine/Engine.hx @@ -21,9 +21,9 @@ import ru.m.tankz.map.LevelMap; public var allEntities(default, null):Map; - public function new(config:Config) { + public function new(config:Config, size:GridSize = null) { this.config = config; - map = new LevelMap(config.map); + map = new LevelMap(config.map, size); allEntities = new Map(); entities = new Map(); ticker = new Ticker(); diff --git a/src/common/haxe/ru/m/tankz/game/EntityBuilder.hx b/src/common/haxe/ru/m/tankz/game/EntityBuilder.hx index 1f93b9b..f3b4966 100644 --- a/src/common/haxe/ru/m/tankz/game/EntityBuilder.hx +++ b/src/common/haxe/ru/m/tankz/game/EntityBuilder.hx @@ -29,8 +29,8 @@ class EntityBuilder { public function buildRect(point:EntityPoint, width:Float, height:Float):Rectangle { return new Rectangle( - (point.x + 1) * config.map.cellWidth - width / 2, - (point.y + 1) * config.map.cellHeight - height / 2, + (point.x + 1) * config.map.cell.width - width / 2, + (point.y + 1) * config.map.cell.height - height / 2, width, height, Direction.fromString(point.direction) @@ -39,7 +39,7 @@ class EntityBuilder { public function buildEagle(point:EntityPoint, teamId:TeamId):Eagle { var eageleConfig = config.getTeam(teamId).eagle; - var eagle = new Eagle(++entityId, buildRect(point, config.map.cellWidth * 2, config.map.cellHeight * 2), teamId, eageleConfig); + var eagle = new Eagle(++entityId, buildRect(point, config.map.cell.width * 2, config.map.cell.height * 2), teamId, eageleConfig); eagle.color = config.getColor(new PlayerId(teamId, -1)); return eagle; } @@ -65,7 +65,7 @@ class EntityBuilder { public function buildBonus(point:EntityPoint, type:BonusType):Bonus { var bonusConfig = config.getBonus(type); - var bonus = new Bonus(++entityId, buildRect(point, config.map.cellWidth * 2, config.map.cellHeight * 2), bonusConfig); + var bonus = new Bonus(++entityId, buildRect(point, config.map.cell.width * 2, config.map.cell.height * 2), bonusConfig); return bonus; } } diff --git a/src/common/haxe/ru/m/tankz/game/GameRunner.hx b/src/common/haxe/ru/m/tankz/game/GameRunner.hx index 78efae3..448d2ce 100644 --- a/src/common/haxe/ru/m/tankz/game/GameRunner.hx +++ b/src/common/haxe/ru/m/tankz/game/GameRunner.hx @@ -22,7 +22,7 @@ class GameRunner extends Game implements EngineListener { public function new(state:GameState) { super(state); this.builder = new EntityBuilder(config); - this.engine = new Engine(config); + this.engine = new Engine(config, state.level.size); this.engine.connect(this); } diff --git a/src/common/haxe/ru/m/tankz/map/Brick.hx b/src/common/haxe/ru/m/tankz/map/Brick.hx index 1359203..1eaad21 100644 --- a/src/common/haxe/ru/m/tankz/map/Brick.hx +++ b/src/common/haxe/ru/m/tankz/map/Brick.hx @@ -27,10 +27,10 @@ class Brick { this.mapConfig = mapConfig; this.config = config; this.rect = new Rectangle( - cellX * mapConfig.cellWidth, - cellY * mapConfig.cellHeight, - mapConfig.cellWidth, - mapConfig.cellHeight + cellX * mapConfig.cell.width, + cellY * mapConfig.cell.height, + mapConfig.cell.width, + mapConfig.cell.height ); } diff --git a/src/common/haxe/ru/m/tankz/map/Grid.hx b/src/common/haxe/ru/m/tankz/map/Grid.hx index bfa081c..54ece06 100644 --- a/src/common/haxe/ru/m/tankz/map/Grid.hx +++ b/src/common/haxe/ru/m/tankz/map/Grid.hx @@ -1,5 +1,7 @@ package ru.m.tankz.map; +import ru.m.tankz.config.Config.GridSize; +import ru.m.tankz.config.Config.CellSize; import ru.m.geom.Line; import ru.m.geom.Point; import ru.m.geom.Rectangle; diff --git a/src/common/haxe/ru/m/tankz/map/LevelMap.hx b/src/common/haxe/ru/m/tankz/map/LevelMap.hx index 7c7aa35..c51a1b3 100755 --- a/src/common/haxe/ru/m/tankz/map/LevelMap.hx +++ b/src/common/haxe/ru/m/tankz/map/LevelMap.hx @@ -24,12 +24,12 @@ class LevelMap { private var bricksMap(default, null):HashMap; - public function new(config:MapConfig) { + public function new(config:MapConfig, size:GridSize = null) { this.config = config; - cellWidth = config.cellWidth; - cellHeight = config.cellHeight; - gridWidth = config.gridWidth; - gridHeight = config.gridHeight; + cellWidth = config.cell.width; + cellHeight = config.cell.width; + gridWidth = size != null ? size.width : config.grid.width; + gridHeight = size != null ? size.height : config.grid.width; bricksMap = new HashMap(); bricks = []; grid = new Grid( @@ -67,16 +67,16 @@ class LevelMap { } public function getPointBrick(point:Point):Brick { - var cellX:Int = Math.floor(point.x / config.cellWidth); - var cellY:Int = Math.floor(point.y / config.cellHeight); - return bricks[cellX + cellY * config.gridWidth]; + var cellX:Int = Math.floor(point.x / cellWidth); + var cellY:Int = Math.floor(point.y / cellHeight); + return bricks[cellX + cellY * gridWidth]; } private inline function get_width():Float { - return config.cellWidth * config.gridWidth; + return cellWidth * gridWidth; } private inline function get_height():Float { - return config.cellHeight * config.gridHeight; + return cellHeight * gridHeight; } } diff --git a/src/common/haxe/ru/m/tankz/util/LevelUtil.hx b/src/common/haxe/ru/m/tankz/util/LevelUtil.hx index 6bc6941..4caeca2 100644 --- a/src/common/haxe/ru/m/tankz/util/LevelUtil.hx +++ b/src/common/haxe/ru/m/tankz/util/LevelUtil.hx @@ -9,6 +9,7 @@ typedef LevelSource = { var data:String; @:optional var name:String; @:optional var points:Array; + @:optional var size:GridSize; } class LevelUtil { @@ -42,6 +43,7 @@ class LevelUtil { data: obj.data.split('').map(function(c) return config.getBrickByIndex(Std.parseInt(c))), points: obj.points, name: obj.name, + size: obj.size, } } } @@ -52,12 +54,13 @@ class LevelUtil { data: bricksStr, points: level.points, name: level.name, + size: level.size, }, Renderer.options().setFlowLevel(1)); } - public static function empty(config:Config):LevelConfig { + public static function empty(size:GridSize, filler:BrickConfig):LevelConfig { return { - data: [for (i in 0...config.map.gridWidth * config.map.gridHeight) config.bricks[1]] + data: [for (i in 0...size.width * size.height) filler] } } } diff --git a/src/common/resources/classic/config.yaml b/src/common/resources/classic/config.yaml index 828d750..04938bb 100644 --- a/src/common/resources/classic/config.yaml +++ b/src/common/resources/classic/config.yaml @@ -5,10 +5,12 @@ game: - team: human map: - cellWidth: 22 - cellHeight: 22 - gridWidth: 26 - gridHeight: 26 + cell: + width: 22 + height: 22 + grid: + width: 26 + height: 26 bricks: - {type: border, index: -1, layer: 2, armor: -1} diff --git a/src/common/resources/death/config.yaml b/src/common/resources/death/config.yaml index eac3145..9cf579a 100644 --- a/src/common/resources/death/config.yaml +++ b/src/common/resources/death/config.yaml @@ -1,14 +1,16 @@ game: - levels: 1 + levels: 2 friendlyFire: true complete: - team: alpha map: - cellWidth: 22 - cellHeight: 22 - gridWidth: 20 - gridHeight: 20 + cell: + width: 22 + height: 22 + grid: + width: 20 + height: 20 bricks: - {type: border, index: -1, layer: 2, armor: -1} diff --git a/src/common/resources/death/levels/level001.txt b/src/common/resources/death/levels/level001.txt new file mode 100644 index 0000000..27b84c1 --- /dev/null +++ b/src/common/resources/death/levels/level001.txt @@ -0,0 +1,4 @@ +name: test +size: {width: 36, height: 23} +points: [{direction: right, x: 0, index: 0, team: alpha, y: 0, type: tank}, {direction: right, x: 11, index: 0, team: beta, y: 0, type: tank}, {direction: right, x: 19, index: 0, team: gamma, y: 0, type: tank}, {direction: right, x: 0, index: 0, team: delta, y: 10, type: tank}, {direction: right, x: 15, index: 0, team: epsilon, y: 10, type: tank}, {direction: right, x: 7, index: 0, team: zeta, y: 7, type: tank}, {direction: right, x: 2, index: 0, team: eta, y: 6, type: tank}, {direction: right, x: 5, index: 0, team: theta, y: 2, type: tank}] +data: "0000000000000000000000000000000000000000000000000220000000000000000005222210000000000000445512220000000000044005500000000000004411115000000000000440000000000000000044000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" diff --git a/src/common/resources/dota/config.yaml b/src/common/resources/dota/config.yaml index a0bbf17..242d61d 100644 --- a/src/common/resources/dota/config.yaml +++ b/src/common/resources/dota/config.yaml @@ -5,10 +5,12 @@ game: - team: radiant map: - cellWidth: 22 - cellHeight: 22 - gridWidth: 40 - gridHeight: 30 + cell: + width: 22 + height: 22 + grid: + width: 40 + height: 30 bricks: - {type: border, index: -1, layer: 2, armor: -1} diff --git a/src/editor/haxe/ru/m/tankz/editor/frame/LevelFrame.hx b/src/editor/haxe/ru/m/tankz/editor/frame/LevelFrame.hx index 6d04fea..0863304 100644 --- a/src/editor/haxe/ru/m/tankz/editor/frame/LevelFrame.hx +++ b/src/editor/haxe/ru/m/tankz/editor/frame/LevelFrame.hx @@ -29,6 +29,8 @@ import ru.m.tankz.util.LevelUtil; @:view var mapView:MapEditView; @:view var spawnPointList:DataView; @:view var brickList:DataView; + @:view("width") var widthInput:InputView; + @:view("height") var heightInput:InputView; @:provide var configBundle:IConfigBundle; @:provide var config:Config; @@ -68,7 +70,6 @@ import ru.m.tankz.util.LevelUtil; config = configBundle.get(type); mapView.config = config; - mapView.data = LevelUtil.empty(config); brickList.data = config.bricks.filter(function(brick) return brick.index > -1); spawnPointList.data = config.points; @@ -90,6 +91,13 @@ import ru.m.tankz.util.LevelUtil; var data = LevelUtil.loads(config, content.content); mapView.data = data; levelName.text = data.name; + /*if (data.size != null) { + widthInput.text = Std.string(data.size.width); + heightInput.text = Std.string(data.size.height); + } else { + widthInput.text = ""; + heightInput.text = ""; + }*/ }); case 'saveButton': L.d(TAG, 'SAVE'); @@ -102,4 +110,12 @@ import ru.m.tankz.util.LevelUtil; case _: } } + + private function applySize():Void { + mapView.gridSize = {width: Std.parseInt(widthInput.text), height: Std.parseInt(heightInput.text)}; + } + + private function resetSize():Void { + mapView.gridSize = null; + } } diff --git a/src/editor/haxe/ru/m/tankz/editor/frame/LevelFrame.yaml b/src/editor/haxe/ru/m/tankz/editor/frame/LevelFrame.yaml index 84436d7..12225d1 100644 --- a/src/editor/haxe/ru/m/tankz/editor/frame/LevelFrame.yaml +++ b/src/editor/haxe/ru/m/tankz/editor/frame/LevelFrame.yaml @@ -30,6 +30,24 @@ views: geometry.size.width: 300 geometry.size.height: 26 text: "" + - $type: haxework.view.HGroupView + views: + - id: width + $type: haxework.view.InputView + skinId: text.box + geometry.size.fixed: [50, 26] + - id: height + $type: haxework.view.InputView + skinId: text.box + geometry.size.fixed: [50, 26] + - $type: haxework.view.ButtonView + skinId: button.simple + text: apply + +onPress: "$code:applySize()" + - $type: haxework.view.ButtonView + skinId: button.simple + text: reset + +onPress: "$code:resetSize()" # map - $type: haxework.view.HGroupView views: diff --git a/src/editor/haxe/ru/m/tankz/editor/level/MapEditView.hx b/src/editor/haxe/ru/m/tankz/editor/level/MapEditView.hx index 05bfa3b..fa1e7d7 100644 --- a/src/editor/haxe/ru/m/tankz/editor/level/MapEditView.hx +++ b/src/editor/haxe/ru/m/tankz/editor/level/MapEditView.hx @@ -1,5 +1,6 @@ package ru.m.tankz.editor.level; +import ru.m.tankz.util.LevelUtil; import flash.display.Graphics; import flash.events.MouseEvent; import ru.m.geom.Point; @@ -40,21 +41,31 @@ enum Brush { } override private function set_config(value:Config):Config { + var result = super.set_config(value); builder = new EntityBuilder(value); - return super.set_config(value); + data = LevelUtil.empty(gridSize != null ? gridSize : config.map.grid, config.bricks[1]); + return result; + } + + override private function set_gridSize(value:GridSize):GridSize { + var result = super.set_gridSize(value); + data = LevelUtil.empty(gridSize != null ? gridSize : config.map.grid, config.bricks[1]); + return result; } override private function drawBackground():Void { super.drawBackground(); var g:Graphics = backgroundLayer.graphics; g.lineStyle(1, 0x007700); - for (x in 0...config.map.gridWidth) { - g.moveTo(x * config.map.cellWidth, 0); - g.lineTo(x * config.map.cellWidth, config.mapHeight); + var gridWidth = gridSize != null ? gridSize.width : config.map.grid.width; + var gridHeight = gridSize != null ? gridSize.height : config.map.grid.height; + for (x in 0...gridWidth) { + g.moveTo(x * config.map.cell.width, 0); + g.lineTo(x * config.map.cell.height, mapHeight); } - for (y in 0...config.map.gridHeight) { - g.moveTo(0, y * config.map.cellHeight); - g.lineTo(config.mapWidth, y * config.map.cellHeight); + for (y in 0...gridHeight) { + g.moveTo(0, y * config.map.cell.height); + g.lineTo(mapWidth, y * config.map.cell.height); } } @@ -95,6 +106,7 @@ enum Brush { return { data: map.bricks.map(function(brick:Brick) return brick.config), points: config.points, + size: gridSize, } } @@ -102,8 +114,8 @@ enum Brush { reset(); pointEntities = new Map(); map = new LevelMap(config.map); - setContentSize(map.gridWidth * map.cellWidth, map.gridHeight * map.cellHeight, "map"); map.setData(value.data); + gridSize = value.size; gameEventSignal.emit(EventUtil.buildBricksSpawn(map)); for (point in config.points) { switch point.type {