[common] Render implement EngineListener
This commit is contained in:
@@ -51,6 +51,7 @@ typedef TeamConfig = {
|
||||
|
||||
|
||||
class Config {
|
||||
public var type(default, null):String;
|
||||
public var map(default, null):MapConfig;
|
||||
public var bricks(default, null):Array<BrickConfig>;
|
||||
public var tanks(default, null):Array<TankConfig>;
|
||||
@@ -60,7 +61,8 @@ class Config {
|
||||
private var tankMap:Map<String, Map<String, TankConfig>>;
|
||||
private var teamMap:Map<String, TeamConfig>;
|
||||
|
||||
public function new(map:MapConfig, bricks:Array<BrickConfig>, teams:Array<TeamConfig>, tanks:Array<TankConfig>) {
|
||||
public function new(type:String, map:MapConfig, bricks:Array<BrickConfig>, teams:Array<TeamConfig>, tanks:Array<TankConfig>) {
|
||||
this.type = type;
|
||||
this.map = map;
|
||||
this.bricks = bricks;
|
||||
this.teams = teams;
|
||||
|
||||
@@ -23,7 +23,7 @@ class ConfigBundle {
|
||||
public static function get(type:String, level:Int):Config {
|
||||
switch (type) {
|
||||
case ClassicGame.TYPE:
|
||||
var source:ConfigSource = convert(Yaml.parse(Assets.getText('resources/config/config.yaml'), Parser.options().useObjects()));
|
||||
var source:ConfigSource = convert(Yaml.parse(Assets.getText('resources/config/${type}.yaml'), Parser.options().useObjects()));
|
||||
var bricksData:String = Assets.getText('resources/levels/level00${level}.txt');
|
||||
var bricks:Array<BrickConfig> = [];
|
||||
for (line in ~/\s+/g.split(bricksData)) {
|
||||
@@ -42,7 +42,7 @@ class ConfigBundle {
|
||||
tanks.push(item);
|
||||
}
|
||||
}
|
||||
return new Config(source.map, source.bricks, source.teams, tanks);
|
||||
return new Config(type, source.map, source.bricks, source.teams, tanks);
|
||||
case _:
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -104,6 +104,12 @@ class Engine {
|
||||
public function destroy(entity:Entity):Void {
|
||||
if (entities.exists(entity.id)) {
|
||||
var type = EntityTypeResolver.of(entity);
|
||||
switch (type) {
|
||||
case EntityType.BULLET(bullet):
|
||||
var tank:Tank = cast entities.get(bullet.tankId);
|
||||
if (tank != null) tank.onDestroyBullet();
|
||||
case _:
|
||||
}
|
||||
for (l in listeners) l.onDestroy(type);
|
||||
entities.remove(entity.id);
|
||||
}
|
||||
@@ -122,7 +128,7 @@ class Engine {
|
||||
case TankAction.SHOT:
|
||||
var bullet = tank.shot();
|
||||
if (bullet != null) {
|
||||
entities.set(bullet.id, bullet);
|
||||
spawn(bullet);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -192,4 +198,8 @@ class Engine {
|
||||
}
|
||||
}
|
||||
|
||||
public function dispose():Void {
|
||||
listeners = [];
|
||||
entities = new Map();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ import ru.m.tankz.config.Config;
|
||||
|
||||
class ClassicGame extends Game {
|
||||
|
||||
public static var TYPE(default, never):GameType = Type.getClassName(ClassicGame);
|
||||
public static var TYPE(default, never):GameType = 'classic';
|
||||
|
||||
public function new(config:Config) {
|
||||
super(TYPE, config);
|
||||
|
||||
@@ -138,8 +138,8 @@ class Game implements EngineListener implements ControlListener {
|
||||
private function spawn(task:SpawnTask):Void {
|
||||
var tank = buildTank(task.playerId, config.getTank(task.playerId.team, '0'), task.point);
|
||||
var player:Player = teams.get(task.playerId.team).players[task.playerId.index];
|
||||
player.tankId = tank.id;
|
||||
engine.spawn(tank);
|
||||
player.tankId = tank.id;
|
||||
}
|
||||
|
||||
public function setControl(playerId:PlayerId, control:Control):Void {
|
||||
@@ -185,6 +185,6 @@ class Game implements EngineListener implements ControlListener {
|
||||
|
||||
|
||||
public function dispose():Void {
|
||||
|
||||
engine.dispose();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user