update
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
package ru.m.tankz.game;
|
||||
package ru.m.tankz.engine;
|
||||
|
||||
import ru.m.tankz.core.Direction;
|
||||
import ru.m.tankz.core.Tank.TankAction;
|
||||
@@ -6,7 +6,7 @@ import flash.ui.Keyboard;
|
||||
import ru.m.tankz.core.PlayerTank;
|
||||
import ru.m.tankz.core.ITank;
|
||||
|
||||
class ClientTankz extends Tankz {
|
||||
class ClientEngine extends Engine {
|
||||
|
||||
public var personId(default, default):Int;
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package ru.m.tankz.render;
|
||||
|
||||
import haxework.gui.IView;
|
||||
import ru.m.tankz.game.ITankz;
|
||||
import ru.m.tankz.engine.IEngine;
|
||||
|
||||
interface IRender extends IView {
|
||||
public function draw(game:ITankz):Void;
|
||||
public function draw(game:IEngine):Void;
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ package ru.m.tankz.render;
|
||||
import flash.display.Sprite;
|
||||
import flash.display.Graphics;
|
||||
import haxework.gui.SpriteView;
|
||||
import ru.m.tankz.game.ITankz;
|
||||
import ru.m.tankz.engine.IEngine;
|
||||
|
||||
class Render extends SpriteView implements IRender {
|
||||
|
||||
@@ -18,7 +18,7 @@ class Render extends SpriteView implements IRender {
|
||||
contentAsSprite.addChild(tankLayer);
|
||||
}
|
||||
|
||||
public function draw(game:ITankz):Void {
|
||||
public function draw(game:IEngine):Void {
|
||||
var mapWidth = game.map.gridWidth * game.map.cellWidth;
|
||||
var mapHeight = game.map.gridHeight * game.map.cellHeight;
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ import ru.m.tankz.core.MobileEntity;
|
||||
import ru.m.tankz.core.Direction;
|
||||
import ru.m.tankz.proto.GameObjectType;
|
||||
import ru.m.tankz.proto.GameChangeType;
|
||||
import ru.m.tankz.game.ClientTankz;
|
||||
import ru.m.tankz.engine.ClientEngine;
|
||||
import protohx.Message;
|
||||
import ru.m.tankz.proto.GameUpdateResponse;
|
||||
import ru.m.core.connect.IConnection;
|
||||
@@ -22,27 +22,27 @@ class GameFrame extends VGroupView implements ViewBuilder implements IPacketHand
|
||||
|
||||
public static inline var ID = "game";
|
||||
|
||||
private var game:ClientTankz;
|
||||
private var engine:ClientEngine;
|
||||
|
||||
public function init():Void {
|
||||
game = new ClientTankz();
|
||||
engine = new ClientEngine();
|
||||
}
|
||||
|
||||
public function onShow():Void {
|
||||
var person = Provider.get(GameData).person;
|
||||
var persons = Provider.get(GameData).game.persons;
|
||||
name.text = person.name;
|
||||
game.personId = person.id;
|
||||
game.init(persons, DEFAULT.CONFIG);
|
||||
engine.personId = person.id;
|
||||
engine.init(persons, DEFAULT.CONFIG);
|
||||
content.addEventListener(Event.ENTER_FRAME, updateGame);
|
||||
Provider.get(IConnection).packetHandler.addListener(this);
|
||||
render.draw(game);
|
||||
render.draw(engine);
|
||||
}
|
||||
|
||||
public function onHide():Void {
|
||||
Provider.get(IConnection).packetHandler.removeListener(this);
|
||||
content.removeEventListener(Event.ENTER_FRAME, updateGame);
|
||||
game.clear();
|
||||
engine.clear();
|
||||
}
|
||||
|
||||
private function updateGame(_):Void {
|
||||
@@ -56,7 +56,7 @@ class GameFrame extends VGroupView implements ViewBuilder implements IPacketHand
|
||||
case GameChangeType.DIRECTION:
|
||||
switch (change.objectType) {
|
||||
case GameObjectType.TANK:
|
||||
for (tank in game.tanks) {
|
||||
for (tank in engine.tanks) {
|
||||
if (tank.id == change.objectId) {
|
||||
tank.direction = new Direction(change.directionX, change.directionY);
|
||||
break;
|
||||
@@ -66,7 +66,7 @@ class GameFrame extends VGroupView implements ViewBuilder implements IPacketHand
|
||||
case GameChangeType.MOVED:
|
||||
switch (change.objectType) {
|
||||
case GameObjectType.TANK:
|
||||
for (tank in game.tanks) {
|
||||
for (tank in engine.tanks) {
|
||||
if (tank.id == change.objectId) {
|
||||
tank.x = change.x;
|
||||
tank.y = change.y;
|
||||
@@ -77,7 +77,7 @@ class GameFrame extends VGroupView implements ViewBuilder implements IPacketHand
|
||||
case GameChangeType.APPEND:
|
||||
switch (change.objectType) {
|
||||
case GameObjectType.BULLET:
|
||||
for (tank in game.tanks) {
|
||||
for (tank in engine.tanks) {
|
||||
if (tank.id == change.parentObjectId) {
|
||||
tank.bullets.push(new MobileEntity(0, change.x, change.y, 0, new Direction(change.directionX, change.directionY)));
|
||||
break;
|
||||
@@ -86,7 +86,7 @@ class GameFrame extends VGroupView implements ViewBuilder implements IPacketHand
|
||||
}
|
||||
}
|
||||
}
|
||||
render.draw(game);
|
||||
render.draw(engine);
|
||||
}
|
||||
|
||||
public function onPacket(packet:Message):Void {}
|
||||
|
||||
Reference in New Issue
Block a user