[common] add map size
This commit is contained in:
@@ -6,6 +6,7 @@ import ru.m.tankz.game.IGame;
|
||||
|
||||
interface IRender extends IView<Dynamic> extends GameListener {
|
||||
public var config(default, set):Config;
|
||||
public var gridSize(default, set):GridSize;
|
||||
public function draw():Void;
|
||||
public function reset():Void;
|
||||
}
|
||||
|
||||
@@ -26,6 +26,10 @@ using ru.m.display.DisplayObjectContainerExtender;
|
||||
class Render extends SpriteView implements IRender {
|
||||
|
||||
public var config(default, set):Config;
|
||||
public var gridSize(default, set):GridSize;
|
||||
|
||||
private var mapWidth(get, null):Float;
|
||||
private var mapHeight(get, null):Float;
|
||||
|
||||
private var backgroundLayer:Sprite;
|
||||
private var groundLayer:Sprite;
|
||||
@@ -51,18 +55,33 @@ class Render extends SpriteView implements IRender {
|
||||
reset();
|
||||
}
|
||||
|
||||
private function get_mapWidth():Float {
|
||||
return config.map.cell.width * (gridSize != null ? gridSize.width : config.map.grid.width);
|
||||
}
|
||||
|
||||
private function get_mapHeight():Float {
|
||||
return config.map.cell.height * (gridSize != null ? gridSize.height : config.map.grid.height);
|
||||
}
|
||||
|
||||
private function set_config(value:Config):Config {
|
||||
config = value;
|
||||
setContentSize(config.mapWidth, config.mapHeight);
|
||||
setContentSize(mapWidth, mapHeight, "render");
|
||||
drawBackground();
|
||||
return config;
|
||||
}
|
||||
|
||||
private function set_gridSize(value:GridSize):GridSize {
|
||||
gridSize = value;
|
||||
setContentSize(mapWidth, mapHeight, "render");
|
||||
drawBackground();
|
||||
return gridSize;
|
||||
}
|
||||
|
||||
private function drawBackground():Void {
|
||||
var g:Graphics = backgroundLayer.graphics;
|
||||
g.clear();
|
||||
g.beginFill(0x000000);
|
||||
g.drawRect(0, 0, config.mapWidth, config.mapHeight);
|
||||
g.drawRect(0, 0, mapWidth, mapHeight);
|
||||
g.endFill();
|
||||
}
|
||||
|
||||
|
||||
@@ -34,6 +34,7 @@ import ru.m.tankz.view.game.GameView;
|
||||
gameView.type = game.type;
|
||||
soundManager.config = game.config;
|
||||
gameView.render.config = game.config;
|
||||
gameView.render.gridSize = game.state.level.size;
|
||||
game.connect(gameView.render);
|
||||
game.connect(soundManager);
|
||||
if (gameView.panel != null) {
|
||||
|
||||
Reference in New Issue
Block a user