[client] add tanks players names to render
This commit is contained in:
@@ -33,6 +33,7 @@ class HumanControl extends Control {
|
||||
super.stop();
|
||||
Lib.current.stage.removeEventListener(KeyboardEvent.KEY_DOWN, onKeyDown);
|
||||
Lib.current.stage.removeEventListener(KeyboardEvent.KEY_UP, onKeyUp);
|
||||
moveQueue = [];
|
||||
}
|
||||
|
||||
private function onKeyDown(event:KeyboardEvent):Void {
|
||||
|
||||
@@ -51,18 +51,18 @@ class Render extends SpriteView implements IRender {
|
||||
}
|
||||
|
||||
private function set_config(value:Config):Config {
|
||||
return config = value;
|
||||
config = value;
|
||||
setContentSize(config.mapWidth, config.mapHeight);
|
||||
drawBackground();
|
||||
return config;
|
||||
}
|
||||
|
||||
private function drawBackground():Void {
|
||||
var width = config.map.cellWidth * config.map.gridWidth;
|
||||
var height = config.map.cellHeight * config.map.gridHeight;
|
||||
var g:Graphics = backgroundLayer.graphics;
|
||||
g.clear();
|
||||
g.beginFill(0x000000);
|
||||
g.drawRect(0, 0, width, height);
|
||||
g.drawRect(0, 0, config.mapWidth, config.mapHeight);
|
||||
g.endFill();
|
||||
setContentSize(width, height);
|
||||
}
|
||||
|
||||
public function draw():Void {
|
||||
@@ -121,6 +121,7 @@ class Render extends SpriteView implements IRender {
|
||||
item.skin = tankConfig.skin;
|
||||
item.hits = info.hits;
|
||||
item.bonus = info.bonus;
|
||||
item.name = info.name == null ? "" : info.name;
|
||||
items.set(id, item);
|
||||
entryLayer.addChild(item.view);
|
||||
item.update();
|
||||
|
||||
@@ -7,6 +7,7 @@ import ru.m.geom.Rectangle;
|
||||
class RenderItem implements IRenderItem {
|
||||
|
||||
public var view(get, null):DisplayObject;
|
||||
public var content(get, null):DisplayObject;
|
||||
|
||||
public var rect(default, null):Rectangle;
|
||||
|
||||
@@ -18,14 +19,24 @@ class RenderItem implements IRenderItem {
|
||||
throw "Not Implemented";
|
||||
}
|
||||
|
||||
private function get_content():DisplayObject {
|
||||
return null;
|
||||
}
|
||||
|
||||
public function move(position:Position):Void {
|
||||
view.x = rect.x = position.x;
|
||||
view.y = rect.y = position.y;
|
||||
if (position.direction != null) {
|
||||
rect.direction = position.direction;
|
||||
view.rotation = rect.direction.angle;
|
||||
view.x = rect.x - rect.width * (rect.direction.x + 1) / 2 + rect.width * (rect.direction.y + 1) / 2 + 0.5 * rect.width;
|
||||
view.y = rect.y - rect.height * (rect.direction.x + 1) / 2 - rect.height * (rect.direction.y + 1) / 2 + 1.5 * rect.height;
|
||||
if (content != null) {
|
||||
content.rotation = rect.direction.angle;
|
||||
content.x = - rect.width * (rect.direction.x + 1) / 2 + rect.width * (rect.direction.y + 1) / 2 + 0.5 * rect.width;
|
||||
content.y = - rect.height * (rect.direction.x + 1) / 2 - rect.height * (rect.direction.y + 1) / 2 + 1.5 * rect.height;
|
||||
} else {
|
||||
view.rotation = rect.direction.angle;
|
||||
view.x = rect.x - rect.width * (rect.direction.x + 1) / 2 + rect.width * (rect.direction.y + 1) / 2 + 0.5 * rect.width;
|
||||
view.y = rect.y - rect.height * (rect.direction.x + 1) / 2 - rect.height * (rect.direction.y + 1) / 2 + 1.5 * rect.height;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,9 +1,13 @@
|
||||
package ru.m.tankz.render.item;
|
||||
|
||||
import flash.display.BitmapData;
|
||||
import flash.display.DisplayObject;
|
||||
import flash.display.Sprite;
|
||||
import flash.display.BitmapData;
|
||||
import flash.text.TextField;
|
||||
import flash.text.TextFieldAutoSize;
|
||||
import flash.text.TextFormat;
|
||||
import haxework.color.Color;
|
||||
import haxework.text.BitmapTextField;
|
||||
import haxework.view.utils.BitmapUtil;
|
||||
import openfl.Assets;
|
||||
import ru.m.animate.Animate;
|
||||
@@ -16,11 +20,13 @@ class TankRenderItem extends BitmapRenderItem {
|
||||
public var bonus(default, set):Bool;
|
||||
public var moves(default, set):Bool;
|
||||
public var protect(default, set):Bool;
|
||||
public var name(default, set):String;
|
||||
|
||||
private var container:Sprite;
|
||||
private var images:Array<BitmapData>;
|
||||
private var frame:Int;
|
||||
private var protectView:Animate;
|
||||
private var nameView:TextField;
|
||||
|
||||
public function new(rect:Rectangle) {
|
||||
super(rect);
|
||||
@@ -29,13 +35,29 @@ class TankRenderItem extends BitmapRenderItem {
|
||||
protectView = AnimateBundle.tankProtect();
|
||||
protectView.visible = false;
|
||||
container.addChild(protectView);
|
||||
nameView = buildNameView();
|
||||
container.addChild(nameView);
|
||||
move(rect.position);
|
||||
}
|
||||
|
||||
private function buildNameView():TextField {
|
||||
var result = new BitmapTextField();
|
||||
result.defaultTextFormat = new TextFormat(Style.fontFamily, 10, 0xffffff);
|
||||
result.embedFonts = Style.fontEmbed;
|
||||
result.autoSize = TextFieldAutoSize.LEFT;
|
||||
result.shadowColor = 0x000000;
|
||||
result.stroke = true;
|
||||
return result;
|
||||
}
|
||||
|
||||
override private function get_view():DisplayObject {
|
||||
return container;
|
||||
}
|
||||
|
||||
override private function get_content():DisplayObject {
|
||||
return bitmap;
|
||||
}
|
||||
|
||||
private function redraw():Void {
|
||||
var image1 = Assets.getBitmapData('resources/image/tank/${skin}-0.png');
|
||||
var image2 = Assets.getBitmapData('resources/image/tank/${skin}-1.png');
|
||||
@@ -105,6 +127,16 @@ class TankRenderItem extends BitmapRenderItem {
|
||||
return moves;
|
||||
}
|
||||
|
||||
private function set_name(value:String):String {
|
||||
if (name != value) {
|
||||
name = value;
|
||||
nameView.text = name;
|
||||
nameView.x = (rect.width - nameView.width) / 2;
|
||||
nameView.y = -nameView.height / 2; //(rect.height - nameView.height) / 2;
|
||||
}
|
||||
return name;
|
||||
}
|
||||
|
||||
override public function update():Void {
|
||||
super.update();
|
||||
if (moves) {
|
||||
|
||||
@@ -1,10 +1,8 @@
|
||||
---
|
||||
layout.overflow: true
|
||||
views:
|
||||
- $type: haxework.view.frame.FrameSwitcher
|
||||
id: switcher
|
||||
geometry.size.stretch: true
|
||||
layout.overflow: true
|
||||
skinId: dark
|
||||
views:
|
||||
- id: start
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
geometry.padding: 5
|
||||
geometry.size.height: 100%
|
||||
layout.margin: 5
|
||||
layout.hAlign: right
|
||||
layout.hAlign: left
|
||||
views:
|
||||
- id: level
|
||||
$type: haxework.view.LabelView
|
||||
|
||||
@@ -109,6 +109,7 @@ typedef PlayerControl = {
|
||||
var playerId:PlayerId;
|
||||
var control:String;
|
||||
@:optional var color:Null<Int>;
|
||||
@:optional var name:String;
|
||||
}
|
||||
|
||||
typedef ControlPreset = {
|
||||
@@ -138,6 +139,8 @@ class Config {
|
||||
public var controls(default, null):Array<ControlPreset>;
|
||||
public var points(default, null):Array<SpawnPoint>;
|
||||
public var bonuses(default, null):Array<BonusConfig>;
|
||||
public var mapWidth(get, null):Float;
|
||||
public var mapHeight(get, null):Float;
|
||||
|
||||
private var brickMap:Map<BrickType, BrickConfig>;
|
||||
private var brickMapByIndex:Map<Int, BrickConfig>;
|
||||
@@ -205,6 +208,14 @@ class Config {
|
||||
}
|
||||
}
|
||||
|
||||
private function get_mapWidth():Float {
|
||||
return map.cellWidth * map.gridWidth;
|
||||
}
|
||||
|
||||
private function get_mapHeight():Float {
|
||||
return map.cellHeight * map.gridHeight;
|
||||
}
|
||||
|
||||
public function getBrick(type:BrickType):BrickConfig {
|
||||
return brickMap.get(type);
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@ class Tank extends MobileEntity {
|
||||
public var playerId(default, null):PlayerId;
|
||||
public var config(default, set):TankConfig;
|
||||
public var color(default, default):Color;
|
||||
public var name(default, default):String;
|
||||
public var hits(default, default):Int;
|
||||
public var bonus(default, default):Bool;
|
||||
public var protect(default, default):Bool;
|
||||
|
||||
@@ -44,11 +44,12 @@ class EntityBuilder {
|
||||
return eagle;
|
||||
}
|
||||
|
||||
public function buildTank(point:EntityPoint, playerId:PlayerId, type:TankType, color:Null<Color>, bonusOff:Bool = false):Tank {
|
||||
public function buildTank(point:EntityPoint, playerId:PlayerId, type:TankType, color:Null<Color>, name:String, bonusOff:Bool = false):Tank {
|
||||
var playerConfig = config.getPlayer(playerId);
|
||||
var tankConfig = config.getTank(type);
|
||||
var tank = new Tank(++entityId, buildRect(point, tankConfig.width, tankConfig.height), playerId, tankConfig);
|
||||
tank.color = color == null || color.zero ? config.getColor(playerId) : color;
|
||||
tank.name = name;
|
||||
if (!bonusOff) {
|
||||
tank.bonus = Math.random() < playerConfig.bonus;
|
||||
}
|
||||
|
||||
@@ -47,6 +47,7 @@ class EventUtil {
|
||||
hits:tank.hits,
|
||||
bonus:tank.bonus,
|
||||
color:tank.color,
|
||||
name:tank.name,
|
||||
}));
|
||||
}
|
||||
|
||||
|
||||
@@ -112,8 +112,13 @@ import ru.m.tankz.Type;
|
||||
for (team in teams.iterator()) {
|
||||
for (player in team.players.iterator()) {
|
||||
var playerControl = controlsById.get(player.id);
|
||||
if (playerControl != null && playerControl.color != null) {
|
||||
player.state.color = playerControl.color;
|
||||
if (playerControl != null) {
|
||||
if (playerControl.color != null) {
|
||||
player.state.color = playerControl.color;
|
||||
}
|
||||
if (playerControl.name != null) {
|
||||
player.state.name = playerControl.name;
|
||||
}
|
||||
}
|
||||
var controlType:Controller = AController.fromString(playerControl != null ? playerControl.control : player.config.control);
|
||||
var control = controlFactory.build(player.id, controlType);
|
||||
|
||||
@@ -11,6 +11,7 @@ typedef TankInfo = {
|
||||
var hits:Int;
|
||||
var bonus:Bool;
|
||||
var color:Color;
|
||||
@:optional var name:String;
|
||||
}
|
||||
|
||||
typedef BrickInfo = {
|
||||
|
||||
@@ -73,7 +73,7 @@ class GameRunner extends Game implements EngineListener {
|
||||
|
||||
private function spawn(task:SpawnTask):Void {
|
||||
var player = getPlayer(task.playerId);
|
||||
var tank = builder.buildTank(task.point, task.playerId, task.tankType, player.state.color);
|
||||
var tank = builder.buildTank(task.point, task.playerId, task.tankType, player.state.color, player.state.name);
|
||||
engine.spawn(tank);
|
||||
gameEventSignal.emit(EventUtil.buildTankSpawn(tank));
|
||||
if (player.config.protect > 0) {
|
||||
|
||||
@@ -38,6 +38,7 @@ class PlayerState extends State {
|
||||
public var id:PlayerId;
|
||||
public var tank:TankType;
|
||||
public var color:Color;
|
||||
public var name:String;
|
||||
public var life:Int;
|
||||
public var total:State;
|
||||
|
||||
|
||||
@@ -203,10 +203,13 @@ controls:
|
||||
values:
|
||||
- playerId: [human, 0]
|
||||
control: human-0
|
||||
name: Player 1
|
||||
- id: 1
|
||||
name: 2 Player
|
||||
values:
|
||||
- playerId: [human, 0]
|
||||
control: human-0
|
||||
name: Player 1
|
||||
- playerId: [human, 1]
|
||||
control: human-1
|
||||
name: Player 2
|
||||
|
||||
@@ -96,10 +96,13 @@ controls:
|
||||
values:
|
||||
- playerId: [alpha, 0]
|
||||
control: human-0
|
||||
name: Player 1
|
||||
- id: 1
|
||||
name: 2 Player
|
||||
values:
|
||||
- playerId: [alpha, 0]
|
||||
control: human-0
|
||||
name: Player 1
|
||||
- playerId: [beta, 0]
|
||||
control: human-1
|
||||
name: Player 2
|
||||
|
||||
@@ -122,21 +122,26 @@ controls:
|
||||
- playerId: [radiant, 0]
|
||||
control: human-0
|
||||
color: 0xff8866
|
||||
name: Player 1
|
||||
- id: 1
|
||||
name: 2 Player Coop
|
||||
values:
|
||||
- playerId: [radiant, 0]
|
||||
control: human-0
|
||||
color: 0xff8866
|
||||
name: Player 1
|
||||
- playerId: [radiant, 1]
|
||||
control: human-1
|
||||
color: 0xff8866
|
||||
name: Player 2
|
||||
- id: 2
|
||||
name: 2 Player VS
|
||||
values:
|
||||
- playerId: [radiant, 0]
|
||||
control: human-0
|
||||
color: 0xff8866
|
||||
name: Player 1
|
||||
- playerId: [dire, 0]
|
||||
control: human-1
|
||||
color: 0x4294ff
|
||||
name: Player 2
|
||||
|
||||
@@ -46,17 +46,15 @@ enum Brush {
|
||||
|
||||
override private function drawBackground():Void {
|
||||
super.drawBackground();
|
||||
var mapWidth = map.gridWidth * map.cellWidth;
|
||||
var mapHeight = map.gridHeight * map.cellHeight;
|
||||
var g:Graphics = backgroundLayer.graphics;
|
||||
g.lineStyle(1, 0x007700);
|
||||
for (x in 0...map.gridWidth) {
|
||||
g.moveTo(x * map.cellWidth, 0);
|
||||
g.lineTo(x * map.cellWidth, mapHeight);
|
||||
for (x in 0...config.map.gridWidth) {
|
||||
g.moveTo(x * config.map.cellWidth, 0);
|
||||
g.lineTo(x * config.map.cellWidth, config.mapHeight);
|
||||
}
|
||||
for (y in 0...map.gridHeight) {
|
||||
g.moveTo(0, y * map.cellHeight);
|
||||
g.lineTo(mapWidth, y * map.cellHeight);
|
||||
for (y in 0...config.map.gridHeight) {
|
||||
g.moveTo(0, y * config.map.cellHeight);
|
||||
g.lineTo(config.mapWidth, y * config.map.cellHeight);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -117,7 +115,7 @@ enum Brush {
|
||||
var playerId = new PlayerId(point.team, point.index < 0 ? 0 : point.index);
|
||||
var player = config.getPlayer(playerId);
|
||||
var tankSpawn = player.tanks[0];
|
||||
var tank = builder.buildTank(point, playerId, tankSpawn.type, 0, true);
|
||||
var tank = builder.buildTank(point, playerId, tankSpawn.type, 0, playerId.toString(), true);
|
||||
pointEntities[pointKey(point)] = tank;
|
||||
gameEventSignal.emit(EventUtil.buildTankSpawn(tank));
|
||||
}
|
||||
|
||||
@@ -64,6 +64,7 @@ class ServerGame extends GameRunner {
|
||||
.map(function(slot:RoomSlotProto):PlayerControl return {
|
||||
playerId: [slot.slot.team, slot.slot.index],
|
||||
control: "human-0",
|
||||
name: slot.user.name,
|
||||
});
|
||||
super.start();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user