diff --git a/src/client/haxe/ru/m/draw/BitmapUtil.hx b/src/client/haxe/ru/m/draw/BitmapUtil.hx index f112f48..a29ae45 100644 --- a/src/client/haxe/ru/m/draw/BitmapUtil.hx +++ b/src/client/haxe/ru/m/draw/BitmapUtil.hx @@ -8,8 +8,9 @@ import flash.display.BitmapData; class BitmapUtil { public static function colorize(data: BitmapData, color: Color):BitmapData { + if (color.zero) return data; var result = data.clone(); - var transform = new ColorTransform(1, 1, 1, 1, color.red, color.green, color.blue, color.alpha); + var transform = new ColorTransform(color.red / 255, color.green / 255, color.blue / 255, 1, 0, 0, 0, 0); result.colorTransform(new Rectangle(0, 0, result.width, result.height), transform); return result; } diff --git a/src/client/haxe/ru/m/draw/Color.hx b/src/client/haxe/ru/m/draw/Color.hx index 7f4a352..da7ee6c 100644 --- a/src/client/haxe/ru/m/draw/Color.hx +++ b/src/client/haxe/ru/m/draw/Color.hx @@ -5,6 +5,7 @@ abstract Color(Int) { public var red(get, never):Int; public var green(get, never):Int; public var blue(get, never):Int; + public var zero(get, never):Bool; public inline function new(value:Int) { this = value; @@ -26,6 +27,15 @@ abstract Color(Int) { return this & 255; } + private inline function get_zero():Bool { + return this == 0; + } + + @:from + static public inline function fromInt(value:Int):Color { + return new Color(value); + } + @:from static public inline function fromString(value:String):Color { return new Color(Std.parseInt('0x${value.split('#').pop()}')); diff --git a/src/client/haxe/ru/m/tankz/render/RenderItem.hx b/src/client/haxe/ru/m/tankz/render/RenderItem.hx index 772598c..31d5bc9 100644 --- a/src/client/haxe/ru/m/tankz/render/RenderItem.hx +++ b/src/client/haxe/ru/m/tankz/render/RenderItem.hx @@ -155,32 +155,14 @@ class TankItem extends RenderItem { } override public function redraw():Void { - // ToDo: ImageBundle - tankView.frames = getFrames().map(function(s) return BitmapUtil.colorize(Assets.getBitmapData(s), '#cc0000')); - } - - public static function getTankFrames(team:TeamId, index:Int, type:TankType, hits:Int=0):Array { - var group = type.group; - if (team == 'radiant') { - index = 0; - } - if (team == 'dire') { - index = 1; - } - if (team == 'human' || team == 'radiant' || team == 'dire') { - group = 'player'; - } - if (team == 'bot') { - index = hits; - } - return [ - 'resources/images/tank/${group}/tank_${group.charAt(0)}${type.type}_${index}-0.png', - 'resources/images/tank/${group}/tank_${group.charAt(0)}${type.type}_${index}-1.png', - ]; + tankView.frames = getFrames().map(function(src) return BitmapUtil.colorize(Assets.getBitmapData(src), value.color)); } private function getFrames():Array { - return getTankFrames(value.playerId.team, value.playerId.index, value.config, value.hits); + return [ + 'resources/image/tank/${value.config.skin}-0.png', + 'resources/image/tank/${value.config.skin}-1.png', + ]; } override public function update():Void { diff --git a/src/client/resources/classic/config.yaml b/src/client/resources/classic/config.yaml index 0a7dc05..5d0c9d4 100644 --- a/src/client/resources/classic/config.yaml +++ b/src/client/resources/classic/config.yaml @@ -19,7 +19,6 @@ bricks: teams: - id: human - spawnInterval: 0 tanks: - {group: human, type: 0, rate: 1} - id: bot @@ -54,6 +53,7 @@ tanks: <<: *bullet speed: 8.0 bullets: 1 + skin: pa - type: 1 width: 40 @@ -63,6 +63,7 @@ tanks: <<: *bullet speed: 8.5 bullets: 1 + skin: pb - type: 2 width: 40 @@ -72,6 +73,7 @@ tanks: <<: *bullet speed: 9.0 bullets: 2 + skin: pc - type: 3 width: 42 @@ -82,6 +84,8 @@ tanks: speed: 9.0 piercing: 3 bullets: 2 + hits: 1 + skin: pd bot: - type: 0 @@ -93,6 +97,7 @@ tanks: speed: 7.0 bullets: 1 score: 100 + skin: ba - type: 1 width: 40 @@ -103,6 +108,7 @@ tanks: speed: 7.0 bullets: 1 score: 200 + skin: bb - type: 2 width: 38 @@ -113,6 +119,7 @@ tanks: speed: 9.0 bullets: 1 score: 300 + skin: bc - type: 3 width: 40 @@ -124,3 +131,4 @@ tanks: bullets: 1 score: 400 hits: 3 + skin: bd diff --git a/src/client/resources/dota/config.yaml b/src/client/resources/dota/config.yaml index f5dd432..5fb237b 100644 --- a/src/client/resources/dota/config.yaml +++ b/src/client/resources/dota/config.yaml @@ -19,17 +19,16 @@ bricks: team_tanks: &team_tanks tanks: - - {group: any, type: 0, rate: 0.25} - - {group: any, type: 1, rate: 0.25} - - {group: any, type: 2, rate: 0.25} + - {group: any, type: 0, rate: 0.5} + - {group: any, type: 1, rate: 0.5} teams: - <<: *team_tanks id: radiant - spawnInterval: 0 + color: 0xff5555 - <<: *team_tanks id: dire - spawnInterval: 0 + color: 0x5555ff points: - {team: radiant, type: eagle, index: -1, direction: right, x: 0, y: 28} @@ -54,38 +53,21 @@ bullet: &bullet tanks: any: - type: 0 - width: 36 + width: 38 height: 36 - speed: 2.5 + speed: 2.0 bullet: <<: *bullet - speed: 8.0 + speed: 10.0 bullets: 1 + skin: bc - type: 1 width: 40 height: 36 - speed: 3.0 + speed: 4.0 bullet: <<: *bullet - speed: 8.5 + speed: 7.0 bullets: 1 - - - type: 2 - width: 40 - height: 36 - speed: 3.0 - bullet: - <<: *bullet - speed: 9.0 - bullets: 2 - - - type: 3 - width: 42 - height: 38 - speed: 2.9 - bullet: - <<: *bullet - speed: 9.0 - piercing: 3 - bullets: 2 \ No newline at end of file + skin: bb diff --git a/src/client/resources/image/tank/ba-0.png b/src/client/resources/image/tank/ba-0.png new file mode 100644 index 0000000..51192e5 Binary files /dev/null and b/src/client/resources/image/tank/ba-0.png differ diff --git a/src/client/resources/image/tank/ba-1.png b/src/client/resources/image/tank/ba-1.png new file mode 100644 index 0000000..a86501b Binary files /dev/null and b/src/client/resources/image/tank/ba-1.png differ diff --git a/src/client/resources/image/tank/bb-0.png b/src/client/resources/image/tank/bb-0.png new file mode 100644 index 0000000..7bf3b5f Binary files /dev/null and b/src/client/resources/image/tank/bb-0.png differ diff --git a/src/client/resources/image/tank/bb-1.png b/src/client/resources/image/tank/bb-1.png new file mode 100644 index 0000000..f3648cb Binary files /dev/null and b/src/client/resources/image/tank/bb-1.png differ diff --git a/src/client/resources/image/tank/bc-0.png b/src/client/resources/image/tank/bc-0.png new file mode 100644 index 0000000..7c4b37c Binary files /dev/null and b/src/client/resources/image/tank/bc-0.png differ diff --git a/src/client/resources/image/tank/bc-1.png b/src/client/resources/image/tank/bc-1.png new file mode 100644 index 0000000..5eae1c7 Binary files /dev/null and b/src/client/resources/image/tank/bc-1.png differ diff --git a/src/client/resources/image/tank/bd-0.png b/src/client/resources/image/tank/bd-0.png new file mode 100644 index 0000000..a1bcb78 Binary files /dev/null and b/src/client/resources/image/tank/bd-0.png differ diff --git a/src/client/resources/image/tank/bd-1.png b/src/client/resources/image/tank/bd-1.png new file mode 100644 index 0000000..cd2a683 Binary files /dev/null and b/src/client/resources/image/tank/bd-1.png differ diff --git a/src/client/resources/image/tank/pa-0.png b/src/client/resources/image/tank/pa-0.png new file mode 100644 index 0000000..9c8bd0e Binary files /dev/null and b/src/client/resources/image/tank/pa-0.png differ diff --git a/src/client/resources/image/tank/pa-1.png b/src/client/resources/image/tank/pa-1.png new file mode 100644 index 0000000..edf381c Binary files /dev/null and b/src/client/resources/image/tank/pa-1.png differ diff --git a/src/client/resources/image/tank/pb-0.png b/src/client/resources/image/tank/pb-0.png new file mode 100644 index 0000000..6f9d3e2 Binary files /dev/null and b/src/client/resources/image/tank/pb-0.png differ diff --git a/src/client/resources/image/tank/pb-1.png b/src/client/resources/image/tank/pb-1.png new file mode 100644 index 0000000..a19cd03 Binary files /dev/null and b/src/client/resources/image/tank/pb-1.png differ diff --git a/src/client/resources/image/tank/pc-0.png b/src/client/resources/image/tank/pc-0.png new file mode 100644 index 0000000..fb0887c Binary files /dev/null and b/src/client/resources/image/tank/pc-0.png differ diff --git a/src/client/resources/image/tank/pc-1.png b/src/client/resources/image/tank/pc-1.png new file mode 100644 index 0000000..e874352 Binary files /dev/null and b/src/client/resources/image/tank/pc-1.png differ diff --git a/src/client/resources/image/tank/pd-0.png b/src/client/resources/image/tank/pd-0.png new file mode 100644 index 0000000..64d6086 Binary files /dev/null and b/src/client/resources/image/tank/pd-0.png differ diff --git a/src/client/resources/image/tank/pd-1.png b/src/client/resources/image/tank/pd-1.png new file mode 100644 index 0000000..66b82df Binary files /dev/null and b/src/client/resources/image/tank/pd-1.png differ diff --git a/src/common/haxe/ru/m/tankz/config/Config.hx b/src/common/haxe/ru/m/tankz/config/Config.hx index df79144..adc77fd 100644 --- a/src/common/haxe/ru/m/tankz/config/Config.hx +++ b/src/common/haxe/ru/m/tankz/config/Config.hx @@ -1,5 +1,7 @@ package ru.m.tankz.config; +import ru.m.draw.Color; + typedef GameConfig = { var levels: Int; @@ -48,6 +50,7 @@ typedef TankConfig = { > TankType, var bullet:BulletConfig; var bullets:Int; var hits:Int; + var skin:String; } typedef TankSpawn = { > TankType, @@ -58,8 +61,9 @@ typedef TankSpawn = { > TankType, typedef TeamConfig = { var id:String; var size:Int; - var spawnInterval:Int; var tanks:Array; + @:optional var spawnInterval:Int; + @:optional var color:Color; } diff --git a/src/common/haxe/ru/m/tankz/core/Tank.hx b/src/common/haxe/ru/m/tankz/core/Tank.hx index 5e4740b..f5a7e62 100755 --- a/src/common/haxe/ru/m/tankz/core/Tank.hx +++ b/src/common/haxe/ru/m/tankz/core/Tank.hx @@ -1,5 +1,6 @@ package ru.m.tankz.core; +import ru.m.draw.Color; import ru.m.tankz.game.Game; import ru.m.geom.Point; import ru.m.tankz.config.Config; @@ -11,6 +12,7 @@ import ru.m.geom.Direction; class Tank extends MobileEntity { public var playerId(default, null):PlayerId; public var config(default, set):TankConfig; + public var color(default, default):Color; public var hits(default, default):Int; private var bulletsCounter:Int = 0; diff --git a/src/common/haxe/ru/m/tankz/game/ClassicGame.hx b/src/common/haxe/ru/m/tankz/game/ClassicGame.hx index befb39f..9a6e5d5 100644 --- a/src/common/haxe/ru/m/tankz/game/ClassicGame.hx +++ b/src/common/haxe/ru/m/tankz/game/ClassicGame.hx @@ -1,5 +1,6 @@ package ru.m.tankz.game; +import ru.m.draw.Color; import ru.m.tankz.control.Control; import haxe.ds.Option; import ru.m.tankz.game.GameState.PlayerState; @@ -13,8 +14,16 @@ class ClassicGame extends Game { public static var HUMAN(default, never):TeamId = 'human'; public static var BOT(default, never):TeamId = 'bot'; - public static var PLAYER1(default, never):GameMode = [{team:HUMAN, type:Control.HUMAN, index:0}]; - public static var PLAYER2(default, never):GameMode = [{team:HUMAN, type:Control.HUMAN, index:0}, {team:HUMAN, type:Control.HUMAN, index:1}]; + private static var PLAYER1_COLOR:Color = 0xffff55; + private static var PLAYER2_COLOR:Color = 0x00ff00; + + public static var PLAYER1(default, never):GameMode = [ + {team:HUMAN, type:Control.HUMAN, color: PLAYER1_COLOR, index:0} + ]; + public static var PLAYER2(default, never):GameMode = [ + {team:HUMAN, type:Control.HUMAN, color: PLAYER1_COLOR, index:0}, + {team:HUMAN, type:Control.HUMAN, color: PLAYER2_COLOR, index:1} + ]; private static var HUMAN_LIFE(default, never):Int = 3; private static var BOT_LIFE(default, never):Int = 20; diff --git a/src/common/haxe/ru/m/tankz/game/DotaGame.hx b/src/common/haxe/ru/m/tankz/game/DotaGame.hx index 6ecd06f..19440f5 100644 --- a/src/common/haxe/ru/m/tankz/game/DotaGame.hx +++ b/src/common/haxe/ru/m/tankz/game/DotaGame.hx @@ -1,5 +1,6 @@ package ru.m.tankz.game; +import ru.m.draw.Color; import ru.m.tankz.control.Control; import haxe.ds.Option; import ru.m.tankz.game.Game; @@ -17,14 +18,17 @@ class DotaGame extends Game { {team:RADIANT, type:Control.HUMAN, index:0} ]; + private static var PLAYER1_COLOR:Color = 0xff7777; + private static var PLAYER2_COLOR:Color = 0x7777ff; + public static var PLAYER2_COOP(default, never):GameMode = [ - {team:RADIANT, type:Control.HUMAN, index:0}, - {team:RADIANT, type:Control.HUMAN, index:1} + {team:RADIANT, type:Control.HUMAN, color: PLAYER1_COLOR, index:0}, + {team:RADIANT, type:Control.HUMAN, color: PLAYER1_COLOR, index:1} ]; public static var PLAYER2_VS(default, never):GameMode = [ - {team:RADIANT, type:Control.HUMAN, index:0}, - {team:DIRE, type:Control.HUMAN, index:0} + {team:RADIANT, type:Control.HUMAN, color: PLAYER1_COLOR, index:0}, + {team:DIRE, type:Control.HUMAN, color: PLAYER2_COLOR, index:0} ]; private static var TEAM_SIZE(default, never):Int = 5; diff --git a/src/common/haxe/ru/m/tankz/game/Game.hx b/src/common/haxe/ru/m/tankz/game/Game.hx index 2ccd4fd..775e8a8 100644 --- a/src/common/haxe/ru/m/tankz/game/Game.hx +++ b/src/common/haxe/ru/m/tankz/game/Game.hx @@ -1,5 +1,6 @@ package ru.m.tankz.game; +import ru.m.draw.Color; import haxe.ds.Option; import haxe.Timer; import promhx.Deferred; @@ -31,6 +32,7 @@ typedef PlayerId = { var team:TeamId; var type:ControlType; var index:Int; + @:optional var color:Color; } @@ -65,6 +67,7 @@ class Game implements EngineListener { var type:TankSpawn = types[Math.floor(Math.random() * types.length)]; var tankConfig:TankConfig = config.getTank(type.group, type.type); var tank = new Tank(playerId, tankConfig); + tank.color = playerId.color.zero ? teams[playerId.team].config.color : playerId.color; applyPoint(tank, point); return tank; }