diff --git a/build/client.js b/build/client.js
index 04baa9d..7fdb160 100755
--- a/build/client.js
+++ b/build/client.js
@@ -64,7 +64,7 @@ exports['client'] = gulp.series(prepare(Haxe.ID), generate(), gulp.parallel(buil
const testFlash = function() {
const argv = yargs.argv;
- return build('flash')
+ return build('flash')()
.pipe(new FlashPlayer().run(argv.dev))
.pipe(debug());
};
diff --git a/build/prepare.js b/build/prepare.js
index 49cb7da..c9485ff 100755
--- a/build/prepare.js
+++ b/build/prepare.js
@@ -3,14 +3,13 @@ const Haxe = require('../tasks/haxe');
const FlashPlayer = require('../tasks/flashplayer');
const packages = [
- {name:'openfl', version:'6.0.1'},
- {name:'lime', version:'5.3.0'},
- 'promhx',
- 'protohx',
- //'haxework',
+ {name:'openfl', version:'6.5.3'},
+ {name:'lime', version:'5.9.1'},
+ {name:'promhx', version:'1.1.0'},
+ {name:'protohx', version:'0.4.6'},
+ {name:'yaml', version:'1.3.0'},
{name:'haxework', git:'git@bitbucket.org:shmyga/haxework.git'},
-
- 'orm',
+ {name:'orm', version:'2.1.0'},
];
diff --git a/project.xml b/project.xml
index 8f89b5c..f2e7708 100755
--- a/project.xml
+++ b/project.xml
@@ -9,6 +9,7 @@
+
diff --git a/src/client/haxe/ru/m/tankz/render/Render.hx b/src/client/haxe/ru/m/tankz/render/Render.hx
index e2e38da..a1e0dd5 100755
--- a/src/client/haxe/ru/m/tankz/render/Render.hx
+++ b/src/client/haxe/ru/m/tankz/render/Render.hx
@@ -19,13 +19,13 @@ interface IState {
}
class BrickState implements IState {
- private var type:BrickType;
+ private var type:Int;
public function new() {}
public function update(object:Brick):Bool {
- if (type != object.type) {
- type = object.type;
+ if (type != object.config.type) {
+ type = object.config.type;
return true;
}
return false;
@@ -59,14 +59,6 @@ class EntityState implements IState {
class Render extends SpriteView implements IRender {
- private static var GROUND_BRICKS:Array = [
- BrickType.BRICK, BrickType.ARMOR, BrickType.WATER, BrickType.ACE
- ];
-
- private static var UP_BRICKS:Array = [
- BrickType.BUSH
- ];
-
private var backgroundLayer:Sprite;
private var groundLayer:Sprite;
private var entryLayer:Sprite;
@@ -139,14 +131,14 @@ class Render extends SpriteView implements IRender {
upLayer.graphics.clear();
for (brick in game.map.bricks) {
var g:Graphics = null;
- if (GROUND_BRICKS.indexOf(brick.type) > -1) {
+ if (brick.config.layer < 3) {
g = groundLayer.graphics;
- } else if (UP_BRICKS.indexOf(brick.type) > -1) {
+ } else if (brick.config.layer >= 3) {
g = upLayer.graphics;
}
if (g != null) {
g.beginFill(0x00ff00);
- g.beginBitmapFill(Assets.getBitmapData('resources/images/map/map_${brick.type}.png'));
+ g.beginBitmapFill(Assets.getBitmapData('resources/images/map/map_${brick.config.type}.png'));
g.drawRect(
brick.cellX * game.map.cellWidth,
brick.cellY * game.map.cellHeight,
@@ -172,7 +164,7 @@ class Render extends SpriteView implements IRender {
image = 'resources/images/tank/player/tank_p${tank.config.level}_${tank.index}-0.png';
} else if (Std.is(ent, Bullet)) {
var bullet:Bullet = cast ent;
- image = 'resources/images/bullet/bullet_${bullet.config.type}.png';
+ image = 'resources/images/bullet/bullet_${bullet.config.piercing-1}.png';
} else {
image = 'ERROR'; // ToDo:
}
diff --git a/src/client/resources/config/config.yaml b/src/client/resources/config/config.yaml
new file mode 100644
index 0000000..9359d2a
--- /dev/null
+++ b/src/client/resources/config/config.yaml
@@ -0,0 +1,93 @@
+map:
+ cellWidth: 22
+ cellHeight: 22
+ gridWidth: 26
+ gridHeight: 26
+ bricks: null
+ points:
+ - type: player
+ index: 0
+ x: 8
+ y: 24
+ direction: top
+ - type: player
+ index: 1
+ x: 16
+ y: 24
+ direction: top
+
+bricks:
+ -1: &brick-boder
+ type: -1
+ layer: 2
+ armor: 3
+ 0: &brick-none
+ type: 0
+ layer: 0
+ armor: 0
+ 1: &brick-ace
+ type: 1
+ layer: 0
+ armor: 0
+ 2: &brick-bush
+ type: 2
+ layer: 3
+ armor: 0
+ 3: &brick-water
+ type: 3
+ layer: 1
+ armor: 0
+ 4: &brick-armor
+ type: 4
+ layer: 2
+ armor: 2
+ 5: &brick-brick
+ type: 5
+ layer: 2
+ armor: 1
+
+bullet: &bullet
+ width: 12
+ height: 12
+ speed: 0
+ piercing: 1
+
+tanks:
+ player:
+ 0:
+ level: 0
+ width: 36
+ height: 36
+ speed: 2.5
+ bullet:
+ <<: *bullet
+ speed: 8.0
+ bullets: 1
+ 1:
+ level: 1
+ width: 40
+ height: 36
+ speed: 3.0
+ bullet:
+ <<: *bullet
+ speed: 8.5
+ bullets: 1
+ 2:
+ level: 2
+ width: 40
+ height: 36
+ speed: 3.0
+ bullet:
+ <<: *bullet
+ speed: 9.0
+ bullets: 2
+ 3:
+ level: 3
+ width: 42
+ height: 38
+ speed: 2.9
+ bullet:
+ <<: *bullet
+ speed: 9.0
+ piercing: 2
+ bullets: 2
diff --git a/src/client/resources/conf/tank-z.ini b/src/client/resources/config/tank-z.ini
similarity index 100%
rename from src/client/resources/conf/tank-z.ini
rename to src/client/resources/config/tank-z.ini
diff --git a/src/common/haxe/ru/m/geom/Direction.hx b/src/common/haxe/ru/m/geom/Direction.hx
index 4c9b0ae..21d2248 100644
--- a/src/common/haxe/ru/m/geom/Direction.hx
+++ b/src/common/haxe/ru/m/geom/Direction.hx
@@ -26,4 +26,14 @@ class Direction {
public static function from(x:Int, y:Int):Direction {
return directions.get(x + y * 10);
}
+
+ @:from static public function fromString(s:String):Direction {
+ return switch(s) {
+ case 'left': LEFT;
+ case 'top': TOP;
+ case 'right': RIGHT;
+ case 'bottom': BOTTOM;
+ case _: null;
+ }
+ }
}
diff --git a/src/common/haxe/ru/m/tankz/config/Config.hx b/src/common/haxe/ru/m/tankz/config/Config.hx
index 8429dc1..987ea39 100644
--- a/src/common/haxe/ru/m/tankz/config/Config.hx
+++ b/src/common/haxe/ru/m/tankz/config/Config.hx
@@ -1,11 +1,24 @@
package ru.m.tankz.config;
-import ru.m.tankz.core.Bullet.BulletType;
-import ru.m.tankz.core.Bullet;
+import Reflect;
+import yaml.Parser;
+import yaml.Yaml;
import openfl.utils.Assets;
-import ru.m.tankz.map.Brick;
import ru.m.tankz.proto.core.GameType;
-import ru.m.geom.Direction;
+
+@:enum abstract SpawnPointType(String) from String to String {
+ var PLAYER = 'player';
+ var BOT = 'bot';
+ var EAGLE = 'eagle';
+}
+
+typedef SpawnPoint = {
+ var type:SpawnPointType;
+ var index:Int;
+ var x:Int;
+ var y:Int;
+ var direction:String;
+}
typedef MapConfig = {
var cellWidth:Float;
@@ -13,14 +26,21 @@ typedef MapConfig = {
var gridWidth:Int;
var gridHeight:Int;
- var bricks:Array;
+ var bricks:Array;
+ var points:Array;
+}
+
+typedef BrickConfig = {
+ var type:Int;
+ var layer:Int;
+ var armor:Int;
}
typedef BulletConfig = {
var width:Float;
var height:Float;
var speed:Float;
- var type:BulletType;
+ var piercing:Int;
}
typedef TankConfig = {
@@ -32,130 +52,78 @@ typedef TankConfig = {
var bullets:Int;
}
-enum SpawnPointType {
- PLAYER;
- BOT;
- EAGLE;
-}
-
-typedef SpawnPoint = {
- var type:SpawnPointType;
- var index:Int;
- var x:Int;
- var y:Int;
- var direction:Direction;
-}
-
class Config {
- public var map(default,null):MapConfig;
- public var points(default,null):Array;
+ public var source(default, null):ConfigSource;
- public function new(map:MapConfig, points:Array) {
- this.map = map;
- this.points = points;
+ public function new(source: ConfigSource) {
+ this.source = source;
}
public function getSpawnPoint(type:SpawnPointType, index:Int):SpawnPoint {
- for (point in points) {
+ for (point in this.source.map.points) {
if (point.type == type && point.index == index) {
return point;
}
}
return null;
}
+
+ public function getBrick(type:Int):BrickConfig {
+ return source.bricks.get(type);
+ }
+
+ public function getPlayerTank(level:Int):TankConfig {
+ return source.tanks.player.get(level);
+ }
+}
+
+
+typedef ConfigSource = {
+ map: MapConfig,
+ bricks: Map,
+ tanks: {
+ player: Map
+ }
}
class ConfigBundle {
- public static var CLASSIC:Config = new Config(
- {
- cellWidth: 22,
- cellHeight: 22,
- gridWidth: 26,
- gridHeight: 26,
- bricks: null
- },
- [
- {
- type: SpawnPointType.PLAYER,
- index: 0,
- x: 8,
- y: 24,
- direction: Direction.TOP
- },
- {
- type: SpawnPointType.PLAYER,
- index: 1,
- x: 16,
- y: 24,
- direction: Direction.TOP
- }
- ]
- );
-
- private static function bulletConfig(speed:Float, type:BulletType):BulletConfig {
- return {
- width: 12,
- height: 12,
- speed: speed,
- type: type
+ private static function buildMap(object:Dynamic):Map {
+ var result:Map = new Map();
+ for (key in Reflect.fields(object)) {
+ result.set(Std.parseInt(key), Reflect.field(object, key));
}
+ return result;
}
- public static var PLAYER_TANKS:Array = [
- {
- level: 0,
- width: 36,
- height: 36,
- speed: 3,
- bullet: bulletConfig(5, BulletType.NORMAL),
- bullets: 1
- },
- {
- level: 1,
- width: 40,
- height: 36,
- speed: 3.5,
- bullet: bulletConfig(5.5, BulletType.NORMAL),
- bullets: 1
- },
- {
- level: 2,
- width: 40,
- height: 36,
- speed: 3.5,
- bullet: bulletConfig(5.5, BulletType.NORMAL),
- bullets: 2
- },
- {
- level: 3,
- width: 42,
- height: 38,
- speed: 3.5,
- bullet: bulletConfig(6, BulletType.PIERCING),
- bullets: 2
+ private static function convert(raw:Dynamic):ConfigSource {
+ var map: MapConfig = Reflect.getProperty(raw, 'map');
+ var bricks: Map = cast buildMap(Reflect.getProperty(raw, 'bricks'));
+ var players: Map = cast buildMap(Reflect.getProperty(Reflect.getProperty(raw, 'tanks'), 'player'));
+ return {
+ map: map,
+ bricks: bricks,
+ tanks: {
+ player: players
+ }
}
- ];
-
-
- public static function getPlayerTank(level:Int):TankConfig {
- return PLAYER_TANKS[level];
}
public static function get(type:Int, level:Int):Config {
switch (type) {
case GameType.CLASSIC:
+ var source:ConfigSource = convert(Yaml.parse(Assets.getText('resources/config/config.yaml'), Parser.options().useObjects()));
var bricksData:String = Assets.getText('resources/levels/level00${level}.txt');
- var bricks:Array = [];
+ var bricks:Array = [];
for (line in ~/\s+/g.split(bricksData)) {
for (c in line.split('')) {
- bricks.push(Std.parseInt(c));
+ bricks.push(source.bricks.get(Std.parseInt(c)));
}
}
- CLASSIC.map.bricks = bricks; // ToDo:
- return CLASSIC;
+ source.map.bricks = bricks;
+ return new Config(source);
case _:
return null;
}
diff --git a/src/common/haxe/ru/m/tankz/core/Bullet.hx b/src/common/haxe/ru/m/tankz/core/Bullet.hx
index b79cb36..c23f1ec 100644
--- a/src/common/haxe/ru/m/tankz/core/Bullet.hx
+++ b/src/common/haxe/ru/m/tankz/core/Bullet.hx
@@ -5,12 +5,6 @@ import ru.m.geom.Rectangle;
import ru.m.geom.Direction;
-@:enum abstract BulletType(Int) from Int to Int {
- var NORMAL = 0;
- var PIERCING = 1;
-}
-
-
class Bullet extends MobileEntity {
public var tankId(default, null):Int;
public var config(default, null):BulletConfig;
diff --git a/src/common/haxe/ru/m/tankz/engine/Engine.hx b/src/common/haxe/ru/m/tankz/engine/Engine.hx
index 59ea079..3731011 100755
--- a/src/common/haxe/ru/m/tankz/engine/Engine.hx
+++ b/src/common/haxe/ru/m/tankz/engine/Engine.hx
@@ -1,5 +1,6 @@
package ru.m.tankz.engine;
+import ru.m.geom.Direction;
import ru.m.tankz.config.Config.TankConfig;
import ru.m.tankz.core.IEntity;
import ru.m.geom.Point;
@@ -9,7 +10,6 @@ import ru.m.tankz.proto.game.GameObjectType;
import ru.m.tankz.proto.game.GameChangeType;
import ru.m.tankz.proto.game.GameChange;
import ru.m.tankz.proto.core.Player;
-import ru.m.geom.Direction;
import ru.m.tankz.core.IMobileEntity;
import ru.m.tankz.config.Config;
import ru.m.tankz.core.Tank;
@@ -19,14 +19,6 @@ import ru.m.tankz.map.ILevelMap;
class Engine implements IEngine {
- private static var STOP_BRICKS:Array = [
- BrickType.BORDER, BrickType.BRICK, BrickType.ARMOR, BrickType.WATER
- ];
-
- private static var BULLET_BRICKS:Array = [
- BrickType.BORDER, BrickType.BRICK, BrickType.ARMOR
- ];
-
public var config(default, default):Config;
public var map(default, null):ILevelMap;
@@ -45,13 +37,13 @@ class Engine implements IEngine {
private function buildTank(index:Int, config:TankConfig, point:SpawnPoint):Tank {
var tank = new Tank(index, config);
tank.rect.center = new Point((point.x + 1) * map.cellWidth, (point.y + 1) * map.cellHeight);
- tank.direction = point.direction;
+ tank.direction = Direction.fromString(point.direction);
return tank;
}
public function init(config:Config):Void {
this.config = config;
- map = new LevelMap(config.map);
+ map = new LevelMap(config.source.map);
playerTanks = new Map();
entities = new Map();
removedEntities = new Array();
@@ -63,7 +55,7 @@ class Engine implements IEngine {
for (index in 0...players.length) {
var player:Player = players[index];
var point:SpawnPoint = config.getSpawnPoint(SpawnPointType.PLAYER, index);
- var tank = buildTank(index, ConfigBundle.getPlayerTank(0), point);
+ var tank = buildTank(index, config.getPlayerTank(0), point);
playerTanks.set(player.id, tank);
entities.set(tank.id, tank);
changes.push(new GameChange()
@@ -91,7 +83,7 @@ class Engine implements IEngine {
.setDirectionY(direction.y)
);*/
case TankAction.LEVEL_UP(level):
- tank.config = ConfigBundle.getPlayerTank(Std.int(Math.min(tank.config.level + level, 3)));
+ tank.config = config.getPlayerTank(Std.int(Math.min(tank.config.level + level, 3)));
case TankAction.STOP:
tank.stop();
/*Provider.get(IConnection).send(
@@ -163,10 +155,10 @@ class Engine implements IEngine {
if (objectType == GameObjectType.TANK) {
if (entity.direction.x != 0) {
- entity.rect.y = Math.round((entity.rect.y + entity.rect.height / 2) / config.map.cellHeight) * config.map.cellHeight - entity.rect.height / 2;
+ entity.rect.y = Math.round((entity.rect.y + entity.rect.height / 2) / map.cellHeight) * map.cellHeight - entity.rect.height / 2;
}
if (entity.direction.y != 0) {
- entity.rect.x = Math.round((entity.rect.x + entity.rect.width / 2) / config.map.cellWidth) * config.map.cellWidth - entity.rect.width / 2;
+ entity.rect.x = Math.round((entity.rect.x + entity.rect.width / 2) / map.cellWidth) * map.cellWidth - entity.rect.width / 2;
}
}
@@ -177,7 +169,7 @@ class Engine implements IEngine {
if (objectType == GameObjectType.TANK) {
for (brick in bricks) {
- if (STOP_BRICKS.indexOf(brick.type) > -1) {
+ if (0 < brick.config.layer && brick.config.layer < 3) {
if (entity.direction.x != 0) {
entity.rect.x = brick.cellX * map.cellWidth + map.cellWidth / 2 - entity.direction.x * map.cellWidth / 2 - entity.direction.x * entity.rect.width / 2 - entity.rect.width / 2;
}
@@ -200,7 +192,7 @@ class Engine implements IEngine {
if (objectType == GameObjectType.BULLET) {
var bullet:Bullet = cast ent;
for (brick in bricks) {
- if (BULLET_BRICKS.indexOf(brick.type) > -1) {
+ if (1 < brick.config.layer && brick.config.layer < 3) {
entities.remove(entity.id);
var tank:Tank = cast entities.get(bullet.tankId);
tank.onDestroyBullet();
@@ -214,11 +206,8 @@ class Engine implements IEngine {
}
}
for (brick in bricks) {
- if (brick.type == BrickType.BRICK) {
- brick.type = BrickType.NONE;
- }
- if (bullet.config.type == BulletType.PIERCING && brick.type == BrickType.ARMOR) {
- brick.type = BrickType.NONE;
+ if (brick.config.armor > 0 && brick.config.armor <= bullet.config.piercing) {
+ brick.config = config.getBrick(0);
}
}
}
diff --git a/src/common/haxe/ru/m/tankz/map/Brick.hx b/src/common/haxe/ru/m/tankz/map/Brick.hx
index 19783b6..71867c1 100644
--- a/src/common/haxe/ru/m/tankz/map/Brick.hx
+++ b/src/common/haxe/ru/m/tankz/map/Brick.hx
@@ -1,29 +1,25 @@
package ru.m.tankz.map;
+import ru.m.tankz.config.Config.BrickConfig;
import ru.m.tankz.core.IKey;
-@:enum abstract BrickType(Int) from Int to Int {
- var BORDER = -1;
- var NONE = 0;
- var ACE = 1;
- var BUSH = 2;
- var WATER = 3;
- var ARMOR = 4;
- var BRICK = 5;
-}
-
-
class Brick implements IKey {
+ public static var BORDER:BrickConfig = {
+ type: -1,
+ layer: 2,
+ armor: 3,
+ }
+
public var cellX(default, null):Int;
public var cellY(default, null):Int;
- public var type(default, default):BrickType;
public var key(get, null):String;
+ public var config(default, default):BrickConfig;
- public function new(type:BrickType, cellX:Int, cellY:Int) {
+ public function new(config:BrickConfig, cellX:Int, cellY:Int) {
this.cellX = cellX;
this.cellY = cellY;
- this.type = type;
+ this.config = config;
}
public function get_key():String {
@@ -31,6 +27,6 @@ class Brick implements IKey {
}
public function toString() {
- return 'Brick{$type,$cellX:$cellY}';
+ return 'Brick{${config.type},$cellX:$cellY}';
}
}
diff --git a/src/common/haxe/ru/m/tankz/map/LevelMap.hx b/src/common/haxe/ru/m/tankz/map/LevelMap.hx
index 021425c..9091129 100755
--- a/src/common/haxe/ru/m/tankz/map/LevelMap.hx
+++ b/src/common/haxe/ru/m/tankz/map/LevelMap.hx
@@ -1,7 +1,6 @@
package ru.m.tankz.map;
-import ru.m.tankz.map.Brick.BrickType;
-import ru.m.tankz.config.Config.MapConfig;
+import ru.m.tankz.config.Config;
class LevelMap implements ILevelMap {
@@ -25,7 +24,7 @@ class LevelMap implements ILevelMap {
private function getBorderBrick(cellX:Int, cellY:Int):Brick {
var index:Int = cellX + cellY * gridWidth;
if (borders[index] == null) {
- borders[index] = new Brick(BrickType.BORDER, cellX, cellY);
+ borders[index] = new Brick(Brick.BORDER, cellX, cellY);
}
return borders[index];
}