[common] update game rework
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
package ru.m.tankz.local;
|
||||
|
||||
import flash.events.Event;
|
||||
import flash.Lib;
|
||||
import ru.m.tankz.control.HumanControl;
|
||||
import ru.m.tankz.game.GameEvent;
|
||||
import ru.m.tankz.game.GameRunner;
|
||||
@@ -11,15 +13,26 @@ class LocalGame extends GameRunner {
|
||||
|
||||
@:provide static var gameStorage:GameStorage;
|
||||
|
||||
private var updateEvent:String;
|
||||
|
||||
public function new(start:Start) {
|
||||
super(start);
|
||||
controlFactory = new LocalControlFactory();
|
||||
updateEvent = Event.ENTER_FRAME;
|
||||
}
|
||||
|
||||
private function onUpdateEvent(_):Void {
|
||||
update();
|
||||
}
|
||||
|
||||
override public function onGameEvent(event:GameEvent):Void {
|
||||
super.onGameEvent(event);
|
||||
switch event {
|
||||
case COMPLETE(result): updateProgress(result);
|
||||
case START(_):
|
||||
Lib.current.stage.addEventListener(updateEvent, onUpdateEvent);
|
||||
case COMPLETE(result):
|
||||
Lib.current.stage.removeEventListener(updateEvent, onUpdateEvent);
|
||||
updateProgress(result);
|
||||
case _:
|
||||
}
|
||||
}
|
||||
@@ -38,4 +51,9 @@ class LocalGame extends GameRunner {
|
||||
gameStorage.set(progress);
|
||||
}
|
||||
}
|
||||
|
||||
override public function dispose():Void {
|
||||
super.dispose();
|
||||
Lib.current.stage.removeEventListener(updateEvent, onUpdateEvent);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
---
|
||||
geometry.padding: [5, 2]
|
||||
layout.vAlign: middle
|
||||
visible: false
|
||||
skin:
|
||||
$type: haxework.view.skin.SpriteSkin
|
||||
border.color: 0x95937D
|
||||
|
||||
@@ -54,6 +54,9 @@ class Ticker implements ITicker {
|
||||
if (actions.length > 0) {
|
||||
runActions();
|
||||
}
|
||||
if (result > 45) {
|
||||
L.w("Ticker", 'Long tick: ${result}');
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
@@ -130,6 +130,9 @@ import ru.m.tankz.Type;
|
||||
public function start():Void {
|
||||
}
|
||||
|
||||
public function update():Void {
|
||||
}
|
||||
|
||||
public function dispose():Void {
|
||||
for (control in controls) {
|
||||
control.dispose();
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package ru.m.tankz.game;
|
||||
|
||||
import ru.m.tankz.core.Weapon;
|
||||
import ru.m.geom.Line;
|
||||
import ru.m.geom.Point;
|
||||
import ru.m.tankz.bonus.BonusFactory;
|
||||
@@ -10,18 +9,17 @@ import ru.m.tankz.core.Bullet;
|
||||
import ru.m.tankz.core.Eagle;
|
||||
import ru.m.tankz.core.EntityType;
|
||||
import ru.m.tankz.core.Tank;
|
||||
import ru.m.tankz.core.Weapon;
|
||||
import ru.m.tankz.engine.Engine;
|
||||
import ru.m.tankz.engine.IEngine;
|
||||
import ru.m.tankz.game.GameEvent;
|
||||
import ru.m.tankz.game.GameState;
|
||||
import ru.m.tankz.game.Spawner;
|
||||
import ru.m.tankz.Type;
|
||||
import ru.m.Timer;
|
||||
|
||||
using ru.m.tankz.game.GameUtil;
|
||||
|
||||
class GameRunner extends Game implements EngineListener {
|
||||
private var timer:Timer;
|
||||
private var builder:EntityBuilder;
|
||||
private var bonuses:BonusFactory;
|
||||
|
||||
@@ -46,7 +44,8 @@ class GameRunner extends Game implements EngineListener {
|
||||
}
|
||||
}
|
||||
|
||||
private function update():Void {
|
||||
override public function update():Void {
|
||||
super.update();
|
||||
engine.update();
|
||||
}
|
||||
|
||||
@@ -140,9 +139,9 @@ class GameRunner extends Game implements EngineListener {
|
||||
}
|
||||
|
||||
private function complete(winner:TeamId):Void {
|
||||
Timer.delay(function() {
|
||||
engine.ticker.emit(function() {
|
||||
gameEventSignal.emit(COMPLETE({state: state, level: level, winner: winner}));
|
||||
}, 3000);
|
||||
}, 3000, "complete");
|
||||
}
|
||||
|
||||
public function onSpawn(entity:EntityType):Void {
|
||||
@@ -276,14 +275,8 @@ class GameRunner extends Game implements EngineListener {
|
||||
switch event {
|
||||
case START(_):
|
||||
engine.ticker.start();
|
||||
timer = new Timer(30);
|
||||
timer.run = update;
|
||||
case COMPLETE(_):
|
||||
engine.ticker.stop();
|
||||
if (timer != null) {
|
||||
timer.stop();
|
||||
timer = null;
|
||||
}
|
||||
case ACTION(tankId, SHOT(index)):
|
||||
var tank:Tank = cast engine.entities.get(tankId);
|
||||
var player = getPlayer(tank.playerId);
|
||||
|
||||
@@ -32,6 +32,8 @@ interface IGame extends GameListener {
|
||||
public function getPlayer(playerId:PlayerId):Player;
|
||||
|
||||
public function start():Void;
|
||||
|
||||
public function update():Void;
|
||||
}
|
||||
|
||||
interface GameListener {
|
||||
|
||||
@@ -21,6 +21,8 @@ class ServerGame extends GameRunner {
|
||||
public var room(default, null):RoomProto;
|
||||
public var id(get, null):Int;
|
||||
|
||||
private var timer:Timer;
|
||||
|
||||
@:provide static var levelBundle:ILevelBundle;
|
||||
|
||||
public function new(room:RoomProto) {
|
||||
@@ -36,6 +38,19 @@ class ServerGame extends GameRunner {
|
||||
return room.game.id;
|
||||
}
|
||||
|
||||
override public function onGameEvent(event:GameEvent):Void {
|
||||
switch event {
|
||||
case START(_):
|
||||
timer = new Timer(30);
|
||||
timer.run = update;
|
||||
case COMPLETE(_):
|
||||
if (timer != null) {
|
||||
timer.stop();
|
||||
timer = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function contains(user:UserProto):Bool {
|
||||
for (slot in room.slots) {
|
||||
if (slot.hasUser() && slot.user.uuid == user.uuid) {
|
||||
@@ -88,6 +103,14 @@ class ServerGame extends GameRunner {
|
||||
super.start();
|
||||
}
|
||||
|
||||
override public function dispose():Void {
|
||||
super.dispose();
|
||||
if (timer != null) {
|
||||
timer.stop();
|
||||
timer = null;
|
||||
}
|
||||
}
|
||||
|
||||
public function restore():Array<GameEvent> {
|
||||
var result = [];
|
||||
result.push(EventUtil.buildBricksSpawn(engine.map));
|
||||
|
||||
Reference in New Issue
Block a user