[common] game update

This commit is contained in:
2019-03-14 17:49:47 +03:00
parent 8ea862a118
commit 426b2718bb
14 changed files with 97 additions and 48 deletions

View File

@@ -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;

View File

@@ -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;
}
}

View File

@@ -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 _:
}

View File

@@ -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):

View File

@@ -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