[common] added Dota game type

This commit is contained in:
2018-01-28 19:04:39 +03:00
parent 9ebed21c5f
commit 9eb21fae7d
12 changed files with 291 additions and 45 deletions

View File

@@ -22,20 +22,15 @@ class ConfigBundle {
}
public static function get(type:String):Config {
switch (type) {
case ClassicGame.TYPE:
var source:ConfigSource = convert(Yaml.parse(Assets.getText('resources/${type}/config.yaml'), Parser.options().useObjects()));
var tanks:Array<TankConfig> = [];
for (group in Reflect.fields(source.tanks)) {
var data:Array<TankConfig> = Reflect.field(source.tanks, group);
for (item in data) {
item.group = group;
tanks.push(item);
}
}
return new Config(type, source.levels, source.map, source.bricks, source.teams, tanks);
case _:
return null;
var source:ConfigSource = convert(Yaml.parse(Assets.getText('resources/${type}/config.yaml'), Parser.options().useObjects()));
var tanks:Array<TankConfig> = [];
for (group in Reflect.fields(source.tanks)) {
var data:Array<TankConfig> = Reflect.field(source.tanks, group);
for (item in data) {
item.group = group;
tanks.push(item);
}
}
return new Config(type, source.levels, source.map, source.bricks, source.teams, tanks);
}
}

View File

@@ -0,0 +1,56 @@
package ru.m.tankz.game;
import ru.m.tankz.game.Game;
import ru.m.tankz.game.GameState;
class DotaGame extends Game {
public static var TYPE(default, never):GameType = 'dota';
public static var RADIANT(default, never):TeamId = 'radiant';
public static var DIRE(default, never):TeamId = 'dire';
private static var TEAM_SIZE(default, never):Int = 5;
public function new() {
super(TYPE);
}
public static function buildState(level:Int, humans:Int):GameState {
var state = new GameState();
state.type = TYPE;
state.level = level;
state.players[RADIANT] = new Map();
state.players[DIRE] = new Map();
for (i in 0...TEAM_SIZE) {
state.players[RADIANT][i] = {
index:i,
tank:{
group: RADIANT,
type: '1'
},
control:{
type: 'bot',
index: i
},
life:-1,
};
}
for (i in 0...TEAM_SIZE) {
state.players[DIRE][i] = {
index:i,
tank:{
group: DIRE,
type: '1'
},
control:{
type: 'bot',
index: i
},
life:-1,
};
}
return state;
}
}

View File

@@ -74,10 +74,13 @@ class Game implements EngineListener {
var control = switch (playerState.control.type) {
case HumanControl.TYPE: new HumanControl(playerState.control.index);
case BotControl.TYPE: new BotControl(playerState.control.index);
case 'none': null;
case _: throw 'Unsupported control type: "${playerState.control.type}"';
}
player.control = control;
player.control.bind(engine);
if (control != null) {
player.control = control;
player.control.bind(engine);
}
}
}
spawners.set(team.id, new Spawner(team.config, spawn));

View File

@@ -41,7 +41,7 @@ class LevelMap {
bricksMap = new HashMap();
bricks = Lambda.array(Lambda.mapi(data, function(i:Int, brickConfig:BrickConfig):Brick {
var cellX = Std.int(i % gridWidth);
var cellY = Std.int(Math.floor(i / gridHeight));
var cellY = Std.int(Math.floor(i / gridWidth));
var cells:HashMap<Point, GridCell> = new HashMap();
var point:Point = new Point(cellX * 2, cellY * 2);
if (brickConfig.layer > 0 || brickConfig.armor > 0) {