update worklist

This commit is contained in:
2018-02-04 14:11:43 +03:00
parent 59cab68e3e
commit e0ceff68f9
5 changed files with 78 additions and 52 deletions

View File

@@ -101,6 +101,7 @@ class Render extends SpriteView implements EngineListener {
items.set(tank.key, item);
entryLayer.addChild(item.view);
item.update();
playTankSpawn(tank.rect.center);
case EntityType.BULLET(bullet):
var item = new BulletItem(bullet);
items.set(bullet.key, item);
@@ -143,6 +144,21 @@ class Render extends SpriteView implements EngineListener {
}
}
private function playTankSpawn(point:Point):Void {
var arr = [
0, 1, 2, 3, 3, 4, 5, 5, 6
];
var frames = [for (i in arr) Assets.getBitmapData('resources/images/tank/appear/appear-${i}.png')];
var animate = new OnceAnimate(frames);
animate.x = point.x - animate.width / 2;
animate.y = point.y - animate.height / 2;
upperLayer.addChild(animate);
animate.play().then(function(animate) {
upperLayer.removeChild(animate);
animate.dispose();
});
}
private function playBulletBoom(point:Point):Void {
var arr = [
0, 1, 1, 0, 0, 1

View File

@@ -10,8 +10,8 @@ class BotControl extends Control {
public static var TYPE(default, never):ControlType = 'bot';
private var shotTimer:Timer;
private var turnRandomTimer:Timer;
private var turnTimer:Timer;
private var turnDelayTimer:Timer;
public function new(index:Int) {
super({type:TYPE, index:index});
@@ -33,9 +33,9 @@ class BotControl extends Control {
shotTimer = new Timer(1000);
shotTimer.run = shot;
}
if (turnTimer == null) {
turnTimer = new Timer(2000);
turnTimer.run = turn;
if (turnRandomTimer == null) {
turnRandomTimer = new Timer(2000);
turnRandomTimer.run = turn;
}
}
@@ -44,9 +44,9 @@ class BotControl extends Control {
shotTimer.stop();
shotTimer = null;
}
if (turnTimer != null) {
turnTimer.stop();
turnTimer = null;
if (turnRandomTimer != null) {
turnRandomTimer.stop();
turnRandomTimer = null;
}
}
@@ -55,17 +55,16 @@ class BotControl extends Control {
}
public function turnAfter(delay:Int):Void {
if (turnDelayTimer == null) {
turnDelayTimer = new Timer(delay);
turnDelayTimer.run = function() {
turnDelayTimer.stop();
turnDelayTimer = null;
turn();
}
if (turnTimer == null) {
turnTimer = Timer.delay(turn, delay);
}
}
public function turn():Void {
if (turnTimer != null) {
turnTimer.stop();
turnTimer = null;
}
action(TankAction.MOVE(randomDirection()));
}

View File

@@ -119,8 +119,8 @@ class Game implements EngineListener {
if (trySpawn(task.playerId, true)) {
var tank = buildTank(task.playerId, task.point);
var player:Player = getPlayer(task.playerId);
engine.spawn(tank);
player.tankId = tank.id;
Timer.delay(function() engine.spawn(tank), 500);
} else if (!isTeamAlive(task.playerId.team)) {
state.teams[task.playerId.team].lose = true;
complete();
@@ -135,12 +135,10 @@ class Game implements EngineListener {
player.control.dispose();
}
}
var timer = new Timer(5000);
timer.run = function() {
timer.stop();
Timer.delay(function() {
deferred.resolve(state);
stream.end();
}
}, 5000);
}
public function setControl(playerId:PlayerId, control:Control):Void {
@@ -159,7 +157,11 @@ class Game implements EngineListener {
public function onSpawn(entity:EntityType):Void {
switch (entity) {
case EntityType.TANK(tank):
getPlayer(tank.playerId).control.start();
case x:
}
}
public function onCollision(entity:EntityType, with:EntityType):Void {
@@ -210,7 +212,8 @@ class Game implements EngineListener {
public function onDestroy(entity:EntityType):Void {
switch (entity) {
case EntityType.TANK(tank):
getPlayer(tank.playerId).tankId = 0;
getPlayer(tank.playerId).control.stop();
getPlayer(tank.playerId).tankId = 0; //ToDo: ?
var respawn:Bool = trySpawn(tank.playerId);
if (respawn) {
spawners.get(tank.playerId.team).push(tank.playerId);

View File

@@ -19,11 +19,6 @@ class Player {
tankId = value;
if (control != null) {
control.tankId = tankId;
if (tankId != 0) {
control.start();
} else {
control.stop();
}
}
return tankId;
}
@@ -33,9 +28,6 @@ class Player {
control = value;
if (control != null) {
control.tankId = tankId;
if (tankId != 0) {
control.start();
}
}
return control;
}