[common] game update
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
---
|
||||
layout.margin: 5
|
||||
views:
|
||||
- id: image
|
||||
- id: tank
|
||||
$type: haxework.gui.ImageView
|
||||
- id: live
|
||||
$type: haxework.gui.LabelView
|
||||
|
||||
@@ -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<TeamButton> {
|
||||
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<PlayerState>;
|
||||
|
||||
@:view var label(default, null):LabelView;
|
||||
@:view var teams(default, null):DataView<TeamId, ToggleButtonView>;
|
||||
|
||||
@: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<TeamButton> {
|
||||
return view;
|
||||
}
|
||||
|
||||
private function set_data(value:PlayerState):PlayerState {
|
||||
private function set_data(value:Array<PlayerState>):Array<PlayerState> {
|
||||
data = value;
|
||||
teams.data = [NONE].concat([for (team in state.preset.teams) team.id]);
|
||||
return data;
|
||||
@@ -84,7 +86,17 @@ class TeamSkin implements ISkin<TeamButton> {
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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<Int, ButtonView>;
|
||||
@:view var players(default, null):DataView<PlayerState, PlayerView>;
|
||||
@:view var players(default, null):DataView<Array<PlayerState>, 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<PlayerState>):PlayerView {
|
||||
var view = new PlayerView();
|
||||
view.item_index = index;
|
||||
view.data = player;
|
||||
view.data = data;
|
||||
return view;
|
||||
}
|
||||
|
||||
|
||||
@@ -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 _:
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user