[map] load
This commit is contained in:
@@ -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<BrickType>;
|
||||
}
|
||||
|
||||
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<BrickType> = [];
|
||||
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;
|
||||
|
||||
@@ -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))}';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
5
src/common/haxe/ru/m/tankz/core/IKey.hx
Normal file
5
src/common/haxe/ru/m/tankz/core/IKey.hx
Normal file
@@ -0,0 +1,5 @@
|
||||
package ru.m.tankz.core;
|
||||
|
||||
interface IKey {
|
||||
public var key(get, null):String;
|
||||
}
|
||||
@@ -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}';
|
||||
}
|
||||
}
|
||||
|
||||
31
src/common/haxe/ru/m/tankz/map/Brick.hx
Normal file
31
src/common/haxe/ru/m/tankz/map/Brick.hx
Normal file
@@ -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}';
|
||||
}
|
||||
}
|
||||
@@ -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<Brick>;
|
||||
}
|
||||
|
||||
@@ -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<Brick>;
|
||||
|
||||
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)))));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user