diff --git a/src/client/haxe/ru/m/tankz/view/frames/GameFrame.hx b/src/client/haxe/ru/m/tankz/view/frames/GameFrame.hx index 217470d..5e624a8 100755 --- a/src/client/haxe/ru/m/tankz/view/frames/GameFrame.hx +++ b/src/client/haxe/ru/m/tankz/view/frames/GameFrame.hx @@ -9,7 +9,7 @@ import protohx.Message; import ru.m.tankz.proto.pack.GameUpdateResponse; import ru.m.core.connect.IConnection; import haxework.gui.ViewBuilder; -import ru.m.tankz.config.TankzConfig; +import ru.m.tankz.config.Config; import flash.events.Event; import haxework.provider.Provider; import haxework.gui.VGroupView; @@ -31,7 +31,7 @@ class GameFrame extends VGroupView implements ViewBuilder implements IPacketHand public function onShow():Void { var game:Game = Provider.get(Game); - engine.init(ConfigData.get(GameType.CLASSIC)); + engine.init(ConfigBundle.get(GameType.CLASSIC)); engine.initTanks(game.players); content.addEventListener(Event.ENTER_FRAME, updateGame); for (index in 0...game.players.length) { diff --git a/src/common/haxe/ru/m/tankz/config/TankzConfig.hx b/src/common/haxe/ru/m/tankz/config/Config.hx similarity index 70% rename from src/common/haxe/ru/m/tankz/config/TankzConfig.hx rename to src/common/haxe/ru/m/tankz/config/Config.hx index 69174c4..932ac56 100644 --- a/src/common/haxe/ru/m/tankz/config/TankzConfig.hx +++ b/src/common/haxe/ru/m/tankz/config/Config.hx @@ -24,20 +24,38 @@ typedef SpawnPoint = { var direction:Direction; } -typedef TankzConfig = { - var map:MapConfig; - var points:Array; + +class Config { + public var map(default,null):MapConfig; + public var points(default,null):Array; + + public function new(map:MapConfig, points:Array) { + this.map = map; + this.points = points; + } + + public function getSpawnPoint(type:SpawnPointType, index:Int):SpawnPoint { + for (point in points) { + if (point.type == type && point.index == index) { + return point; + } + } + return null; + } } -class ConfigData { - public static var CLASSIC:TankzConfig = { - map: { + +class ConfigBundle { + + + public static var CLASSIC:Config = new Config( + { cellWidth: 22, cellHeight: 22, gridWidth: 26, gridHeight: 26 }, - points: [ + [ { type: SpawnPointType.PLAYER, index: 0, @@ -53,9 +71,9 @@ class ConfigData { direction: Direction.TOP } ] - }; + ); - public static function get(type:Int):TankzConfig { + public static function get(type:Int):Config { switch (type) { case GameType.CLASSIC: return CLASSIC; @@ -63,13 +81,4 @@ class ConfigData { return null; } } - - public static function findSpawnPoint(config:TankzConfig, type:SpawnPointType, index:Int):SpawnPoint { - for (point in config.points) { - if (point.type == type && point.index == index) { - return point; - } - } - return null; - } } diff --git a/src/common/haxe/ru/m/tankz/engine/Engine.hx b/src/common/haxe/ru/m/tankz/engine/Engine.hx index 820e092..10b718e 100755 --- a/src/common/haxe/ru/m/tankz/engine/Engine.hx +++ b/src/common/haxe/ru/m/tankz/engine/Engine.hx @@ -8,15 +8,15 @@ import ru.m.tankz.proto.core.Player; import ru.m.tankz.core.Direction; import ru.m.tankz.core.IMobileEntity; //import flash.geom.Rectangle; -import ru.m.tankz.config.TankzConfig; +import ru.m.tankz.config.Config; import ru.m.tankz.core.Tank; -import ru.m.tankz.map.TankzMap; -import ru.m.tankz.map.ITankzMap; +import ru.m.tankz.map.LevelMap; +import ru.m.tankz.map.ILevelMap; class Engine implements IEngine { - public var config(default, default):TankzConfig; - public var map(default, null):ITankzMap; + public var config(default, default):Config; + public var map(default, null):ILevelMap; public var tanks(default, null):Map; public var mobileEntities(default, null):Map; @@ -34,9 +34,9 @@ class Engine implements IEngine { return new Tank(personId, id, cellX * map.cellWidth, cellY * map.cellHeight, direction); } - public function init(config:TankzConfig):Void { + public function init(config:Config):Void { this.config = config; - map = new TankzMap(config.map); + map = new LevelMap(config.map); tanks = new Map(); mobileEntities = new Map(); x_limit = map.gridWidth * map.cellWidth; @@ -47,7 +47,7 @@ class Engine implements IEngine { var changes = new Array(); for (index in 0...players.length) { var player:Player = players[index]; - var point:SpawnPoint = ConfigData.findSpawnPoint(config, SpawnPointType.PLAYER, index); + var point:SpawnPoint = config.getSpawnPoint(SpawnPointType.PLAYER, index); var tank = buildTank(player.id, 0, point.x, point.y, point.direction); this.tanks.set(tank.personId, tank); this.mobileEntities.set(tank.id, tank); @@ -70,7 +70,7 @@ class Engine implements IEngine { case TankAction.MOVE(direction): tank.move(direction); /*Provider.get(IConnection).send( - new GameActionRequest() + Map GameActionRequest() .setType(GameActionType.MOVE) .setDirectionX(direction.x) .setDirectionY(direction.y) @@ -78,7 +78,7 @@ class Engine implements IEngine { case TankAction.STOP: tank.stop(); /*Provider.get(IConnection).send( - new GameActionRequest() + Map GameActionRequest() .setType(GameActionType.STOP) );*/ case TankAction.SHOT: @@ -87,7 +87,7 @@ class Engine implements IEngine { mobileEntities.set(bullet.id, bullet); } /*Provider.get(IConnection).send( - new GameActionRequest() + Map GameActionRequest() .setType(GameActionType.SHOT) );*/ } @@ -103,7 +103,7 @@ class Engine implements IEngine { mobileEntities.set(tank.id, tank); tanks.set(tank.personId, tank); case GameObjectType.BULLET: - var bullet:Bullet = new Bullet(change.personId, change.objectId, change.x, change.y, 0, Direction.from(change.directionX, change.directionY)); + var bullet:Bullet = Map Bullet(change.personId, change.objectId, change.x, change.y, 0, Direction.from(change.directionX, change.directionY)); mobileEntities.set(bullet.id, bullet); } case GameChangeType.DESTROED: @@ -143,10 +143,10 @@ class Engine implements IEngine { entiny.x += entiny.mx; entiny.y += entiny.my; - /*var tankR = new Rectangle(tank.x, tank.y, tank.width, tank.height); + /*var tankR = Map Rectangle(tank.x, tank.y, tank.width, tank.height); for (t in tanks) if (t != tank) { - var r = new Rectangle(t.x, t.y, t.width, t.height); + var r = Map Rectangle(t.x, t.y, t.width, t.height); if (tankR.intersects(r)) { if (tank.direction.x > 0) { if (tank.x + tank.width > t.x) tank.x = t.x - tank.width; diff --git a/src/common/haxe/ru/m/tankz/engine/IEngine.hx b/src/common/haxe/ru/m/tankz/engine/IEngine.hx index 3e05a11..27369f2 100755 --- a/src/common/haxe/ru/m/tankz/engine/IEngine.hx +++ b/src/common/haxe/ru/m/tankz/engine/IEngine.hx @@ -4,17 +4,17 @@ import ru.m.tankz.proto.game.GameChange; import ru.m.tankz.core.IMobileEntity; import ru.m.tankz.core.Tank; import ru.m.tankz.proto.core.Player; -import ru.m.tankz.config.TankzConfig; -import ru.m.tankz.map.ITankzMap; +import ru.m.tankz.config.Config; +import ru.m.tankz.map.ILevelMap; interface IEngine { - public var config(default, default):TankzConfig; - public var map(default, null):ITankzMap; + public var config(default, default):Config; + public var map(default, null):ILevelMap; public var tanks(default, null):Map; public var mobileEntities(default, null):Map; public function clear():Void; - public function init(config:TankzConfig):Void; + public function init(config:Config):Void; public function initTanks(players:Array):Array; public function action(tankId:Int, action:TankAction):Void; //public function updateFromChanges(changes:Array):Void; diff --git a/src/common/haxe/ru/m/tankz/map/ITankzMap.hx b/src/common/haxe/ru/m/tankz/map/ILevelMap.hx similarity index 90% rename from src/common/haxe/ru/m/tankz/map/ITankzMap.hx rename to src/common/haxe/ru/m/tankz/map/ILevelMap.hx index 0a509f1..69c14e7 100755 --- a/src/common/haxe/ru/m/tankz/map/ITankzMap.hx +++ b/src/common/haxe/ru/m/tankz/map/ILevelMap.hx @@ -1,6 +1,6 @@ package ru.m.tankz.map; -interface ITankzMap { +interface ILevelMap { public var cellWidth(default, null):Float; public var cellHeight(default, null):Float; public var gridWidth(default, null):Int; diff --git a/src/common/haxe/ru/m/tankz/map/TankzMap.hx b/src/common/haxe/ru/m/tankz/map/LevelMap.hx similarity index 82% rename from src/common/haxe/ru/m/tankz/map/TankzMap.hx rename to src/common/haxe/ru/m/tankz/map/LevelMap.hx index 44e062a..37883b6 100755 --- a/src/common/haxe/ru/m/tankz/map/TankzMap.hx +++ b/src/common/haxe/ru/m/tankz/map/LevelMap.hx @@ -1,8 +1,8 @@ package ru.m.tankz.map; -import ru.m.tankz.config.TankzConfig.MapConfig; +import ru.m.tankz.config.Config.MapConfig; -class TankzMap implements ITankzMap { +class LevelMap implements ILevelMap { public var cellWidth(default, null):Float; public var cellHeight(default, null):Float;