[common] game update
This commit is contained in:
@@ -15,15 +15,15 @@ import ru.m.tankz.preset.ClassicGame;
|
|||||||
public var game:Game;
|
public var game:Game;
|
||||||
|
|
||||||
private function updateViews():Void {
|
private function updateViews():Void {
|
||||||
bot.live.text = '${game.teams[ClassicGame.BOT].life}';
|
bot.live = game.teams[ClassicGame.BOT].life;
|
||||||
player1.live.text = '${game.teams[ClassicGame.HUMAN].players[0].state.life}';
|
player1.live = game.teams[ClassicGame.HUMAN].players[0].state.life;
|
||||||
player1.score.text = '${game.teams[ClassicGame.HUMAN].players[0].state.score}';
|
player1.score = game.teams[ClassicGame.HUMAN].players[0].state.score;
|
||||||
if (game.teams[ClassicGame.HUMAN].players[1] != null) {
|
if (game.teams[ClassicGame.HUMAN].players[1] != null) {
|
||||||
player2.live.text = '${game.teams[ClassicGame.HUMAN].players[1].state.life}';
|
player2.visible = true;
|
||||||
player2.score.text = '${game.teams[ClassicGame.HUMAN].players[1].state.score}';
|
player2.live = game.teams[ClassicGame.HUMAN].players[1].state.life;
|
||||||
|
player2.score = game.teams[ClassicGame.HUMAN].players[1].state.score;
|
||||||
} else {
|
} else {
|
||||||
player2.live.text = "";
|
player2.visible = false;
|
||||||
player2.score.text = "";
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -5,12 +5,13 @@ layout.hAlign: right
|
|||||||
views:
|
views:
|
||||||
- id: bot
|
- id: bot
|
||||||
$type: ru.m.tankz.frame.common.LifeView
|
$type: ru.m.tankz.frame.common.LifeView
|
||||||
image.image: $asset:image:resources/image/tank/ba-0.png
|
tank: ba
|
||||||
|
scoreLabel.visible: false
|
||||||
- id: player1
|
- id: player1
|
||||||
$type: ru.m.tankz.frame.common.LifeView
|
$type: ru.m.tankz.frame.common.LifeView
|
||||||
image.image: $asset:image:resources/image/tank/pa-0.png
|
tank: pa
|
||||||
image.color: 0xFFFF00
|
color: 0xFFFF00
|
||||||
- id: player2
|
- id: player2
|
||||||
$type: ru.m.tankz.frame.common.LifeView
|
$type: ru.m.tankz.frame.common.LifeView
|
||||||
image.image: $asset:image:resources/image/tank/pa-0.png
|
tank: pa
|
||||||
image.color: 0x15C040
|
color: 0x15C040
|
||||||
|
|||||||
@@ -1,11 +1,37 @@
|
|||||||
package ru.m.tankz.frame.common;
|
package ru.m.tankz.frame.common;
|
||||||
|
|
||||||
|
import openfl.Assets;
|
||||||
import haxework.gui.LabelView;
|
import haxework.gui.LabelView;
|
||||||
import haxework.gui.ImageView;
|
import haxework.gui.ImageView;
|
||||||
import haxework.gui.HGroupView;
|
import haxework.gui.HGroupView;
|
||||||
|
|
||||||
@:template class LifeView extends HGroupView {
|
@:template class LifeView extends HGroupView {
|
||||||
@:view public var image:ImageView;
|
@:view("tank") public var tankImage:ImageView;
|
||||||
@:view public var live:LabelView;
|
@:view("live") public var liveLabel:LabelView;
|
||||||
@:view public var score: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
|
layout.margin: 5
|
||||||
views:
|
views:
|
||||||
- id: image
|
- id: tank
|
||||||
$type: haxework.gui.ImageView
|
$type: haxework.gui.ImageView
|
||||||
- id: live
|
- id: live
|
||||||
$type: haxework.gui.LabelView
|
$type: haxework.gui.LabelView
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
package ru.m.tankz.frame.common;
|
package ru.m.tankz.frame.common;
|
||||||
|
|
||||||
|
import ru.m.tankz.control.Control;
|
||||||
import haxework.gui.DataView;
|
import haxework.gui.DataView;
|
||||||
import haxework.gui.HGroupView;
|
import haxework.gui.HGroupView;
|
||||||
import haxework.gui.LabelView;
|
import haxework.gui.LabelView;
|
||||||
import haxework.gui.skin.ISkin;
|
import haxework.gui.skin.ISkin;
|
||||||
import haxework.gui.ToggleButtonView;
|
import haxework.gui.ToggleButtonView;
|
||||||
import ru.m.tankz.game.GameState;
|
import ru.m.tankz.game.GameState;
|
||||||
import ru.m.tankz.Type.PlayerId;
|
|
||||||
import ru.m.tankz.Type.TeamId;
|
import ru.m.tankz.Type.TeamId;
|
||||||
|
|
||||||
class TeamButton extends ToggleButtonView {
|
class TeamButton extends ToggleButtonView {
|
||||||
@@ -44,13 +44,15 @@ class TeamSkin implements ISkin<TeamButton> {
|
|||||||
private static inline var NONE:TeamId = "none";
|
private static inline var NONE:TeamId = "none";
|
||||||
|
|
||||||
public var item_index(default, set):Int;
|
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 label(default, null):LabelView;
|
||||||
@:view var teams(default, null):DataView<TeamId, ToggleButtonView>;
|
@:view var teams(default, null):DataView<TeamId, ToggleButtonView>;
|
||||||
|
|
||||||
@:provide var state:GameState;
|
@:provide var state:GameState;
|
||||||
|
|
||||||
|
private var player:PlayerState;
|
||||||
|
|
||||||
private function teamViewFactory(index:Int, team:TeamId) {
|
private function teamViewFactory(index:Int, team:TeamId) {
|
||||||
var view = new TeamButton();
|
var view = new TeamButton();
|
||||||
view.skin = [new TeamSkin(getTeamColor(team))];
|
view.skin = [new TeamSkin(getTeamColor(team))];
|
||||||
@@ -60,7 +62,7 @@ class TeamSkin implements ISkin<TeamButton> {
|
|||||||
return view;
|
return view;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function set_data(value:PlayerState):PlayerState {
|
private function set_data(value:Array<PlayerState>):Array<PlayerState> {
|
||||||
data = value;
|
data = value;
|
||||||
teams.data = [NONE].concat([for (team in state.preset.teams) team.id]);
|
teams.data = [NONE].concat([for (team in state.preset.teams) team.id]);
|
||||||
return data;
|
return data;
|
||||||
@@ -84,7 +86,17 @@ class TeamSkin implements ISkin<TeamButton> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private function onTeamSelect(team:TeamId) {
|
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) {
|
for (view in teams.views) {
|
||||||
var button = cast(view, TeamButton);
|
var button = cast(view, TeamButton);
|
||||||
button.on = team == button.team;
|
button.on = team == button.team;
|
||||||
|
|||||||
@@ -14,10 +14,10 @@ import ru.m.tankz.preset.DotaGame;
|
|||||||
public var game:Game;
|
public var game:Game;
|
||||||
|
|
||||||
private function updateViews():Void {
|
private function updateViews():Void {
|
||||||
radiant.live.text = '${game.teams[DotaGame.RADIANT].life}';
|
radiant.live = game.teams[DotaGame.RADIANT].life;
|
||||||
radiant.score.text = '${game.teams[DotaGame.RADIANT].score}';
|
radiant.score = game.teams[DotaGame.RADIANT].score;
|
||||||
dire.live.text = '${game.teams[DotaGame.DIRE].life}';
|
dire.live = game.teams[DotaGame.DIRE].life;
|
||||||
dire.score.text = '${game.teams[DotaGame.DIRE].score}';
|
dire.score = game.teams[DotaGame.DIRE].score;
|
||||||
}
|
}
|
||||||
|
|
||||||
override public function update():Void {
|
override public function update():Void {
|
||||||
|
|||||||
@@ -4,11 +4,11 @@ layout.margin: 20
|
|||||||
views:
|
views:
|
||||||
- id: radiant
|
- id: radiant
|
||||||
$type: ru.m.tankz.frame.common.LifeView
|
$type: ru.m.tankz.frame.common.LifeView
|
||||||
image.image: $asset:image:resources/image/tank/bc-0.png
|
tank: bc
|
||||||
image.color: 0xff4422
|
color: 0xff4422
|
||||||
- $type: haxework.gui.SpriteView
|
- $type: haxework.gui.SpriteView
|
||||||
geometry.size.width: 100%
|
geometry.size.width: 100%
|
||||||
- id: dire
|
- id: dire
|
||||||
$type: ru.m.tankz.frame.common.LifeView
|
$type: ru.m.tankz.frame.common.LifeView
|
||||||
image.image: $asset:image:resources/image/tank/bc-0.png
|
tank: bc
|
||||||
image.color: 0x3284ff
|
color: 0x3284ff
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ package ru.m.tankz.frame.dota;
|
|||||||
import haxework.gui.ButtonView;
|
import haxework.gui.ButtonView;
|
||||||
import haxework.gui.DataView;
|
import haxework.gui.DataView;
|
||||||
import haxework.gui.frame.FrameSwitcher;
|
import haxework.gui.frame.FrameSwitcher;
|
||||||
import ru.m.tankz.control.Control;
|
|
||||||
import ru.m.tankz.frame.common.LevelFrame;
|
import ru.m.tankz.frame.common.LevelFrame;
|
||||||
import ru.m.tankz.frame.common.PlayerView;
|
import ru.m.tankz.frame.common.PlayerView;
|
||||||
import ru.m.tankz.game.GameState;
|
import ru.m.tankz.game.GameState;
|
||||||
@@ -13,25 +12,20 @@ import ru.m.tankz.preset.DotaGame;
|
|||||||
public static inline var ID = "dota.level";
|
public static inline var ID = "dota.level";
|
||||||
|
|
||||||
@:view var levels(default, null):DataView<Int, ButtonView>;
|
@: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;
|
@:provide var frames:FrameSwitcher;
|
||||||
|
|
||||||
private function onShow():Void {
|
private function onShow():Void {
|
||||||
gameType = DotaGame.TYPE;
|
gameType = DotaGame.TYPE;
|
||||||
levels.data = [for (i in 0...config.game.levels) i];
|
levels.data = [for (i in 0...config.game.levels) i];
|
||||||
var data = [];
|
players.data = [for (i in 0...2) state.players];
|
||||||
for (i in 0...2) {
|
|
||||||
data.push(new PlayerState(null, Control.HUMAN));
|
|
||||||
}
|
|
||||||
state.players = data;
|
|
||||||
players.data = data;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private function playerViewFactory(index:Int, player:PlayerState):PlayerView {
|
private function playerViewFactory(index:Int, data:Array<PlayerState>):PlayerView {
|
||||||
var view = new PlayerView();
|
var view = new PlayerView();
|
||||||
view.item_index = index;
|
view.item_index = index;
|
||||||
view.data = player;
|
view.data = data;
|
||||||
return view;
|
return view;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ class SoundManager {
|
|||||||
play('bullet_hit');
|
play('bullet_hit');
|
||||||
//case [EntityType.TANK(_), EntityChange.LIVE_UP]:
|
//case [EntityType.TANK(_), EntityChange.LIVE_UP]:
|
||||||
// play('live');
|
// play('live');
|
||||||
case [EntityType.EAGLE(_), EntityChange.DEATH]:
|
case [EntityType.EAGLE(_), EntityChange.DEATH(_)]:
|
||||||
play('boom_player');
|
play('boom_player');
|
||||||
case _:
|
case _:
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -78,9 +78,14 @@ typedef PlayerConfig = {
|
|||||||
@:optional var control:ControlType;
|
@:optional var control:ControlType;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
typedef EagleConfig = {
|
||||||
|
@:optional var score:Int;
|
||||||
|
}
|
||||||
|
|
||||||
typedef TeamConfig = {
|
typedef TeamConfig = {
|
||||||
var id:TeamId;
|
var id:TeamId;
|
||||||
var players:Array<PlayerConfig>;
|
var players:Array<PlayerConfig>;
|
||||||
|
@:optional var eagle:EagleConfig;
|
||||||
@:optional var life:Int;
|
@:optional var life:Int;
|
||||||
@:optional var spawnInterval:Int;
|
@:optional var spawnInterval:Int;
|
||||||
@:optional var color:Color;
|
@:optional var color:Color;
|
||||||
|
|||||||
@@ -1,19 +1,27 @@
|
|||||||
package ru.m.tankz.core;
|
package ru.m.tankz.core;
|
||||||
|
|
||||||
|
import ru.m.tankz.config.Config.EagleConfig;
|
||||||
import ru.m.geom.Rectangle;
|
import ru.m.geom.Rectangle;
|
||||||
import ru.m.tankz.Type;
|
import ru.m.tankz.Type;
|
||||||
|
|
||||||
|
|
||||||
class Eagle extends Entity {
|
class Eagle extends Entity {
|
||||||
|
|
||||||
public var team(default, null):TeamId;
|
public var team(default, null):TeamId;
|
||||||
|
public var config(default, null):EagleConfig;
|
||||||
public var death(default, default):Bool;
|
public var death(default, default):Bool;
|
||||||
public var protect(default, null):Modificator;
|
public var protect(default, null):Modificator;
|
||||||
|
|
||||||
public function new(team:TeamId) {
|
public var score(get, null):Int;
|
||||||
super(new Rectangle(0, 0, 44, 44)); // ToDo: hardcode size
|
|
||||||
|
public function new(team:TeamId, config:EagleConfig) {
|
||||||
|
super(new Rectangle(0, 0, 44, 44)); // ToDo: hardcode size
|
||||||
this.team = team;
|
this.team = team;
|
||||||
|
this.config = config;
|
||||||
this.death = false;
|
this.death = false;
|
||||||
this.protect = new Modificator();
|
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 {
|
enum EntityChange {
|
||||||
HIT;
|
HIT;
|
||||||
TYPE;
|
TYPE;
|
||||||
DEATH;
|
DEATH(playerId:PlayerId);
|
||||||
PROTECT;
|
PROTECT;
|
||||||
FREEZING;
|
FREEZING;
|
||||||
}
|
}
|
||||||
@@ -74,7 +74,7 @@ class CollisionProcessor {
|
|||||||
if (!eagle.protect.active) {
|
if (!eagle.protect.active) {
|
||||||
eagle.death = true;
|
eagle.death = true;
|
||||||
// ToDo: change
|
// ToDo: change
|
||||||
engine.change(eagle, EntityChange.DEATH);
|
engine.change(eagle, EntityChange.DEATH(bullet.playerId));
|
||||||
}
|
}
|
||||||
case _:
|
case _:
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -120,7 +120,7 @@ class Game {
|
|||||||
}
|
}
|
||||||
var eaglePoint = team.spawner.getPoint('eagle');
|
var eaglePoint = team.spawner.getPoint('eagle');
|
||||||
if (eaglePoint != null) {
|
if (eaglePoint != null) {
|
||||||
var eagle = new Eagle(team.id);
|
var eagle = new Eagle(team.id, team.config.eagle);
|
||||||
team.eagleId = eagle.id;
|
team.eagleId = eagle.id;
|
||||||
applyPoint(eagle, eaglePoint);
|
applyPoint(eagle, eaglePoint);
|
||||||
engine.spawn(eagle);
|
engine.spawn(eagle);
|
||||||
@@ -167,8 +167,9 @@ class Game {
|
|||||||
|
|
||||||
public function onChange(entity:EntityType, change:EntityChange):Void {
|
public function onChange(entity:EntityType, change:EntityChange):Void {
|
||||||
switch [entity, change] {
|
switch [entity, change] {
|
||||||
case [EntityType.EAGLE(eagle), EntityChange.DEATH]:
|
case [EntityType.EAGLE(eagle), EntityChange.DEATH(playerId)]:
|
||||||
if (eagle.death) {
|
if (eagle.death) {
|
||||||
|
getPlayer(playerId).state.score += eagle.score * (eagle.team == playerId.team ? 0 : 1);
|
||||||
lose(eagle.team);
|
lose(eagle.team);
|
||||||
deferred.resolve(state);
|
deferred.resolve(state);
|
||||||
}
|
}
|
||||||
@@ -217,9 +218,9 @@ class Game {
|
|||||||
if (tank.bonus) {
|
if (tank.bonus) {
|
||||||
spawnBonus();
|
spawnBonus();
|
||||||
}
|
}
|
||||||
if (tank.config.score > 0 && playerId != null) {
|
if (playerId != null) {
|
||||||
getPlayer(playerId).state.frags++;
|
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);
|
deferred.resolve(state);
|
||||||
case EntityType.BONUS(bonus):
|
case EntityType.BONUS(bonus):
|
||||||
|
|||||||
@@ -39,6 +39,8 @@ team:
|
|||||||
- {<<: *player-slow, index: 2}
|
- {<<: *player-slow, index: 2}
|
||||||
- {<<: *player-fast, index: 3}
|
- {<<: *player-fast, index: 3}
|
||||||
- {<<: *player-slow, index: 4}
|
- {<<: *player-slow, index: 4}
|
||||||
|
eagle:
|
||||||
|
score: 500
|
||||||
radiant: &radiant
|
radiant: &radiant
|
||||||
id: radiant
|
id: radiant
|
||||||
color: 0xff4422
|
color: 0xff4422
|
||||||
|
|||||||
Reference in New Issue
Block a user