[map] load
This commit is contained in:
14
WORK.md
14
WORK.md
@@ -1,8 +1,8 @@
|
|||||||
* build
|
* build
|
||||||
* gulp
|
* gulp 100%
|
||||||
|
|
||||||
* deploy
|
* deploy
|
||||||
* capistrano
|
* capistrano 100%
|
||||||
|
|
||||||
* ui
|
* ui
|
||||||
* login frame
|
* login frame
|
||||||
@@ -11,10 +11,10 @@
|
|||||||
* game frame
|
* game frame
|
||||||
|
|
||||||
* engine
|
* engine
|
||||||
* config
|
* config 50%
|
||||||
* map
|
* map 50%
|
||||||
* tanks
|
* tanks 2%
|
||||||
* bullets
|
* bullets 2%
|
||||||
* boxes
|
* boxes
|
||||||
* map changes
|
* map changes
|
||||||
* bonuses
|
* bonuses
|
||||||
@@ -22,4 +22,4 @@
|
|||||||
* proto
|
* proto
|
||||||
|
|
||||||
* common
|
* common
|
||||||
* single game
|
* single game 2%
|
||||||
@@ -1,5 +1,7 @@
|
|||||||
package ru.m.tankz;
|
package ru.m.tankz;
|
||||||
|
|
||||||
|
import flash.ui.Keyboard;
|
||||||
|
import flash.events.KeyboardEvent;
|
||||||
import flash.text.Font;
|
import flash.text.Font;
|
||||||
import ru.m.tankz.view.frames.StartFrame;
|
import ru.m.tankz.view.frames.StartFrame;
|
||||||
import haxework.log.SocketLogger;
|
import haxework.log.SocketLogger;
|
||||||
@@ -25,64 +27,70 @@ class MainView extends VGroupView implements ViewBuilder {}
|
|||||||
|
|
||||||
class Client implements IConnectionHandler {
|
class Client implements IConnectionHandler {
|
||||||
|
|
||||||
private static inline var TAG = "Tankz";
|
private static inline var TAG = "Tankz";
|
||||||
|
|
||||||
public static function main() {
|
public static function main() {
|
||||||
L.push(new TraceLogger());
|
L.push(new TraceLogger());
|
||||||
#if flash
|
#if flash
|
||||||
L.push(new JSLogger());
|
L.push(new JSLogger());
|
||||||
#end
|
#end
|
||||||
#if debug
|
#if debug
|
||||||
L.push(new SocketLogger());
|
L.push(new SocketLogger());
|
||||||
#end
|
#end
|
||||||
Const.init();
|
Const.init();
|
||||||
L.d(TAG, "Debug: " + Const.DEBUG);
|
L.d(TAG, "Debug: " + Const.DEBUG);
|
||||||
L.i(TAG, "Version: " + Const.VERSION);
|
L.i(TAG, "Version: " + Const.VERSION);
|
||||||
L.i(TAG, "Build: " + Const.BUILD);
|
L.i(TAG, "Build: " + Const.BUILD);
|
||||||
new Client();
|
new Client();
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
private var view:MainView;
|
|
||||||
|
|
||||||
public function new() {
|
|
||||||
Provider.setFactory(IResources, Resources);
|
|
||||||
|
|
||||||
var font:Font = Font.enumerateFonts()[0];
|
|
||||||
Provider.get(IResources).text.put("font", "Bookman Old Style");
|
|
||||||
Provider.get(IResources).text.put("version", 'v${Const.VERSION} b${Const.BUILD}');
|
|
||||||
|
|
||||||
Provider.set(IPacketBuilder, new PacketBuilder());
|
|
||||||
#if flash
|
|
||||||
Provider.set(IConnection, new ru.m.core.connect.flash.FlashConnection("localhost", 5001));
|
|
||||||
#elseif html5
|
|
||||||
Provider.set(IConnection, new ru.m.core.connect.js.JsConnection("localhost", 5001));
|
|
||||||
#end
|
|
||||||
|
|
||||||
Provider.get(IConnection).handler.addListener(this);
|
|
||||||
|
|
||||||
view = new MainView();
|
|
||||||
Provider.set(IFrameSwitcher, view.switcher);
|
|
||||||
Root.bind(view);
|
|
||||||
//view.logout.onPress = this;
|
|
||||||
view.switcher.change(StartFrame.ID);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function onPress(view:ButtonView):Void {
|
|
||||||
switch (view.id) {
|
|
||||||
case "logout":
|
|
||||||
Provider.get(IConnection).disconnect();
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public function onConnected():Void {}
|
|
||||||
|
|
||||||
public function onDisconnected():Void {
|
private var view:MainView;
|
||||||
//view.switcher.change(AuthFrame.ID);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function onError(error:Dynamic):Void {
|
public function new() {
|
||||||
L.e(TAG, "", error);
|
Provider.setFactory(IResources, Resources);
|
||||||
//view.switcher.change(AuthFrame.ID);
|
|
||||||
}
|
var font:Font = Font.enumerateFonts()[0];
|
||||||
|
Provider.get(IResources).text.put("font", "Bookman Old Style");
|
||||||
|
Provider.get(IResources).text.put("version", 'v${Const.VERSION} b${Const.BUILD}');
|
||||||
|
|
||||||
|
Provider.set(IPacketBuilder, new PacketBuilder());
|
||||||
|
#if flash
|
||||||
|
Provider.set(IConnection, new ru.m.core.connect.flash.FlashConnection("localhost", 5001));
|
||||||
|
#elseif html5
|
||||||
|
Provider.set(IConnection, new ru.m.core.connect.js.JsConnection("localhost", 5001));
|
||||||
|
#end
|
||||||
|
|
||||||
|
Provider.get(IConnection).handler.addListener(this);
|
||||||
|
|
||||||
|
view = new MainView();
|
||||||
|
Provider.set(IFrameSwitcher, view.switcher);
|
||||||
|
Root.bind(view);
|
||||||
|
//view.logout.onPress = this;
|
||||||
|
view.switcher.change(StartFrame.ID);
|
||||||
|
|
||||||
|
view.content.stage.addEventListener(KeyboardEvent.KEY_UP, function(event:KeyboardEvent):Void {
|
||||||
|
if (event.keyCode == Keyboard.ESCAPE) {
|
||||||
|
view.switcher.change(StartFrame.ID);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public function onPress(view:ButtonView):Void {
|
||||||
|
switch (view.id) {
|
||||||
|
case "logout":
|
||||||
|
Provider.get(IConnection).disconnect();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function onConnected():Void {}
|
||||||
|
|
||||||
|
public function onDisconnected():Void {
|
||||||
|
//view.switcher.change(AuthFrame.ID);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function onError(error:Dynamic):Void {
|
||||||
|
L.e(TAG, "", error);
|
||||||
|
//view.switcher.change(AuthFrame.ID);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ class PlayerControl {
|
|||||||
moveQueue = new Array<Int>();
|
moveQueue = new Array<Int>();
|
||||||
Lib.current.stage.addEventListener(KeyboardEvent.KEY_DOWN, onKeyDown);
|
Lib.current.stage.addEventListener(KeyboardEvent.KEY_DOWN, onKeyDown);
|
||||||
Lib.current.stage.addEventListener(KeyboardEvent.KEY_UP, onKeyUp);
|
Lib.current.stage.addEventListener(KeyboardEvent.KEY_UP, onKeyUp);
|
||||||
Lib.current.stage.addEventListener(FocusEvent.FOCUS_OUT, onFocusOut);
|
//Lib.current.stage.addEventListener(FocusEvent.FOCUS_OUT, onFocusOut);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function onKeyDown(event:KeyboardEvent):Void {
|
private function onKeyDown(event:KeyboardEvent):Void {
|
||||||
|
|||||||
@@ -5,4 +5,5 @@ import ru.m.tankz.engine.IEngine;
|
|||||||
|
|
||||||
interface IRender extends IView {
|
interface IRender extends IView {
|
||||||
public function draw(game:IEngine):Void;
|
public function draw(game:IEngine):Void;
|
||||||
|
public function reset():Void;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
package ru.m.tankz.render;
|
package ru.m.tankz.render;
|
||||||
|
|
||||||
|
import ru.m.tankz.core.Entity;
|
||||||
|
import ru.m.tankz.map.Brick;
|
||||||
import ru.m.tankz.core.Direction;
|
import ru.m.tankz.core.Direction;
|
||||||
import flash.geom.Matrix;
|
import flash.geom.Matrix;
|
||||||
import openfl.Assets;
|
import openfl.Assets;
|
||||||
@@ -10,78 +12,188 @@ import flash.display.Graphics;
|
|||||||
import haxework.gui.SpriteView;
|
import haxework.gui.SpriteView;
|
||||||
import ru.m.tankz.engine.IEngine;
|
import ru.m.tankz.engine.IEngine;
|
||||||
|
|
||||||
|
|
||||||
|
interface IState<T> {
|
||||||
|
public function update(object:T):Bool;
|
||||||
|
}
|
||||||
|
|
||||||
|
class BrickState implements IState<Brick> {
|
||||||
|
private var type:BrickType;
|
||||||
|
|
||||||
|
public function new() {}
|
||||||
|
|
||||||
|
public function update(object:Brick):Bool {
|
||||||
|
if (type != object.type) {
|
||||||
|
type = object.type;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class EntityState implements IState<Entity> {
|
||||||
|
private var x:Float;
|
||||||
|
private var y:Float;
|
||||||
|
|
||||||
|
public function new() {}
|
||||||
|
|
||||||
|
public function update(object:Entity):Bool {
|
||||||
|
if (x != object.x || y != object.y) {
|
||||||
|
x = object.x;
|
||||||
|
y = object.y;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
class Render extends SpriteView implements IRender {
|
class Render extends SpriteView implements IRender {
|
||||||
|
|
||||||
private var mapLayer:Sprite;
|
private static var GROUND_BRICKS:Array<BrickType> = [
|
||||||
private var tankLayer:Sprite;
|
BrickType.BRICK, BrickType.ARMOR, BrickType.WATER, BrickType.ACE
|
||||||
|
];
|
||||||
|
|
||||||
public function new() {
|
private static var UP_BRICKS:Array<BrickType> = [
|
||||||
super();
|
BrickType.BUSH
|
||||||
mapLayer = new Sprite();
|
];
|
||||||
tankLayer = new Sprite();
|
|
||||||
contentAsSprite.addChild(mapLayer);
|
|
||||||
contentAsSprite.addChild(tankLayer);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function draw(game:IEngine):Void {
|
private var backgroundLayer:Sprite;
|
||||||
var mapWidth = game.map.gridWidth * game.map.cellWidth;
|
private var groundLayer:Sprite;
|
||||||
var mapHeight = game.map.gridHeight * game.map.cellHeight;
|
private var entryLayer:Sprite;
|
||||||
|
private var upLayer:Sprite;
|
||||||
|
|
||||||
if (contentSize) {
|
private var layersForUpdate:Map<Sprite, Bool>;
|
||||||
width = mapWidth;
|
private var states:Map<String, IState<Dynamic>>;
|
||||||
height = mapHeight;
|
|
||||||
|
public function new() {
|
||||||
|
super();
|
||||||
|
layersForUpdate = new Map();
|
||||||
|
backgroundLayer = new Sprite();
|
||||||
|
groundLayer = new Sprite();
|
||||||
|
entryLayer = new Sprite();
|
||||||
|
upLayer = new Sprite();
|
||||||
|
contentAsSprite.addChild(backgroundLayer);
|
||||||
|
contentAsSprite.addChild(groundLayer);
|
||||||
|
contentAsSprite.addChild(entryLayer);
|
||||||
|
contentAsSprite.addChild(upLayer);
|
||||||
|
reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
var g:Graphics = mapLayer.graphics;
|
private function invalidateLayers(game:IEngine):Void {
|
||||||
g.clear();
|
for (brick in game.map.bricks) {
|
||||||
g.beginFill(0x00ff00);
|
if (!states.exists(brick.key)) {
|
||||||
g.drawRect(0, 0, mapWidth, mapHeight);
|
states[brick.key] = new BrickState();
|
||||||
g.endFill();
|
}
|
||||||
|
if (states.get(brick.key).update(brick)) {
|
||||||
g.lineStyle(1, 0x000000);
|
layersForUpdate[groundLayer] = true;
|
||||||
for (i in 0...game.map.gridWidth + 1) {
|
layersForUpdate[upLayer] = true;
|
||||||
g.moveTo(i * game.map.cellWidth, 0);
|
}
|
||||||
g.lineTo(i * game.map.cellWidth, mapHeight);
|
}
|
||||||
|
for (entry in game.mobileEntities) {
|
||||||
|
if (!states.exists(entry.key)) {
|
||||||
|
states[entry.key] = new EntityState();
|
||||||
|
}
|
||||||
|
if (states.get(entry.key).update(entry)) {
|
||||||
|
layersForUpdate[entryLayer] = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
for (i in 0...game.map.gridHeight + 1) {
|
|
||||||
g.moveTo(0, i * game.map.cellHeight);
|
private function drawBackground(game:IEngine):Void {
|
||||||
g.lineTo(mapWidth, i * game.map.cellHeight);
|
var mapWidth = game.map.gridWidth * game.map.cellWidth;
|
||||||
|
var mapHeight = game.map.gridHeight * game.map.cellHeight;
|
||||||
|
|
||||||
|
if (layersForUpdate[backgroundLayer]) {
|
||||||
|
var g:Graphics = backgroundLayer.graphics;
|
||||||
|
g.clear();
|
||||||
|
g.beginFill(0x000000);
|
||||||
|
g.drawRect(0, 0, mapWidth, mapHeight);
|
||||||
|
g.endFill();
|
||||||
|
if (contentSize) {
|
||||||
|
width = mapWidth;
|
||||||
|
height = mapHeight;
|
||||||
|
}
|
||||||
|
layersForUpdate[backgroundLayer] = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
g.lineStyle();
|
|
||||||
|
|
||||||
var g:Graphics = tankLayer.graphics;
|
private function drawMap(game:IEngine):Void {
|
||||||
g.clear();
|
if (layersForUpdate[groundLayer] || layersForUpdate[upLayer]) {
|
||||||
|
groundLayer.graphics.clear();
|
||||||
for (e in game.mobileEntities) {
|
upLayer.graphics.clear();
|
||||||
if (Std.is(e, Tank)) {
|
for (brick in game.map.bricks) {
|
||||||
var m = new Matrix();
|
var g:Graphics = null;
|
||||||
m.rotate(calcRotate(e.direction));
|
if (GROUND_BRICKS.indexOf(brick.type) > -1) {
|
||||||
m.translate(e.x, e.y);
|
g = groundLayer.graphics;
|
||||||
g.beginBitmapFill(Assets.getBitmapData("resources/images/tank/player/tank_p0_0-0.png"), m);
|
} else if (UP_BRICKS.indexOf(brick.type) > -1) {
|
||||||
g.drawRect(e.x, e.y, e.width, e.height);
|
g = upLayer.graphics;
|
||||||
g.endFill();
|
}
|
||||||
} else if (Std.is(e, Bullet)) {
|
if (g != null) {
|
||||||
var m = new Matrix();
|
g.beginFill(0x00ff00);
|
||||||
m.rotate(calcRotate(e.direction));
|
g.beginBitmapFill(Assets.getBitmapData('resources/images/map/map_${brick.type}.png'));
|
||||||
m.translate(e.x, e.y);
|
g.drawRect(
|
||||||
g.beginBitmapFill(Assets.getBitmapData("resources/images/bullet/bullet_0.png"), m);
|
brick.cellX * game.map.cellWidth,
|
||||||
g.drawRect(e.x, e.y, e.width, e.height);
|
brick.cellY * game.map.cellHeight,
|
||||||
g.endFill();
|
game.map.cellWidth,
|
||||||
}
|
game.map.cellHeight
|
||||||
|
);
|
||||||
|
g.endFill();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
layersForUpdate[groundLayer] = false;
|
||||||
|
layersForUpdate[upLayer] = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
private function calcRotate(direction:Direction):Float {
|
public function drawEntries(game:IEngine):Void {
|
||||||
return (if (direction == Direction.RIGHT) {
|
if (layersForUpdate[entryLayer]) {
|
||||||
0;
|
var g:Graphics = entryLayer.graphics;
|
||||||
} else if (direction == Direction.LEFT) {
|
g.clear();
|
||||||
180;
|
for (e in game.mobileEntities) {
|
||||||
} else if (direction == Direction.TOP) {
|
if (Std.is(e, Tank)) {
|
||||||
270;
|
var m = new Matrix();
|
||||||
} else if (direction == Direction.BOTTOM) {
|
m.rotate(calcRotate(e.direction));
|
||||||
90;
|
m.translate(e.x, e.y);
|
||||||
} else {
|
g.beginBitmapFill(Assets.getBitmapData("resources/images/tank/player/tank_p0_0-0.png"), m);
|
||||||
0;
|
g.drawRect(e.x, e.y, e.width, e.height);
|
||||||
}) * (Math.PI / 180);
|
g.endFill();
|
||||||
}
|
} else if (Std.is(e, Bullet)) {
|
||||||
|
var m = new Matrix();
|
||||||
|
m.rotate(calcRotate(e.direction));
|
||||||
|
m.translate(e.x, e.y);
|
||||||
|
g.beginBitmapFill(Assets.getBitmapData("resources/images/bullet/bullet_0.png"), m);
|
||||||
|
g.drawRect(e.x, e.y, e.width, e.height);
|
||||||
|
g.endFill();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
layersForUpdate[entryLayer] = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function draw(game:IEngine):Void {
|
||||||
|
invalidateLayers(game);
|
||||||
|
drawBackground(game);
|
||||||
|
drawMap(game);
|
||||||
|
drawEntries(game);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function reset():Void {
|
||||||
|
states = new Map<String, IState<Dynamic>>();
|
||||||
|
layersForUpdate[backgroundLayer] = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function calcRotate(direction:Direction):Float {
|
||||||
|
return (if (direction == Direction.RIGHT) {
|
||||||
|
0;
|
||||||
|
} else if (direction == Direction.LEFT) {
|
||||||
|
180;
|
||||||
|
} else if (direction == Direction.TOP) {
|
||||||
|
270;
|
||||||
|
} else if (direction == Direction.BOTTOM) {
|
||||||
|
90;
|
||||||
|
} else {
|
||||||
|
0;
|
||||||
|
}) * (Math.PI / 180);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ class GameFrame extends VGroupView implements ViewBuilder implements IPacketHand
|
|||||||
|
|
||||||
public function onShow():Void {
|
public function onShow():Void {
|
||||||
var game:Game = Provider.get(Game);
|
var game:Game = Provider.get(Game);
|
||||||
engine.init(ConfigBundle.get(GameType.CLASSIC));
|
engine.init(ConfigBundle.get(GameType.CLASSIC, 0));
|
||||||
engine.initTanks(game.players);
|
engine.initTanks(game.players);
|
||||||
content.addEventListener(Event.ENTER_FRAME, updateGame);
|
content.addEventListener(Event.ENTER_FRAME, updateGame);
|
||||||
for (index in 0...game.players.length) {
|
for (index in 0...game.players.length) {
|
||||||
@@ -46,6 +46,7 @@ class GameFrame extends VGroupView implements ViewBuilder implements IPacketHand
|
|||||||
Provider.get(IConnection).packetHandler.removeListener(this);
|
Provider.get(IConnection).packetHandler.removeListener(this);
|
||||||
content.removeEventListener(Event.ENTER_FRAME, updateGame);
|
content.removeEventListener(Event.ENTER_FRAME, updateGame);
|
||||||
engine.clear();
|
engine.clear();
|
||||||
|
render.reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
private function updateGame(_):Void {
|
private function updateGame(_):Void {
|
||||||
|
|||||||
BIN
src/client/resources/images/map/map_3.png
Normal file
BIN
src/client/resources/images/map/map_3.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 598 B |
@@ -1,27 +1 @@
|
|||||||
00000000000000000000000000
|
00000000000000000000000000
|
||||||
|
|
||||||
00000000000000000000000000
|
|
||||||
|
|
||||||
00055500055500005000555000
|
|
||||||
|
|
||||||
00550550550550055005505500
|
|
||||||
|
|
||||||
00000050500050555005000500
|
|
||||||
|
|
||||||
00000550500050505005000500
|
|
||||||
|
|
||||||
00055500500050005005000500
|
|
||||||
|
|
||||||
00550000550550055005505500
|
|
||||||
|
|
||||||
00555550055500555500555000
|
|
||||||
|
|
||||||
00000000000000000000000000
|
|
||||||
|
|
||||||
22222222222222222222222222
|
|
||||||
|
|
||||||
22222222222222222222222222
|
|
||||||
|
|
||||||
44111111111144111111111144
|
|
||||||
|
|
||||||
44111111111144111111111144
|
|
||||||
@@ -1,5 +1,7 @@
|
|||||||
package ru.m.tankz.config;
|
package ru.m.tankz.config;
|
||||||
|
|
||||||
|
import openfl.utils.Assets;
|
||||||
|
import ru.m.tankz.map.Brick.BrickType;
|
||||||
import ru.m.tankz.proto.core.GameType;
|
import ru.m.tankz.proto.core.GameType;
|
||||||
import ru.m.tankz.core.Direction;
|
import ru.m.tankz.core.Direction;
|
||||||
|
|
||||||
@@ -8,6 +10,8 @@ typedef MapConfig = {
|
|||||||
var cellHeight:Float;
|
var cellHeight:Float;
|
||||||
var gridWidth:Int;
|
var gridWidth:Int;
|
||||||
var gridHeight:Int;
|
var gridHeight:Int;
|
||||||
|
|
||||||
|
var bricks:Array<BrickType>;
|
||||||
}
|
}
|
||||||
|
|
||||||
enum SpawnPointType {
|
enum SpawnPointType {
|
||||||
@@ -53,7 +57,8 @@ class ConfigBundle {
|
|||||||
cellWidth: 22,
|
cellWidth: 22,
|
||||||
cellHeight: 22,
|
cellHeight: 22,
|
||||||
gridWidth: 26,
|
gridWidth: 26,
|
||||||
gridHeight: 26
|
gridHeight: 26,
|
||||||
|
bricks: null
|
||||||
},
|
},
|
||||||
[
|
[
|
||||||
{
|
{
|
||||||
@@ -73,9 +78,17 @@ class ConfigBundle {
|
|||||||
]
|
]
|
||||||
);
|
);
|
||||||
|
|
||||||
public static function get(type:Int):Config {
|
public static function get(type:Int, level:Int):Config {
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case GameType.CLASSIC:
|
case GameType.CLASSIC:
|
||||||
|
var bricksData:String = Assets.getText('resources/levels/level00${level}.txt');
|
||||||
|
var bricks:Array<BrickType> = [];
|
||||||
|
for (line in ~/\s+/g.split(bricksData)) {
|
||||||
|
for (c in line.split('')) {
|
||||||
|
bricks.push(Std.parseInt(c));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
CLASSIC.map.bricks = bricks; // ToDo:
|
||||||
return CLASSIC;
|
return CLASSIC;
|
||||||
case _:
|
case _:
|
||||||
return null;
|
return null;
|
||||||
|
|||||||
@@ -7,9 +7,14 @@ class Entity implements IEntity {
|
|||||||
|
|
||||||
public var width(default, default):Float;
|
public var width(default, default):Float;
|
||||||
public var height(default, default):Float;
|
public var height(default, default):Float;
|
||||||
|
public var key(get, null):String;
|
||||||
|
|
||||||
public function new(x:Float, y:Float) {
|
public function new(x:Float, y:Float) {
|
||||||
this.x = x;
|
this.x = x;
|
||||||
this.y = y;
|
this.y = y;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function get_key():String {
|
||||||
|
return '${Type.getClassName(Type.getClass(this))}';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
package ru.m.tankz.core;
|
package ru.m.tankz.core;
|
||||||
|
|
||||||
interface IEntity {
|
interface IEntity extends IKey {
|
||||||
public var x(default, default):Float;
|
public var x(default, default):Float;
|
||||||
public var y(default, default):Float;
|
public var y(default, default):Float;
|
||||||
|
|
||||||
|
|||||||
5
src/common/haxe/ru/m/tankz/core/IKey.hx
Normal file
5
src/common/haxe/ru/m/tankz/core/IKey.hx
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
package ru.m.tankz.core;
|
||||||
|
|
||||||
|
interface IKey {
|
||||||
|
public var key(get, null):String;
|
||||||
|
}
|
||||||
@@ -28,4 +28,8 @@ class MobileEntity extends Entity implements IMobileEntity {
|
|||||||
mx = 0;
|
mx = 0;
|
||||||
my = 0;
|
my = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override private function get_key():String {
|
||||||
|
return '${super.get_key()}:${id}';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
31
src/common/haxe/ru/m/tankz/map/Brick.hx
Normal file
31
src/common/haxe/ru/m/tankz/map/Brick.hx
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
package ru.m.tankz.map;
|
||||||
|
|
||||||
|
import ru.m.tankz.core.IKey;
|
||||||
|
|
||||||
|
|
||||||
|
@:enum abstract BrickType(Int) from Int to Int {
|
||||||
|
var NONE = 0;
|
||||||
|
var ACE = 1;
|
||||||
|
var BUSH = 2;
|
||||||
|
var WATER = 3;
|
||||||
|
var ARMOR = 4;
|
||||||
|
var BRICK = 5;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
class Brick implements IKey {
|
||||||
|
public var cellX(default, null):Int;
|
||||||
|
public var cellY(default, null):Int;
|
||||||
|
public var type(default, null):BrickType;
|
||||||
|
public var key(get, null):String;
|
||||||
|
|
||||||
|
public function new(type:BrickType, cellX:Int, cellY:Int) {
|
||||||
|
this.cellX = cellX;
|
||||||
|
this.cellY = cellY;
|
||||||
|
this.type = type;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function get_key():String {
|
||||||
|
return 'brick:${cellX}:${cellY}';
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,8 +1,11 @@
|
|||||||
package ru.m.tankz.map;
|
package ru.m.tankz.map;
|
||||||
|
|
||||||
|
|
||||||
interface ILevelMap {
|
interface ILevelMap {
|
||||||
public var cellWidth(default, null):Float;
|
public var cellWidth(default, null):Float;
|
||||||
public var cellHeight(default, null):Float;
|
public var cellHeight(default, null):Float;
|
||||||
public var gridWidth(default, null):Int;
|
public var gridWidth(default, null):Int;
|
||||||
public var gridHeight(default, null):Int;
|
public var gridHeight(default, null):Int;
|
||||||
|
|
||||||
|
public var bricks(default, null):Array<Brick>;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,15 +4,18 @@ import ru.m.tankz.config.Config.MapConfig;
|
|||||||
|
|
||||||
class LevelMap implements ILevelMap {
|
class LevelMap implements ILevelMap {
|
||||||
|
|
||||||
public var cellWidth(default, null):Float;
|
public var cellWidth(default, null):Float;
|
||||||
public var cellHeight(default, null):Float;
|
public var cellHeight(default, null):Float;
|
||||||
public var gridWidth(default, null):Int;
|
public var gridWidth(default, null):Int;
|
||||||
public var gridHeight(default, null):Int;
|
public var gridHeight(default, null):Int;
|
||||||
|
|
||||||
public function new(config:MapConfig) {
|
public var bricks(default, null):Array<Brick>;
|
||||||
cellWidth = config.cellWidth;
|
|
||||||
cellHeight = config.cellHeight;
|
public function new(config:MapConfig) {
|
||||||
gridWidth = config.gridWidth;
|
cellWidth = config.cellWidth;
|
||||||
gridHeight = config.gridHeight;
|
cellHeight = config.cellHeight;
|
||||||
}
|
gridWidth = config.gridWidth;
|
||||||
|
gridHeight = config.gridHeight;
|
||||||
|
bricks = Lambda.array(Lambda.mapi(config.bricks, function(i, type):Brick return new Brick(type, Std.int(i % gridWidth), Std.int(Math.floor(i / gridHeight)))));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user