diff --git a/src/client/haxe/ru/m/animate/Animate.hx b/src/client/haxe/ru/m/animate/Animate.hx index 3db9430..6cb4c0e 100644 --- a/src/client/haxe/ru/m/animate/Animate.hx +++ b/src/client/haxe/ru/m/animate/Animate.hx @@ -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; private var index:Int; diff --git a/src/client/haxe/ru/m/tankz/render/Render.hx b/src/client/haxe/ru/m/tankz/render/Render.hx index 03b93e0..a85eb21 100755 --- a/src/client/haxe/ru/m/tankz/render/Render.hx +++ b/src/client/haxe/ru/m/tankz/render/Render.hx @@ -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); - if (brick.config.layer > 2) { - upLayer.addChild(items[brick.key].view); - } else { - groundLayer.addChild(items[brick.key].view); + var item:RenderItem = 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(item.view); + } else { + groundLayer.addChild(item.view); + } } } } diff --git a/src/client/haxe/ru/m/tankz/render/RenderItem.hx b/src/client/haxe/ru/m/tankz/render/RenderItem.hx index cea12ce..7813868 100644 --- a/src/client/haxe/ru/m/tankz/render/RenderItem.hx +++ b/src/client/haxe/ru/m/tankz/render/RenderItem.hx @@ -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 extends RenderItem { } -class BrickItem extends RenderItem { +class BrickItem extends BitmapItem { + + 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 { + + 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 { 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 { 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 { } private function getImage():String { - return 'resources/images/map/map_${value.config.type}.png'; + return 'resources/image/map/${value.config.type}.png'; } } diff --git a/src/client/resources/classic/config.yaml b/src/client/resources/classic/config.yaml index 18845f2..6e2051b 100644 --- a/src/client/resources/classic/config.yaml +++ b/src/client/resources/classic/config.yaml @@ -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 diff --git a/src/client/resources/dota/config.yaml b/src/client/resources/dota/config.yaml index b3ba38c..5193237 100644 --- a/src/client/resources/dota/config.yaml +++ b/src/client/resources/dota/config.yaml @@ -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 diff --git a/src/client/resources/image/map/ace.png b/src/client/resources/image/map/ace.png new file mode 100644 index 0000000..df394b5 Binary files /dev/null and b/src/client/resources/image/map/ace.png differ diff --git a/src/client/resources/image/map/armor.png b/src/client/resources/image/map/armor.png new file mode 100644 index 0000000..16ecf69 Binary files /dev/null and b/src/client/resources/image/map/armor.png differ diff --git a/src/client/resources/image/map/brick.png b/src/client/resources/image/map/brick.png new file mode 100644 index 0000000..cc14732 Binary files /dev/null and b/src/client/resources/image/map/brick.png differ diff --git a/src/client/resources/image/map/bush.png b/src/client/resources/image/map/bush.png new file mode 100644 index 0000000..7f1615e Binary files /dev/null and b/src/client/resources/image/map/bush.png differ diff --git a/src/client/resources/image/map/none.png b/src/client/resources/image/map/none.png new file mode 100644 index 0000000..f133468 Binary files /dev/null and b/src/client/resources/image/map/none.png differ diff --git a/src/client/resources/image/map/water-0.png b/src/client/resources/image/map/water-0.png new file mode 100644 index 0000000..2151ef8 Binary files /dev/null and b/src/client/resources/image/map/water-0.png differ diff --git a/src/client/resources/image/map/water-1.png b/src/client/resources/image/map/water-1.png new file mode 100644 index 0000000..e8b3726 Binary files /dev/null and b/src/client/resources/image/map/water-1.png differ diff --git a/src/common/haxe/ru/m/tankz/Type.hx b/src/common/haxe/ru/m/tankz/Type.hx index c598298..31a03a1 100644 --- a/src/common/haxe/ru/m/tankz/Type.hx +++ b/src/common/haxe/ru/m/tankz/Type.hx @@ -9,7 +9,7 @@ typedef TeamId = String; typedef ControlType = String; -typedef BrickType = Int; +typedef BrickType = String; typedef TankType = String; diff --git a/src/common/haxe/ru/m/tankz/config/Config.hx b/src/common/haxe/ru/m/tankz/config/Config.hx index 9c0a630..d247251 100644 --- a/src/common/haxe/ru/m/tankz/config/Config.hx +++ b/src/common/haxe/ru/m/tankz/config/Config.hx @@ -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; public var bonuses(default, null):Array; - private var brickMap:Map; + private var brickMap:Map; + private var brickMapByIndex:Map; private var tankMap:Map; private var presetsMap:Map; private var bonusMap:Map; @@ -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); } diff --git a/src/common/haxe/ru/m/tankz/config/LevelBundle.hx b/src/common/haxe/ru/m/tankz/config/LevelBundle.hx index 067339f..02a1327 100644 --- a/src/common/haxe/ru/m/tankz/config/LevelBundle.hx +++ b/src/common/haxe/ru/m/tankz/config/LevelBundle.hx @@ -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, } } diff --git a/src/common/haxe/ru/m/tankz/game/Team.hx b/src/common/haxe/ru/m/tankz/game/Team.hx index bd2a2b3..70be402 100644 --- a/src/common/haxe/ru/m/tankz/game/Team.hx +++ b/src/common/haxe/ru/m/tankz/game/Team.hx @@ -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) { diff --git a/src/common/haxe/ru/m/tankz/map/Brick.hx b/src/common/haxe/ru/m/tankz/map/Brick.hx index d94fcd5..ea5daaf 100644 --- a/src/common/haxe/ru/m/tankz/map/Brick.hx +++ b/src/common/haxe/ru/m/tankz/map/Brick.hx @@ -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;