diff --git a/WORK.md b/WORK.md index ba7461a..1bd9d7f 100644 --- a/WORK.md +++ b/WORK.md @@ -11,12 +11,8 @@ * A star * game config validate * additional weapon - * mine * display count * bonus ammo * screen gamepad (button enabled, count label) * ui: * game frame layouts -* fix: - * ice brick fix - * shot delay diff --git a/src/client/haxe/ru/m/tankz/AppTheme.hx b/src/client/haxe/ru/m/tankz/AppTheme.hx index f24d65f..ce3a6bc 100644 --- a/src/client/haxe/ru/m/tankz/AppTheme.hx +++ b/src/client/haxe/ru/m/tankz/AppTheme.hx @@ -122,16 +122,22 @@ class AppTheme extends Theme { var red:Color = 0xff0000; register(new Style("result.winner", [ "skin.border.color" => green, + "skin.border.alpha" => 0.5, + "skin.border.thickness" => 5, + "skin.round" => 10, ], ["light"])); register(new Style("result.loser", [ "skin.border.color" => red, + "skin.border.alpha" => 0.5, + "skin.border.thickness" => 5, + "skin.round" => 10, ], ["light"])); register(new Style("player.winner", [ - "skin.background.alpha" => 0.1, + "skin.background.alpha" => 0.2, "skin.background.color" => green, ])); register(new Style("player.loser", [ - "skin.background.alpha" => 0.1, + "skin.background.alpha" => 0.2, "skin.background.color" => red, ])); diff --git a/src/client/haxe/ru/m/tankz/control/HumanControl.hx b/src/client/haxe/ru/m/tankz/control/HumanControl.hx index ca99dbd..0746fbe 100644 --- a/src/client/haxe/ru/m/tankz/control/HumanControl.hx +++ b/src/client/haxe/ru/m/tankz/control/HumanControl.hx @@ -81,7 +81,8 @@ class HumanControl extends Control { case TankAction.SHOT(weapon): if (on) { if (!shotTimers.exists(weapon)) { - var timer = new Timer(300); + // ToDo: weapon.config.delay + var timer = new Timer(350); timer.run = shooter(weapon); timer.run(); shotTimers.set(weapon, timer); diff --git a/src/client/haxe/ru/m/tankz/render/Render.hx b/src/client/haxe/ru/m/tankz/render/Render.hx index 730104f..61b1ad6 100755 --- a/src/client/haxe/ru/m/tankz/render/Render.hx +++ b/src/client/haxe/ru/m/tankz/render/Render.hx @@ -150,8 +150,10 @@ class Render extends SpriteView implements IRender { entryLayer.addChild(item.view); item.update(); playAnimate(item.rect.center, AnimateBundle.tankSpawn()); - case SPAWN(BULLET(id, rect, playerId, skin)): - var item = new BulletRenderItem(rect, skin); + case SPAWN(BULLET(id, rect, playerId, skin, color)): + var item = new BulletRenderItem(rect); + item.color = color; + item.skin = skin; items.set(id, item); entryLayer.addChild(item.view); item.update(); diff --git a/src/client/haxe/ru/m/tankz/render/item/BulletRenderItem.hx b/src/client/haxe/ru/m/tankz/render/item/BulletRenderItem.hx index d637575..ebd6048 100644 --- a/src/client/haxe/ru/m/tankz/render/item/BulletRenderItem.hx +++ b/src/client/haxe/ru/m/tankz/render/item/BulletRenderItem.hx @@ -1,20 +1,26 @@ package ru.m.tankz.render.item; +import haxework.color.Color; +import haxework.view.utils.BitmapUtil; import ru.m.geom.Rectangle; class BulletRenderItem extends BitmapRenderItem { + public var color(default, default):Null; public var skin(default, set):String; - public function new(rect:Rectangle, skin:String) { + public function new(rect:Rectangle) { super(rect); - this.skin = skin; move(rect.position); } private function set_skin(value:String):String { if (skin != value) { skin = value; - image = RenderUtil.bulletImage(skin); + var image = RenderUtil.bulletImage(skin); + if (color != null) { + image = BitmapUtil.colorize(image, color); + } + this.image = image; } return skin; } diff --git a/src/client/resources/image/bullet/mine.png b/src/client/resources/image/bullet/mine.png index 2de8cc4..97d99e9 100644 Binary files a/src/client/resources/image/bullet/mine.png and b/src/client/resources/image/bullet/mine.png differ diff --git a/src/common/haxe/ru/m/geom/Rectangle.hx b/src/common/haxe/ru/m/geom/Rectangle.hx index 468a7e6..66fe0f8 100644 --- a/src/common/haxe/ru/m/geom/Rectangle.hx +++ b/src/common/haxe/ru/m/geom/Rectangle.hx @@ -113,7 +113,8 @@ abstract Rectangle(Array) { } public function intersection2(line:Line):Bool { - return contain(line.point1) || contain(line.point2); + // ToDo: line to rect? + return contain(line.point1) || contain(line.point2) || contain(line.center); } public function lean(rect:Rectangle):Void { diff --git a/src/common/haxe/ru/m/tankz/config/Config.hx b/src/common/haxe/ru/m/tankz/config/Config.hx index cfbc6d5..e697fcd 100644 --- a/src/common/haxe/ru/m/tankz/config/Config.hx +++ b/src/common/haxe/ru/m/tankz/config/Config.hx @@ -55,6 +55,7 @@ typedef WeaponConfig = { var bullet:BulletConfig; var count:Int; var queue:Int; + var delay:Int; } typedef TankConfig = { diff --git a/src/common/haxe/ru/m/tankz/core/Bullet.hx b/src/common/haxe/ru/m/tankz/core/Bullet.hx index 2485c86..626202a 100644 --- a/src/common/haxe/ru/m/tankz/core/Bullet.hx +++ b/src/common/haxe/ru/m/tankz/core/Bullet.hx @@ -1,5 +1,6 @@ package ru.m.tankz.core; +import haxework.color.Color; import ru.m.geom.Direction; import ru.m.geom.Rectangle; import ru.m.tankz.config.Config; @@ -11,6 +12,7 @@ class Bullet extends MobileEntity { public var tank(default, default):Tank; public var weapon(default, default):Weapon; public var config(default, null):BulletConfig; + public var color(default, default):Color; public function new(id:Int, rect:Rectangle, playerId:PlayerId, config:BulletConfig) { super(id, rect, config.speed, Direction.RIGHT); diff --git a/src/common/haxe/ru/m/tankz/core/Tank.hx b/src/common/haxe/ru/m/tankz/core/Tank.hx index 6e70cf1..67ab59b 100755 --- a/src/common/haxe/ru/m/tankz/core/Tank.hx +++ b/src/common/haxe/ru/m/tankz/core/Tank.hx @@ -4,7 +4,6 @@ import haxework.color.Color; import ru.m.geom.Direction; import ru.m.geom.Rectangle; import ru.m.tankz.config.Config; -import ru.m.tankz.game.GameEvent; import ru.m.tankz.Type; class Tank extends MobileEntity { diff --git a/src/common/haxe/ru/m/tankz/core/Weapon.hx b/src/common/haxe/ru/m/tankz/core/Weapon.hx index 5f9b204..da753b2 100644 --- a/src/common/haxe/ru/m/tankz/core/Weapon.hx +++ b/src/common/haxe/ru/m/tankz/core/Weapon.hx @@ -1,5 +1,6 @@ package ru.m.tankz.core; +import ru.m.tankz.engine.ITicker; import ru.m.tankz.config.Config; class Weapon { @@ -9,21 +10,29 @@ class Weapon { public var queue(default, default):Int; public var available(get, null):Bool; + private var lastShotTime:Int; + public function new(config:WeaponConfig) { this.config = config; this.count = this.config.count; this.queue = 0; + this.lastShotTime = 0; } private function get_available():Bool { return (count < 0 || count > 0) && (config.queue < 0 || queue < config.queue); } - public function use():Void { - queue++; - if (count > 0) { - count--; + public function use(ticker:ITicker):Bool { + if (available && ticker.time > lastShotTime + config.delay) { + lastShotTime = ticker.time; + queue++; + if (count > 0) { + count--; + } + return true; } + return false; } public function release():Void { diff --git a/src/common/haxe/ru/m/tankz/engine/Engine.hx b/src/common/haxe/ru/m/tankz/engine/Engine.hx index 464adf8..b03c594 100755 --- a/src/common/haxe/ru/m/tankz/engine/Engine.hx +++ b/src/common/haxe/ru/m/tankz/engine/Engine.hx @@ -56,6 +56,7 @@ import ru.m.tankz.map.LevelMap; public function move(entityId:Int, direction:Direction):Void { if (entities.exists(entityId)) { + ticker.cancel('slide.tank.${entityId}'); cast(entities.get(entityId), MobileEntity).move(direction); } } diff --git a/src/common/haxe/ru/m/tankz/game/EventUtil.hx b/src/common/haxe/ru/m/tankz/game/EventUtil.hx index e1e8587..6dbea7b 100644 --- a/src/common/haxe/ru/m/tankz/game/EventUtil.hx +++ b/src/common/haxe/ru/m/tankz/game/EventUtil.hx @@ -50,7 +50,7 @@ class EventUtil { } public static function buildBulletSpawn(bullet:Bullet):GameEvent { - return SPAWN(BULLET(bullet.id, bullet.rect.clone(), bullet.playerId, bullet.config.skin)); + return SPAWN(BULLET(bullet.id, bullet.rect.clone(), bullet.playerId, bullet.config.skin, bullet.color)); } public static function buildMove(entity:Entity):GameEvent { diff --git a/src/common/haxe/ru/m/tankz/game/GameEvent.hx b/src/common/haxe/ru/m/tankz/game/GameEvent.hx index f7b6dea..b9ac393 100644 --- a/src/common/haxe/ru/m/tankz/game/GameEvent.hx +++ b/src/common/haxe/ru/m/tankz/game/GameEvent.hx @@ -1,5 +1,6 @@ package ru.m.tankz.game; +import haxework.color.Color; import ru.m.geom.Position; import ru.m.geom.Rectangle; import ru.m.tankz.config.Config; @@ -29,7 +30,7 @@ enum SpawnEvent { BRICK(bricks:Array); EAGLE(id:Int, rect:Rectangle, teamId:TeamId); TANK(id:Int, rect:Rectangle, playerId:PlayerId, info:TankInfo); - BULLET(id:Int, rect:Rectangle, playerId:PlayerId, skin:String); + BULLET(id:Int, rect:Rectangle, playerId:PlayerId, skin:String, color:Color); BONUS(id:Int, rect:Rectangle, type:BonusType); } diff --git a/src/common/haxe/ru/m/tankz/game/GameRunner.hx b/src/common/haxe/ru/m/tankz/game/GameRunner.hx index bda1a54..8344f5e 100644 --- a/src/common/haxe/ru/m/tankz/game/GameRunner.hx +++ b/src/common/haxe/ru/m/tankz/game/GameRunner.hx @@ -283,16 +283,22 @@ class GameRunner extends Game implements EngineListener { case ACTION(tankId, SHOT(index)): var tank:Tank = cast engine.entities.get(tankId); var player = getPlayer(tank.playerId); - var weapon:Weapon = tank.weapons.length > index - 1 ? tank.weapons[index] : null; - if (weapon != null && !tank.freezing && weapon.available) { - var rect = tank.rect; - var point = rect.center.add(new Point(rect.width / 4 * rect.direction.x, rect.height / 4 * rect.direction.y)); - var bullet = builder.buildBullet(point, rect.direction, player.id, weapon.config.bullet); - bullet.tank = tank; - bullet.weapon = weapon; - bullet.move(bullet.rect.direction); - engine.spawn(bullet); - gameEventSignal.emit(EventUtil.buildBulletSpawn(bullet)); + if (!tank.freezing) { + var weapon:Weapon = tank.weapons.length > index - 1 ? tank.weapons[index] : null; + if (weapon != null && weapon.use(ticker)) { + var rect = tank.rect; + var point = rect.center.add(new Point(rect.width / 4 * rect.direction.x, rect.height / 4 * rect.direction.y)); + var bullet = builder.buildBullet(point, rect.direction, player.id, weapon.config.bullet); + // ToDo: mine color + if (bullet.config.skin == "mine") { + bullet.color = config.getColor(player.id); + } + bullet.tank = tank; + bullet.weapon = weapon; + bullet.move(bullet.rect.direction); + engine.spawn(bullet); + gameEventSignal.emit(EventUtil.buildBulletSpawn(bullet)); + } } case ACTION(tankId, MOVE(direction)): engine.move(tankId, direction); @@ -305,9 +311,6 @@ class GameRunner extends Game implements EngineListener { var player = getPlayer(playerId); player.tankId = id; player.state.tank = info; - case SPAWN(BULLET(id, _, _, _)): - var bullet:Bullet = engine.getEntity(id); - bullet.weapon.use(); case CHANGE(BRICK(id, type)): engine.map.bricksById[id].config = config.getBrick(type); case CHANGE(TANK(id, type, hits, bonus, boat)): diff --git a/src/common/resources/config/classic.yaml b/src/common/resources/config/classic.yaml index 521962e..d2d1be9 100644 --- a/src/common/resources/config/classic.yaml +++ b/src/common/resources/config/classic.yaml @@ -71,6 +71,7 @@ tanks: - bullet: {<<: *bullet, speed: 8.0} queue: 1 count: -1 + delay: 300 - type: human1 upgrade: human2 @@ -83,6 +84,7 @@ tanks: - bullet: {<<: *bullet, speed: 8.5} queue: 1 count: -1 + delay: 300 - type: human2 upgrade: human3 @@ -94,6 +96,7 @@ tanks: - bullet: {<<: *bullet, speed: 9.0} queue: 2 count: -1 + delay: 300 - type: human3 downgrade: human2 @@ -105,6 +108,7 @@ tanks: - bullet: {<<: *bullet, speed: 9.0, piercing: 3, skin: piercing} queue: 2 count: -1 + delay: 300 - type: bot0 width: 38 @@ -116,6 +120,7 @@ tanks: - bullet: {<<: *bullet, speed: 7.0} queue: 1 count: -1 + delay: 300 - type: bot1 width: 40 @@ -127,6 +132,7 @@ tanks: - bullet: {<<: *bullet, speed: 7.0} queue: 1 count: -1 + delay: 300 - type: bot2 width: 38 @@ -138,6 +144,7 @@ tanks: - bullet: {<<: *bullet, speed: 9.0} queue: 1 count: -1 + delay: 300 - type: bot3 width: 40 @@ -150,6 +157,7 @@ tanks: - bullet: {<<: *bullet, speed: 8.0} queue: 1 count: -1 + delay: 300 bonuses: - {score: 500, factory: freeze.team, type: clock, duration: 10} diff --git a/src/common/resources/config/death.yaml b/src/common/resources/config/death.yaml index 1f9559a..f0e2a5f 100644 --- a/src/common/resources/config/death.yaml +++ b/src/common/resources/config/death.yaml @@ -81,11 +81,14 @@ tanks: - bullet: {width: 12, height: 12, speed: 12.0, piercing: 1, layer: 2, skin: normal} queue: 2 count: -1 + delay: 300 - bullet: {width: 16, height: 16, speed: 4.0, piercing: 4, layer: 4, skin: rocket} queue: 1 count: 3 + delay: 300 - bullet: {width: 20, height: 20, speed: 0.0, piercing: 1, layer: 0, skin: mine} queue: -1 count: 3 + delay: 300 bonuses: [] diff --git a/src/common/resources/config/dota.yaml b/src/common/resources/config/dota.yaml index 8c117cc..79dd83a 100644 --- a/src/common/resources/config/dota.yaml +++ b/src/common/resources/config/dota.yaml @@ -97,6 +97,7 @@ tanks: - bullet: {<<: *bullet, speed: 12.0} queue: 1 count: -1 + delay: 300 - type: fast width: 40 @@ -108,6 +109,7 @@ tanks: - bullet: {<<: *bullet, speed: 8.0} queue: 1 count: -1 + delay: 300 bonuses: - {score: 100, factory: freeze.team, type: clock, duration: 10}