[client] add tanks players names to render
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user