[config] config.yaml
This commit is contained in:
@@ -64,7 +64,7 @@ exports['client'] = gulp.series(prepare(Haxe.ID), generate(), gulp.parallel(buil
|
|||||||
|
|
||||||
const testFlash = function() {
|
const testFlash = function() {
|
||||||
const argv = yargs.argv;
|
const argv = yargs.argv;
|
||||||
return build('flash')
|
return build('flash')()
|
||||||
.pipe(new FlashPlayer().run(argv.dev))
|
.pipe(new FlashPlayer().run(argv.dev))
|
||||||
.pipe(debug());
|
.pipe(debug());
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -3,14 +3,13 @@ const Haxe = require('../tasks/haxe');
|
|||||||
const FlashPlayer = require('../tasks/flashplayer');
|
const FlashPlayer = require('../tasks/flashplayer');
|
||||||
|
|
||||||
const packages = [
|
const packages = [
|
||||||
{name:'openfl', version:'6.0.1'},
|
{name:'openfl', version:'6.5.3'},
|
||||||
{name:'lime', version:'5.3.0'},
|
{name:'lime', version:'5.9.1'},
|
||||||
'promhx',
|
{name:'promhx', version:'1.1.0'},
|
||||||
'protohx',
|
{name:'protohx', version:'0.4.6'},
|
||||||
//'haxework',
|
{name:'yaml', version:'1.3.0'},
|
||||||
{name:'haxework', git:'git@bitbucket.org:shmyga/haxework.git'},
|
{name:'haxework', git:'git@bitbucket.org:shmyga/haxework.git'},
|
||||||
|
{name:'orm', version:'2.1.0'},
|
||||||
'orm',
|
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -9,6 +9,7 @@
|
|||||||
<haxelib name="openfl"/>
|
<haxelib name="openfl"/>
|
||||||
<haxelib name="protohx"/>
|
<haxelib name="protohx"/>
|
||||||
<haxelib name="haxework" version="git"/>
|
<haxelib name="haxework" version="git"/>
|
||||||
|
<haxelib name="yaml"/>
|
||||||
<!--<window width="760" height="600"/>-->
|
<!--<window width="760" height="600"/>-->
|
||||||
<haxeflag name="-D" value="swf-gpu"/>
|
<haxeflag name="-D" value="swf-gpu"/>
|
||||||
<haxeflag name="-D" value="native-trace"/>
|
<haxeflag name="-D" value="native-trace"/>
|
||||||
|
|||||||
@@ -19,13 +19,13 @@ interface IState<T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class BrickState implements IState<Brick> {
|
class BrickState implements IState<Brick> {
|
||||||
private var type:BrickType;
|
private var type:Int;
|
||||||
|
|
||||||
public function new() {}
|
public function new() {}
|
||||||
|
|
||||||
public function update(object:Brick):Bool {
|
public function update(object:Brick):Bool {
|
||||||
if (type != object.type) {
|
if (type != object.config.type) {
|
||||||
type = object.type;
|
type = object.config.type;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
@@ -59,14 +59,6 @@ class EntityState implements IState<Entity> {
|
|||||||
|
|
||||||
class Render extends SpriteView implements IRender {
|
class Render extends SpriteView implements IRender {
|
||||||
|
|
||||||
private static var GROUND_BRICKS:Array<BrickType> = [
|
|
||||||
BrickType.BRICK, BrickType.ARMOR, BrickType.WATER, BrickType.ACE
|
|
||||||
];
|
|
||||||
|
|
||||||
private static var UP_BRICKS:Array<BrickType> = [
|
|
||||||
BrickType.BUSH
|
|
||||||
];
|
|
||||||
|
|
||||||
private var backgroundLayer:Sprite;
|
private var backgroundLayer:Sprite;
|
||||||
private var groundLayer:Sprite;
|
private var groundLayer:Sprite;
|
||||||
private var entryLayer:Sprite;
|
private var entryLayer:Sprite;
|
||||||
@@ -139,14 +131,14 @@ class Render extends SpriteView implements IRender {
|
|||||||
upLayer.graphics.clear();
|
upLayer.graphics.clear();
|
||||||
for (brick in game.map.bricks) {
|
for (brick in game.map.bricks) {
|
||||||
var g:Graphics = null;
|
var g:Graphics = null;
|
||||||
if (GROUND_BRICKS.indexOf(brick.type) > -1) {
|
if (brick.config.layer < 3) {
|
||||||
g = groundLayer.graphics;
|
g = groundLayer.graphics;
|
||||||
} else if (UP_BRICKS.indexOf(brick.type) > -1) {
|
} else if (brick.config.layer >= 3) {
|
||||||
g = upLayer.graphics;
|
g = upLayer.graphics;
|
||||||
}
|
}
|
||||||
if (g != null) {
|
if (g != null) {
|
||||||
g.beginFill(0x00ff00);
|
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(
|
g.drawRect(
|
||||||
brick.cellX * game.map.cellWidth,
|
brick.cellX * game.map.cellWidth,
|
||||||
brick.cellY * game.map.cellHeight,
|
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';
|
image = 'resources/images/tank/player/tank_p${tank.config.level}_${tank.index}-0.png';
|
||||||
} else if (Std.is(ent, Bullet)) {
|
} else if (Std.is(ent, Bullet)) {
|
||||||
var bullet:Bullet = cast ent;
|
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 {
|
} else {
|
||||||
image = 'ERROR'; // ToDo:
|
image = 'ERROR'; // ToDo:
|
||||||
}
|
}
|
||||||
|
|||||||
93
src/client/resources/config/config.yaml
Normal file
93
src/client/resources/config/config.yaml
Normal file
@@ -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
|
||||||
@@ -26,4 +26,14 @@ class Direction {
|
|||||||
public static function from(x:Int, y:Int):Direction {
|
public static function from(x:Int, y:Int):Direction {
|
||||||
return directions.get(x + y * 10);
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,11 +1,24 @@
|
|||||||
package ru.m.tankz.config;
|
package ru.m.tankz.config;
|
||||||
|
|
||||||
import ru.m.tankz.core.Bullet.BulletType;
|
import Reflect;
|
||||||
import ru.m.tankz.core.Bullet;
|
import yaml.Parser;
|
||||||
|
import yaml.Yaml;
|
||||||
import openfl.utils.Assets;
|
import openfl.utils.Assets;
|
||||||
import ru.m.tankz.map.Brick;
|
|
||||||
import ru.m.tankz.proto.core.GameType;
|
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 = {
|
typedef MapConfig = {
|
||||||
var cellWidth:Float;
|
var cellWidth:Float;
|
||||||
@@ -13,14 +26,21 @@ typedef MapConfig = {
|
|||||||
var gridWidth:Int;
|
var gridWidth:Int;
|
||||||
var gridHeight:Int;
|
var gridHeight:Int;
|
||||||
|
|
||||||
var bricks:Array<BrickType>;
|
var bricks:Array<BrickConfig>;
|
||||||
|
var points:Array<SpawnPoint>;
|
||||||
|
}
|
||||||
|
|
||||||
|
typedef BrickConfig = {
|
||||||
|
var type:Int;
|
||||||
|
var layer:Int;
|
||||||
|
var armor:Int;
|
||||||
}
|
}
|
||||||
|
|
||||||
typedef BulletConfig = {
|
typedef BulletConfig = {
|
||||||
var width:Float;
|
var width:Float;
|
||||||
var height:Float;
|
var height:Float;
|
||||||
var speed:Float;
|
var speed:Float;
|
||||||
var type:BulletType;
|
var piercing:Int;
|
||||||
}
|
}
|
||||||
|
|
||||||
typedef TankConfig = {
|
typedef TankConfig = {
|
||||||
@@ -32,130 +52,78 @@ typedef TankConfig = {
|
|||||||
var bullets:Int;
|
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 {
|
class Config {
|
||||||
public var map(default,null):MapConfig;
|
public var source(default, null):ConfigSource;
|
||||||
public var points(default,null):Array<SpawnPoint>;
|
|
||||||
|
|
||||||
public function new(map:MapConfig, points:Array<SpawnPoint>) {
|
public function new(source: ConfigSource) {
|
||||||
this.map = map;
|
this.source = source;
|
||||||
this.points = points;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getSpawnPoint(type:SpawnPointType, index:Int):SpawnPoint {
|
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) {
|
if (point.type == type && point.index == index) {
|
||||||
return point;
|
return point;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null;
|
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<Int, BrickConfig>,
|
||||||
|
tanks: {
|
||||||
|
player: Map<Int, TankConfig>
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
class ConfigBundle {
|
class ConfigBundle {
|
||||||
|
|
||||||
public static var CLASSIC:Config = new Config(
|
private static function buildMap(object:Dynamic):Map<Int, Dynamic> {
|
||||||
{
|
var result:Map<Int, Dynamic> = new Map();
|
||||||
cellWidth: 22,
|
for (key in Reflect.fields(object)) {
|
||||||
cellHeight: 22,
|
result.set(Std.parseInt(key), Reflect.field(object, key));
|
||||||
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
|
|
||||||
}
|
}
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static var PLAYER_TANKS:Array<TankConfig> = [
|
private static function convert(raw:Dynamic):ConfigSource {
|
||||||
{
|
var map: MapConfig = Reflect.getProperty(raw, 'map');
|
||||||
level: 0,
|
var bricks: Map<Int, BrickConfig> = cast buildMap(Reflect.getProperty(raw, 'bricks'));
|
||||||
width: 36,
|
var players: Map<Int, TankConfig> = cast buildMap(Reflect.getProperty(Reflect.getProperty(raw, 'tanks'), 'player'));
|
||||||
height: 36,
|
return {
|
||||||
speed: 3,
|
map: map,
|
||||||
bullet: bulletConfig(5, BulletType.NORMAL),
|
bricks: bricks,
|
||||||
bullets: 1
|
tanks: {
|
||||||
},
|
player: players
|
||||||
{
|
}
|
||||||
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
|
|
||||||
}
|
}
|
||||||
];
|
|
||||||
|
|
||||||
|
|
||||||
public static function getPlayerTank(level:Int):TankConfig {
|
|
||||||
return PLAYER_TANKS[level];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function get(type:Int, level:Int):Config {
|
public static function get(type:Int, level:Int):Config {
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case GameType.CLASSIC:
|
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 bricksData:String = Assets.getText('resources/levels/level00${level}.txt');
|
||||||
var bricks:Array<BrickType> = [];
|
var bricks:Array<BrickConfig> = [];
|
||||||
for (line in ~/\s+/g.split(bricksData)) {
|
for (line in ~/\s+/g.split(bricksData)) {
|
||||||
for (c in line.split('')) {
|
for (c in line.split('')) {
|
||||||
bricks.push(Std.parseInt(c));
|
bricks.push(source.bricks.get(Std.parseInt(c)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
CLASSIC.map.bricks = bricks; // ToDo:
|
source.map.bricks = bricks;
|
||||||
return CLASSIC;
|
return new Config(source);
|
||||||
case _:
|
case _:
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,12 +5,6 @@ import ru.m.geom.Rectangle;
|
|||||||
import ru.m.geom.Direction;
|
import ru.m.geom.Direction;
|
||||||
|
|
||||||
|
|
||||||
@:enum abstract BulletType(Int) from Int to Int {
|
|
||||||
var NORMAL = 0;
|
|
||||||
var PIERCING = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
class Bullet extends MobileEntity {
|
class Bullet extends MobileEntity {
|
||||||
public var tankId(default, null):Int;
|
public var tankId(default, null):Int;
|
||||||
public var config(default, null):BulletConfig;
|
public var config(default, null):BulletConfig;
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package ru.m.tankz.engine;
|
package ru.m.tankz.engine;
|
||||||
|
|
||||||
|
import ru.m.geom.Direction;
|
||||||
import ru.m.tankz.config.Config.TankConfig;
|
import ru.m.tankz.config.Config.TankConfig;
|
||||||
import ru.m.tankz.core.IEntity;
|
import ru.m.tankz.core.IEntity;
|
||||||
import ru.m.geom.Point;
|
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.GameChangeType;
|
||||||
import ru.m.tankz.proto.game.GameChange;
|
import ru.m.tankz.proto.game.GameChange;
|
||||||
import ru.m.tankz.proto.core.Player;
|
import ru.m.tankz.proto.core.Player;
|
||||||
import ru.m.geom.Direction;
|
|
||||||
import ru.m.tankz.core.IMobileEntity;
|
import ru.m.tankz.core.IMobileEntity;
|
||||||
import ru.m.tankz.config.Config;
|
import ru.m.tankz.config.Config;
|
||||||
import ru.m.tankz.core.Tank;
|
import ru.m.tankz.core.Tank;
|
||||||
@@ -19,14 +19,6 @@ import ru.m.tankz.map.ILevelMap;
|
|||||||
|
|
||||||
class Engine implements IEngine {
|
class Engine implements IEngine {
|
||||||
|
|
||||||
private static var STOP_BRICKS:Array<BrickType> = [
|
|
||||||
BrickType.BORDER, BrickType.BRICK, BrickType.ARMOR, BrickType.WATER
|
|
||||||
];
|
|
||||||
|
|
||||||
private static var BULLET_BRICKS:Array<BrickType> = [
|
|
||||||
BrickType.BORDER, BrickType.BRICK, BrickType.ARMOR
|
|
||||||
];
|
|
||||||
|
|
||||||
public var config(default, default):Config;
|
public var config(default, default):Config;
|
||||||
public var map(default, null):ILevelMap;
|
public var map(default, null):ILevelMap;
|
||||||
|
|
||||||
@@ -45,13 +37,13 @@ class Engine implements IEngine {
|
|||||||
private function buildTank(index:Int, config:TankConfig, point:SpawnPoint):Tank {
|
private function buildTank(index:Int, config:TankConfig, point:SpawnPoint):Tank {
|
||||||
var tank = new Tank(index, config);
|
var tank = new Tank(index, config);
|
||||||
tank.rect.center = new Point((point.x + 1) * map.cellWidth, (point.y + 1) * map.cellHeight);
|
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;
|
return tank;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function init(config:Config):Void {
|
public function init(config:Config):Void {
|
||||||
this.config = config;
|
this.config = config;
|
||||||
map = new LevelMap(config.map);
|
map = new LevelMap(config.source.map);
|
||||||
playerTanks = new Map<Int, Tank>();
|
playerTanks = new Map<Int, Tank>();
|
||||||
entities = new Map<Int, IEntity>();
|
entities = new Map<Int, IEntity>();
|
||||||
removedEntities = new Array<String>();
|
removedEntities = new Array<String>();
|
||||||
@@ -63,7 +55,7 @@ class Engine implements IEngine {
|
|||||||
for (index in 0...players.length) {
|
for (index in 0...players.length) {
|
||||||
var player:Player = players[index];
|
var player:Player = players[index];
|
||||||
var point:SpawnPoint = config.getSpawnPoint(SpawnPointType.PLAYER, 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);
|
playerTanks.set(player.id, tank);
|
||||||
entities.set(tank.id, tank);
|
entities.set(tank.id, tank);
|
||||||
changes.push(new GameChange()
|
changes.push(new GameChange()
|
||||||
@@ -91,7 +83,7 @@ class Engine implements IEngine {
|
|||||||
.setDirectionY(direction.y)
|
.setDirectionY(direction.y)
|
||||||
);*/
|
);*/
|
||||||
case TankAction.LEVEL_UP(level):
|
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:
|
case TankAction.STOP:
|
||||||
tank.stop();
|
tank.stop();
|
||||||
/*Provider.get(IConnection).send(
|
/*Provider.get(IConnection).send(
|
||||||
@@ -163,10 +155,10 @@ class Engine implements IEngine {
|
|||||||
|
|
||||||
if (objectType == GameObjectType.TANK) {
|
if (objectType == GameObjectType.TANK) {
|
||||||
if (entity.direction.x != 0) {
|
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) {
|
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) {
|
if (objectType == GameObjectType.TANK) {
|
||||||
for (brick in bricks) {
|
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) {
|
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;
|
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) {
|
if (objectType == GameObjectType.BULLET) {
|
||||||
var bullet:Bullet = cast ent;
|
var bullet:Bullet = cast ent;
|
||||||
for (brick in bricks) {
|
for (brick in bricks) {
|
||||||
if (BULLET_BRICKS.indexOf(brick.type) > -1) {
|
if (1 < brick.config.layer && brick.config.layer < 3) {
|
||||||
entities.remove(entity.id);
|
entities.remove(entity.id);
|
||||||
var tank:Tank = cast entities.get(bullet.tankId);
|
var tank:Tank = cast entities.get(bullet.tankId);
|
||||||
tank.onDestroyBullet();
|
tank.onDestroyBullet();
|
||||||
@@ -214,11 +206,8 @@ class Engine implements IEngine {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (brick in bricks) {
|
for (brick in bricks) {
|
||||||
if (brick.type == BrickType.BRICK) {
|
if (brick.config.armor > 0 && brick.config.armor <= bullet.config.piercing) {
|
||||||
brick.type = BrickType.NONE;
|
brick.config = config.getBrick(0);
|
||||||
}
|
|
||||||
if (bullet.config.type == BulletType.PIERCING && brick.type == BrickType.ARMOR) {
|
|
||||||
brick.type = BrickType.NONE;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,29 +1,25 @@
|
|||||||
package ru.m.tankz.map;
|
package ru.m.tankz.map;
|
||||||
|
|
||||||
|
import ru.m.tankz.config.Config.BrickConfig;
|
||||||
import ru.m.tankz.core.IKey;
|
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 {
|
class Brick implements IKey {
|
||||||
|
public static var BORDER:BrickConfig = {
|
||||||
|
type: -1,
|
||||||
|
layer: 2,
|
||||||
|
armor: 3,
|
||||||
|
}
|
||||||
|
|
||||||
public var cellX(default, null):Int;
|
public var cellX(default, null):Int;
|
||||||
public var cellY(default, null):Int;
|
public var cellY(default, null):Int;
|
||||||
public var type(default, default):BrickType;
|
|
||||||
public var key(get, null):String;
|
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.cellX = cellX;
|
||||||
this.cellY = cellY;
|
this.cellY = cellY;
|
||||||
this.type = type;
|
this.config = config;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function get_key():String {
|
public function get_key():String {
|
||||||
@@ -31,6 +27,6 @@ class Brick implements IKey {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function toString() {
|
public function toString() {
|
||||||
return 'Brick{$type,$cellX:$cellY}';
|
return 'Brick{${config.type},$cellX:$cellY}';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
package ru.m.tankz.map;
|
package ru.m.tankz.map;
|
||||||
|
|
||||||
import ru.m.tankz.map.Brick.BrickType;
|
import ru.m.tankz.config.Config;
|
||||||
import ru.m.tankz.config.Config.MapConfig;
|
|
||||||
|
|
||||||
class LevelMap implements ILevelMap {
|
class LevelMap implements ILevelMap {
|
||||||
|
|
||||||
@@ -25,7 +24,7 @@ class LevelMap implements ILevelMap {
|
|||||||
private function getBorderBrick(cellX:Int, cellY:Int):Brick {
|
private function getBorderBrick(cellX:Int, cellY:Int):Brick {
|
||||||
var index:Int = cellX + cellY * gridWidth;
|
var index:Int = cellX + cellY * gridWidth;
|
||||||
if (borders[index] == null) {
|
if (borders[index] == null) {
|
||||||
borders[index] = new Brick(BrickType.BORDER, cellX, cellY);
|
borders[index] = new Brick(Brick.BORDER, cellX, cellY);
|
||||||
}
|
}
|
||||||
return borders[index];
|
return borders[index];
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user