[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 _:
|
||||
}
|
||||
|
||||
@@ -78,9 +78,14 @@ typedef PlayerConfig = {
|
||||
@:optional var control:ControlType;
|
||||
}
|
||||
|
||||
typedef EagleConfig = {
|
||||
@:optional var score:Int;
|
||||
}
|
||||
|
||||
typedef TeamConfig = {
|
||||
var id:TeamId;
|
||||
var players:Array<PlayerConfig>;
|
||||
@:optional var eagle:EagleConfig;
|
||||
@:optional var life:Int;
|
||||
@:optional var spawnInterval:Int;
|
||||
@:optional var color:Color;
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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 _:
|
||||
}
|
||||
|
||||
@@ -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):
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user