[client] added any map item renders

This commit is contained in:
2018-02-13 14:44:04 +03:00
parent f68e5d160f
commit 05b6fe4a56
17 changed files with 77 additions and 39 deletions

View File

@@ -26,8 +26,6 @@ class Animate extends Bitmap {
}
}
private static var a = new BitmapData(1, 1);
public var playing(default, set):Bool;
public var frames(default, set):Array<BitmapData>;
private var index:Int;

View File

@@ -54,13 +54,21 @@ class Render extends SpriteView implements EngineListener {
}
public function draw(game:Engine):Void {
for (brick in game.map.bricks) if (brick.config.type > 0) {
for (brick in game.map.bricks) if (brick.config.index > 0) {
if (!items.exists(brick.key)) {
items[brick.key] = new BrickItem(brick);
var item:RenderItem<Dynamic, Dynamic> = switch(brick.config.type) {
case 'ace' | 'bush': new BrickItem(brick);
case 'water': new BrickAnimateItem(brick);
case 'armor' | 'brick': new BrickBreakingItem(brick);
case x: null;
};
if (item != null) {
items[brick.key] = item;
if (brick.config.layer > 2) {
upLayer.addChild(items[brick.key].view);
upLayer.addChild(item.view);
} else {
groundLayer.addChild(items[brick.key].view);
groundLayer.addChild(item.view);
}
}
}
}

View File

@@ -1,5 +1,6 @@
package ru.m.tankz.render;
import ru.m.tankz.Type.BrickType;
import openfl.display.BitmapData;
import ru.m.draw.Color;
import ru.m.tankz.core.Bonus;
@@ -77,10 +78,39 @@ class BitmapItem<T:TRectangle> extends RenderItem<T, Bitmap> {
}
class BrickItem extends RenderItem<Brick, Shape> {
class BrickItem extends BitmapItem<Brick> {
public function new(value:Brick) {
super(value);
redraw();
}
override private function getImage():String {
return 'resources/image/map/${value.config.type}.png';
}
}
class BrickAnimateItem extends AnimateItem<Brick> {
public function new(value:Brick) {
super(value);
redraw();
}
override public function redraw():Void {
var frame0 = Assets.getBitmapData('resources/image/map/${value.config.type}-0.png');
var frame1 = Assets.getBitmapData('resources/image/map/${value.config.type}-1.png');
view.frames = [for (i in 0...15) frame0].concat([for (i in 0...15) frame1]);
view.playing = true;
}
}
class BrickBreakingItem extends RenderItem<Brick, Shape> {
private var broken:Int;
private var type:Int;
private var type:BrickType;
public function new(value:Brick) {
super(value);
@@ -93,7 +123,7 @@ class BrickItem extends RenderItem<Brick, Shape> {
var g = view.graphics;
g.clear();
if (value.destroyed) return;
if (value.config.type > 0) {
if (value.config.index > 0) {
g.beginBitmapFill(image);
g.drawRect(0, 0, value.rect.width, value.rect.height);
for (c in value.cells) {
@@ -118,7 +148,7 @@ class BrickItem extends RenderItem<Brick, Shape> {
}
private function getImage():String {
return 'resources/images/map/map_${value.config.type}.png';
return 'resources/image/map/${value.config.type}.png';
}
}

View File

@@ -9,13 +9,13 @@ map:
gridHeight: 26
bricks:
- {type: -1, layer: 2, armor: -1} # border
- {type: 0, layer: 0, armor: 0} # none
- {type: 1, layer: 0, armor: 0} # ace
- {type: 2, layer: 3, armor: 0} # bush
- {type: 3, layer: 1, armor: 0} # water
- {type: 4, layer: 2, armor: 2} # armor
- {type: 5, layer: 2, armor: 1} # brick
- {type: border, index: -1, layer: 2, armor: -1}
- {type: none, index: 0, layer: 0, armor: 0}
- {type: ace, index: 1, layer: 0, armor: 0}
- {type: bush, index: 2, layer: 3, armor: 0}
- {type: water, index: 3, layer: 1, armor: 0}
- {type: armor, index: 4, layer: 2, armor: 2}
- {type: brick, index: 5, layer: 2, armor: 1}
player:
human: &human

View File

@@ -9,13 +9,13 @@ map:
gridHeight: 30
bricks:
- {type: -1, layer: 2, armor: -1} # border
- {type: 0, layer: 0, armor: 0} # none
- {type: 1, layer: 0, armor: 0} # ace
- {type: 2, layer: 3, armor: 0} # bush
- {type: 3, layer: 1, armor: 0} # water
- {type: 4, layer: 2, armor: 2} # armor
- {type: 5, layer: 2, armor: 1} # brick
- {type: border, index: -1, layer: 2, armor: -1}
- {type: none, index: 0, layer: 0, armor: 0}
- {type: ace, index: 1, layer: 0, armor: 0}
- {type: bush, index: 2, layer: 3, armor: 0}
- {type: water, index: 3, layer: 1, armor: 0}
- {type: armor, index: 4, layer: 2, armor: 2}
- {type: brick, index: 5, layer: 2, armor: 1}
team:
radiant: &radiant

Binary file not shown.

After

Width:  |  Height:  |  Size: 307 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 304 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 279 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 969 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 93 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 598 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 531 B

View File

@@ -9,7 +9,7 @@ typedef TeamId = String;
typedef ControlType = String;
typedef BrickType = Int;
typedef BrickType = String;
typedef TankType = String;

View File

@@ -27,6 +27,7 @@ typedef MapConfig = {
typedef BrickConfig = {
var type:BrickType;
var index:Int;
var layer:Int;
var armor:Int;
}
@@ -97,7 +98,8 @@ class Config {
public var points(default, null):Array<SpawnPoint>;
public var bonuses(default, null):Array<BonusConfig>;
private var brickMap:Map<Int, BrickConfig>;
private var brickMap:Map<BrickType, BrickConfig>;
private var brickMapByIndex:Map<Int, BrickConfig>;
private var tankMap:Map<TankType, TankConfig>;
private var presetsMap:Map<PresetId, GamePreset>;
private var bonusMap:Map<BonusType, BonusConfig>;
@@ -125,8 +127,10 @@ class Config {
private function init() {
brickMap = new Map();
brickMapByIndex = new Map();
for (item in bricks) {
brickMap.set(item.type, item);
brickMapByIndex.set(item.index, item);
}
presetsMap = new Map();
for (preset in presets) {
@@ -142,10 +146,14 @@ class Config {
}
}
public function getBrick(type:Int):BrickConfig {
public function getBrick(type:BrickType):BrickConfig {
return brickMap.get(type);
}
public function getBrickByIndex(index:Int):BrickConfig {
return brickMapByIndex.get(index);
}
public function getPreset(id:PresetId):GamePreset {
return presetsMap.get(id);
}

View File

@@ -26,7 +26,7 @@ class LevelBundle {
for (line in ~/\s+/g.split(data)) {
for (c in line.split('')) {
if (c.length > 0) {
bricks.push(config.getBrick(Std.parseInt(c)));
bricks.push(config.getBrickByIndex(Std.parseInt(c)));
}
}
}
@@ -41,7 +41,7 @@ class LevelBundle {
} else {
var obj:LevelSource = Yaml.parse(data, Parser.options().useObjects());
return {
data: obj.data.split('').map(function(c) return config.getBrick(Std.parseInt(c))),
data: obj.data.split('').map(function(c) return config.getBrickByIndex(Std.parseInt(c))),
points: obj.points,
}
}

View File

@@ -24,8 +24,8 @@ class Team {
this.spawner = new Spawner(config, points);
}
public function trySpawn(player:PlayerId, spawn:Bool = false):Bool {
var player:Player = players[player.index];
public function trySpawn(playerId:PlayerId, spawn:Bool = false):Bool {
var player:Player = players[playerId.index];
var result = false;
if (player.life > -1) {
if (player.life > 0) {

View File

@@ -9,12 +9,6 @@ import ru.m.tankz.core.IKey;
class Brick implements IKey {
public static var BORDER:BrickConfig = {
type: -1,
layer: 2,
armor: -1,
}
public var cellX(default, null):Int;
public var cellY(default, null):Int;
public var key(get, null):String;