[common] add map size
This commit is contained in:
@@ -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<BrickConfig>;
|
||||
@:optional var name:String;
|
||||
@:optional var points:Array<SpawnPoint>;
|
||||
@:optional var size:{width:Int, height:Int};
|
||||
}
|
||||
|
||||
typedef PlayerControl = {
|
||||
@@ -139,8 +148,6 @@ class Config {
|
||||
public var controls(default, null):Array<ControlPreset>;
|
||||
public var points(default, null):Array<SpawnPoint>;
|
||||
public var bonuses(default, null):Array<BonusConfig>;
|
||||
public var mapWidth(get, null):Float;
|
||||
public var mapHeight(get, null):Float;
|
||||
|
||||
private var brickMap:Map<BrickType, BrickConfig>;
|
||||
private var brickMapByIndex:Map<Int, BrickConfig>;
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -21,9 +21,9 @@ import ru.m.tankz.map.LevelMap;
|
||||
|
||||
public var allEntities(default, null):Map<Int, Entity>;
|
||||
|
||||
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();
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -24,12 +24,12 @@ class LevelMap {
|
||||
|
||||
private var bricksMap(default, null):HashMap<Point, Brick>;
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ typedef LevelSource = {
|
||||
var data:String;
|
||||
@:optional var name:String;
|
||||
@:optional var points:Array<SpawnPoint>;
|
||||
@: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]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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}
|
||||
|
||||
@@ -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}
|
||||
|
||||
4
src/common/resources/death/levels/level001.txt
Normal file
4
src/common/resources/death/levels/level001.txt
Normal file
@@ -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"
|
||||
@@ -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}
|
||||
|
||||
Reference in New Issue
Block a user