[render] add protect view

This commit is contained in:
2019-05-17 16:10:10 +03:00
parent 96e608c36f
commit 11f8fc6190
17 changed files with 133 additions and 340 deletions

View File

@@ -20,10 +20,15 @@ class Eagle extends Entity {
this.team = team;
this.config = config;
this.death = false;
this.protect = new Modificator();
this.protect = new Modificator(id);
}
private inline function get_score():Int {
return config != null ? config.score : 0;
}
override public function dispose() {
super.dispose();
protect.dispose();
}
}

View File

@@ -18,4 +18,6 @@ class Entity {
public function toString():String {
return '$type($id)';
}
public function dispose() {}
}

View File

@@ -1,26 +1,37 @@
package ru.m.tankz.core;
import haxe.Timer;
import haxework.signal.Signal;
class Modificator {
class Modificator extends Signal2<Int, Bool> {
public var id(default, default):Int;
public var active(default, default):Bool;
private var timer:Timer;
public function new() {
public function new(id) {
super();
this.id = id;
active = false;
}
override public function connect(receiver:Int->Bool->Void):Void {
super.connect(receiver);
receiver(id, active);
}
public function on(seconds:Float):Void {
off();
active = true;
timer = Timer.delay(off, Std.int(seconds * 1000));
emit(id, true);
}
public function off():Void {
if (timer != null) {
timer.stop();
timer = null;
emit(id, false);
}
active = false;
}

View File

@@ -17,8 +17,8 @@ class Tank extends MobileEntity {
public function new(id:Int, rect:Rectangle, playerId:PlayerId, config:TankConfig) {
super(id, rect, config.speed, Direction.RIGHT);
this.protect = new Modificator();
this.freezing = new Modificator();
this.protect = new Modificator(id);
this.freezing = new Modificator(id);
this.playerId = playerId;
this.config = config;
this.layer = 1;
@@ -39,4 +39,10 @@ class Tank extends MobileEntity {
super.move(direction);
}
}
override public function dispose() {
super.dispose();
protect.dispose();
freezing.dispose();
}
}

View File

@@ -140,7 +140,10 @@ import ru.m.tankz.map.LevelMap;
}
public function dispose():Void {
// ToDo: set to null
for (entity in allEntities) {
entity.dispose();
}
allEntities = new Map();
entities = new Map();
//map = null;
spawnSignal.dispose();

View File

@@ -58,6 +58,9 @@ enum StopEvent {
enum ChangeEvent {
TANK(id:Int, type:TankType, hits:Int, bonus:Bool);
TANK_PROTECT(id:Int, state:Bool);
TANK_FREEZE(id:Int, state:Bool);
EAGLE_PROTECT(id:Int, state:Bool);
PLAYER_SCORE(playerId:PlayerId, value:Int);
PLAYER_LIFE(playerId:PlayerId, value:Int);
TEAM_SCORE(teamId:TeamId, value:Int);

View File

@@ -1,7 +1,5 @@
package ru.m.tankz.game;
import ru.m.tankz.map.Grid.GridCell;
import ru.m.tankz.map.Brick;
import haxe.ds.Option;
import haxe.Timer;
import haxework.signal.Signal;
@@ -21,6 +19,7 @@ import ru.m.tankz.engine.IEngine;
import ru.m.tankz.game.GameEvent;
import ru.m.tankz.game.IGame;
import ru.m.tankz.game.Spawner;
import ru.m.tankz.map.Brick;
import ru.m.tankz.Type;
class GameRunner implements EngineListener implements GameListener {
@@ -85,6 +84,7 @@ class GameRunner implements EngineListener implements GameListener {
var eagle = builder.buildEagle(++entityId, point, team.id);
game.engine.spawn(eagle);
gameEventSignal.emit(GameEvent.SPAWN(EAGLE(eagle.id, eagle.rect, eagle.team)));
eagle.protect.connect(onEagleProtectChange);
}
}
var bricks = game.engine.map.bricks.map(function(item:Brick):BrickInfo {
@@ -115,6 +115,20 @@ class GameRunner implements EngineListener implements GameListener {
var tank = builder.buildTank(++entityId, task.point, task.playerId, task.tankType);
game.engine.spawn(tank);
gameEventSignal.emit(GameEvent.SPAWN(TANK(tank.id, tank.rect.clone(), tank.playerId, {type:tank.config.type, hits:tank.hits, bonus:tank.bonus})));
tank.protect.connect(onTankProtectChange);
tank.freezing.connect(onTankFreezingChange);
}
private function onEagleProtectChange(id:Int, state:Bool):Void {
gameEventSignal.emit(GameEvent.CHANGE(EAGLE_PROTECT(id, state)));
}
private function onTankProtectChange(id:Int, state:Bool):Void {
gameEventSignal.emit(GameEvent.CHANGE(TANK_PROTECT(id, state)));
}
private function onTankFreezingChange(id:Int, state:Bool):Void {
gameEventSignal.emit(GameEvent.CHANGE(TANK_FREEZE(id, state)));
}
private function checkComplete():Void {