diff --git a/src/client/haxe/ru/m/tankz/frame/classic/ClassicGamePanel.hx b/src/client/haxe/ru/m/tankz/frame/classic/ClassicGamePanel.hx index d253288..0c8d922 100644 --- a/src/client/haxe/ru/m/tankz/frame/classic/ClassicGamePanel.hx +++ b/src/client/haxe/ru/m/tankz/frame/classic/ClassicGamePanel.hx @@ -15,15 +15,15 @@ import ru.m.tankz.preset.ClassicGame; public var game:Game; private function updateViews():Void { - bot.live.text = '${game.teams[ClassicGame.BOT].life}'; - player1.live.text = '${game.teams[ClassicGame.HUMAN].players[0].state.life}'; - player1.score.text = '${game.teams[ClassicGame.HUMAN].players[0].state.score}'; + bot.live = game.teams[ClassicGame.BOT].life; + player1.live = game.teams[ClassicGame.HUMAN].players[0].state.life; + player1.score = game.teams[ClassicGame.HUMAN].players[0].state.score; if (game.teams[ClassicGame.HUMAN].players[1] != null) { - player2.live.text = '${game.teams[ClassicGame.HUMAN].players[1].state.life}'; - player2.score.text = '${game.teams[ClassicGame.HUMAN].players[1].state.score}'; + player2.visible = true; + player2.live = game.teams[ClassicGame.HUMAN].players[1].state.life; + player2.score = game.teams[ClassicGame.HUMAN].players[1].state.score; } else { - player2.live.text = ""; - player2.score.text = ""; + player2.visible = false; } } diff --git a/src/client/haxe/ru/m/tankz/frame/classic/ClassicGamePanel.yaml b/src/client/haxe/ru/m/tankz/frame/classic/ClassicGamePanel.yaml index 3f2545d..9e8012c 100644 --- a/src/client/haxe/ru/m/tankz/frame/classic/ClassicGamePanel.yaml +++ b/src/client/haxe/ru/m/tankz/frame/classic/ClassicGamePanel.yaml @@ -5,12 +5,13 @@ layout.hAlign: right views: - id: bot $type: ru.m.tankz.frame.common.LifeView - image.image: $asset:image:resources/image/tank/ba-0.png + tank: ba + scoreLabel.visible: false - id: player1 $type: ru.m.tankz.frame.common.LifeView - image.image: $asset:image:resources/image/tank/pa-0.png - image.color: 0xFFFF00 + tank: pa + color: 0xFFFF00 - id: player2 $type: ru.m.tankz.frame.common.LifeView - image.image: $asset:image:resources/image/tank/pa-0.png - image.color: 0x15C040 + tank: pa + color: 0x15C040 diff --git a/src/client/haxe/ru/m/tankz/frame/common/LifeView.hx b/src/client/haxe/ru/m/tankz/frame/common/LifeView.hx index 8457379..7b52486 100644 --- a/src/client/haxe/ru/m/tankz/frame/common/LifeView.hx +++ b/src/client/haxe/ru/m/tankz/frame/common/LifeView.hx @@ -1,11 +1,37 @@ package ru.m.tankz.frame.common; +import openfl.Assets; import haxework.gui.LabelView; import haxework.gui.ImageView; import haxework.gui.HGroupView; @:template class LifeView extends HGroupView { - @:view public var image:ImageView; - @:view public var live:LabelView; - @:view public var score:LabelView; + @:view("tank") public var tankImage:ImageView; + @:view("live") public var liveLabel:LabelView; + @:view("score") public var scoreLabel:LabelView; + + public var tank(null, set):String; + public var color(null, set):Int; + public var live(null, set):Int; + public var score(null, set):Int; + + private inline function set_tank(value:String):String { + tankImage.image = Assets.getBitmapData('resources/image/tank/${value}-0.png'); + return value; + } + + private inline function set_color(value:Int):Int { + tankImage.color = value; + return value; + } + + private inline function set_live(value:Int):Int { + liveLabel.text = 'x${value}'; + return value; + } + + private inline function set_score(value:Int):Int { + scoreLabel.text = '${value}$'; + return value; + } } diff --git a/src/client/haxe/ru/m/tankz/frame/common/LifeView.yaml b/src/client/haxe/ru/m/tankz/frame/common/LifeView.yaml index ab4d68c..55161fd 100644 --- a/src/client/haxe/ru/m/tankz/frame/common/LifeView.yaml +++ b/src/client/haxe/ru/m/tankz/frame/common/LifeView.yaml @@ -1,7 +1,7 @@ --- layout.margin: 5 views: - - id: image + - id: tank $type: haxework.gui.ImageView - id: live $type: haxework.gui.LabelView diff --git a/src/client/haxe/ru/m/tankz/frame/common/PlayerView.hx b/src/client/haxe/ru/m/tankz/frame/common/PlayerView.hx index 6a3bc37..aa00c12 100644 --- a/src/client/haxe/ru/m/tankz/frame/common/PlayerView.hx +++ b/src/client/haxe/ru/m/tankz/frame/common/PlayerView.hx @@ -1,12 +1,12 @@ package ru.m.tankz.frame.common; +import ru.m.tankz.control.Control; import haxework.gui.DataView; import haxework.gui.HGroupView; import haxework.gui.LabelView; import haxework.gui.skin.ISkin; import haxework.gui.ToggleButtonView; import ru.m.tankz.game.GameState; -import ru.m.tankz.Type.PlayerId; import ru.m.tankz.Type.TeamId; class TeamButton extends ToggleButtonView { @@ -44,13 +44,15 @@ class TeamSkin implements ISkin { private static inline var NONE:TeamId = "none"; public var item_index(default, set):Int; - public var data(default, set):PlayerState; + public var data(default, set):Array; @:view var label(default, null):LabelView; @:view var teams(default, null):DataView; @:provide var state:GameState; + private var player:PlayerState; + private function teamViewFactory(index:Int, team:TeamId) { var view = new TeamButton(); view.skin = [new TeamSkin(getTeamColor(team))]; @@ -60,7 +62,7 @@ class TeamSkin implements ISkin { return view; } - private function set_data(value:PlayerState):PlayerState { + private function set_data(value:Array):Array { data = value; teams.data = [NONE].concat([for (team in state.preset.teams) team.id]); return data; @@ -84,7 +86,17 @@ class TeamSkin implements ISkin { } private function onTeamSelect(team:TeamId) { - data.id = new PlayerId(team, item_index); + if (player != null) { + player.control = Control.BOT; + player = null; + } + for (p in data) { + if (p.id.team == team && p.control != Control.HUMAN) { + player = p; + player.control = Control.HUMAN; + break; + } + } for (view in teams.views) { var button = cast(view, TeamButton); button.on = team == button.team; diff --git a/src/client/haxe/ru/m/tankz/frame/dota/DotaGamePanel.hx b/src/client/haxe/ru/m/tankz/frame/dota/DotaGamePanel.hx index 713738b..64d650d 100644 --- a/src/client/haxe/ru/m/tankz/frame/dota/DotaGamePanel.hx +++ b/src/client/haxe/ru/m/tankz/frame/dota/DotaGamePanel.hx @@ -14,10 +14,10 @@ import ru.m.tankz.preset.DotaGame; public var game:Game; private function updateViews():Void { - radiant.live.text = '${game.teams[DotaGame.RADIANT].life}'; - radiant.score.text = '${game.teams[DotaGame.RADIANT].score}'; - dire.live.text = '${game.teams[DotaGame.DIRE].life}'; - dire.score.text = '${game.teams[DotaGame.DIRE].score}'; + radiant.live = game.teams[DotaGame.RADIANT].life; + radiant.score = game.teams[DotaGame.RADIANT].score; + dire.live = game.teams[DotaGame.DIRE].life; + dire.score = game.teams[DotaGame.DIRE].score; } override public function update():Void { diff --git a/src/client/haxe/ru/m/tankz/frame/dota/DotaGamePanel.yaml b/src/client/haxe/ru/m/tankz/frame/dota/DotaGamePanel.yaml index af3fca8..1d9d6fd 100644 --- a/src/client/haxe/ru/m/tankz/frame/dota/DotaGamePanel.yaml +++ b/src/client/haxe/ru/m/tankz/frame/dota/DotaGamePanel.yaml @@ -4,11 +4,11 @@ layout.margin: 20 views: - id: radiant $type: ru.m.tankz.frame.common.LifeView - image.image: $asset:image:resources/image/tank/bc-0.png - image.color: 0xff4422 + tank: bc + color: 0xff4422 - $type: haxework.gui.SpriteView geometry.size.width: 100% - id: dire $type: ru.m.tankz.frame.common.LifeView - image.image: $asset:image:resources/image/tank/bc-0.png - image.color: 0x3284ff + tank: bc + color: 0x3284ff diff --git a/src/client/haxe/ru/m/tankz/frame/dota/DotaLevelFrame.hx b/src/client/haxe/ru/m/tankz/frame/dota/DotaLevelFrame.hx index 704e1da..ff9dd7e 100644 --- a/src/client/haxe/ru/m/tankz/frame/dota/DotaLevelFrame.hx +++ b/src/client/haxe/ru/m/tankz/frame/dota/DotaLevelFrame.hx @@ -3,7 +3,6 @@ package ru.m.tankz.frame.dota; import haxework.gui.ButtonView; import haxework.gui.DataView; import haxework.gui.frame.FrameSwitcher; -import ru.m.tankz.control.Control; import ru.m.tankz.frame.common.LevelFrame; import ru.m.tankz.frame.common.PlayerView; import ru.m.tankz.game.GameState; @@ -13,25 +12,20 @@ import ru.m.tankz.preset.DotaGame; public static inline var ID = "dota.level"; @:view var levels(default, null):DataView; - @:view var players(default, null):DataView; + @:view var players(default, null):DataView, PlayerView>; @:provide var frames:FrameSwitcher; private function onShow():Void { gameType = DotaGame.TYPE; levels.data = [for (i in 0...config.game.levels) i]; - var data = []; - for (i in 0...2) { - data.push(new PlayerState(null, Control.HUMAN)); - } - state.players = data; - players.data = data; + players.data = [for (i in 0...2) state.players]; } - private function playerViewFactory(index:Int, player:PlayerState):PlayerView { + private function playerViewFactory(index:Int, data:Array):PlayerView { var view = new PlayerView(); view.item_index = index; - view.data = player; + view.data = data; return view; } diff --git a/src/client/haxe/ru/m/tankz/sound/SoundManager.hx b/src/client/haxe/ru/m/tankz/sound/SoundManager.hx index 9520f83..1b2b7a3 100644 --- a/src/client/haxe/ru/m/tankz/sound/SoundManager.hx +++ b/src/client/haxe/ru/m/tankz/sound/SoundManager.hx @@ -44,7 +44,7 @@ class SoundManager { play('bullet_hit'); //case [EntityType.TANK(_), EntityChange.LIVE_UP]: // play('live'); - case [EntityType.EAGLE(_), EntityChange.DEATH]: + case [EntityType.EAGLE(_), EntityChange.DEATH(_)]: play('boom_player'); case _: } diff --git a/src/common/haxe/ru/m/tankz/config/Config.hx b/src/common/haxe/ru/m/tankz/config/Config.hx index 927d7b9..6ca73f8 100644 --- a/src/common/haxe/ru/m/tankz/config/Config.hx +++ b/src/common/haxe/ru/m/tankz/config/Config.hx @@ -78,9 +78,14 @@ typedef PlayerConfig = { @:optional var control:ControlType; } +typedef EagleConfig = { + @:optional var score:Int; +} + typedef TeamConfig = { var id:TeamId; var players:Array; + @:optional var eagle:EagleConfig; @:optional var life:Int; @:optional var spawnInterval:Int; @:optional var color:Color; diff --git a/src/common/haxe/ru/m/tankz/core/Eagle.hx b/src/common/haxe/ru/m/tankz/core/Eagle.hx index 30247a9..62f5e5d 100644 --- a/src/common/haxe/ru/m/tankz/core/Eagle.hx +++ b/src/common/haxe/ru/m/tankz/core/Eagle.hx @@ -1,19 +1,27 @@ package ru.m.tankz.core; +import ru.m.tankz.config.Config.EagleConfig; import ru.m.geom.Rectangle; import ru.m.tankz.Type; - class Eagle extends Entity { public var team(default, null):TeamId; + public var config(default, null):EagleConfig; public var death(default, default):Bool; public var protect(default, null):Modificator; - public function new(team:TeamId) { - super(new Rectangle(0, 0, 44, 44)); // ToDo: hardcode size + public var score(get, null):Int; + + public function new(team:TeamId, config:EagleConfig) { + super(new Rectangle(0, 0, 44, 44)); // ToDo: hardcode size this.team = team; + this.config = config; this.death = false; this.protect = new Modificator(); } + + private inline function get_score():Int { + return config != null ? config.score : 0; + } } diff --git a/src/common/haxe/ru/m/tankz/engine/Engine.hx b/src/common/haxe/ru/m/tankz/engine/Engine.hx index 26bb4ec..54f9066 100755 --- a/src/common/haxe/ru/m/tankz/engine/Engine.hx +++ b/src/common/haxe/ru/m/tankz/engine/Engine.hx @@ -17,7 +17,7 @@ import ru.m.tankz.Type; enum EntityChange { HIT; TYPE; - DEATH; + DEATH(playerId:PlayerId); PROTECT; FREEZING; } @@ -74,7 +74,7 @@ class CollisionProcessor { if (!eagle.protect.active) { eagle.death = true; // ToDo: change - engine.change(eagle, EntityChange.DEATH); + engine.change(eagle, EntityChange.DEATH(bullet.playerId)); } case _: } diff --git a/src/common/haxe/ru/m/tankz/game/Game.hx b/src/common/haxe/ru/m/tankz/game/Game.hx index eb77dca..8b46322 100644 --- a/src/common/haxe/ru/m/tankz/game/Game.hx +++ b/src/common/haxe/ru/m/tankz/game/Game.hx @@ -120,7 +120,7 @@ class Game { } var eaglePoint = team.spawner.getPoint('eagle'); if (eaglePoint != null) { - var eagle = new Eagle(team.id); + var eagle = new Eagle(team.id, team.config.eagle); team.eagleId = eagle.id; applyPoint(eagle, eaglePoint); engine.spawn(eagle); @@ -167,8 +167,9 @@ class Game { public function onChange(entity:EntityType, change:EntityChange):Void { switch [entity, change] { - case [EntityType.EAGLE(eagle), EntityChange.DEATH]: + case [EntityType.EAGLE(eagle), EntityChange.DEATH(playerId)]: if (eagle.death) { + getPlayer(playerId).state.score += eagle.score * (eagle.team == playerId.team ? 0 : 1); lose(eagle.team); deferred.resolve(state); } @@ -217,9 +218,9 @@ class Game { if (tank.bonus) { spawnBonus(); } - if (tank.config.score > 0 && playerId != null) { + if (playerId != null) { getPlayer(playerId).state.frags++; - getPlayer(playerId).state.score += tank.config.score; + getPlayer(playerId).state.score += tank.config.score * (tank.playerId.team == playerId.team ? 0 : 1); } deferred.resolve(state); case EntityType.BONUS(bonus): diff --git a/src/common/resources/dota/config.yaml b/src/common/resources/dota/config.yaml index 6b3ed4d..69ad753 100644 --- a/src/common/resources/dota/config.yaml +++ b/src/common/resources/dota/config.yaml @@ -39,6 +39,8 @@ team: - {<<: *player-slow, index: 2} - {<<: *player-fast, index: 3} - {<<: *player-slow, index: 4} + eagle: + score: 500 radiant: &radiant id: radiant color: 0xff4422