update
This commit is contained in:
@@ -13,8 +13,8 @@ class PlayerTank extends Tank {
|
||||
private var keyBinding:Map<Int, TankAction>;
|
||||
private var moveQueue:Array<Int>;
|
||||
|
||||
public function new(id:Int, x:Float, y:Float, keyBinding:Map<Int, TankAction>) {
|
||||
super(id, x, y);
|
||||
public function new(personId:Int, id:Int, x:Float, y:Float, direction:Direction, keyBinding:Map<Int, TankAction>) {
|
||||
super(personId, id, x, y, direction);
|
||||
this.keyBinding = keyBinding;
|
||||
moveQueue = new Array<Int>();
|
||||
Lib.current.stage.addEventListener(KeyboardEvent.KEY_DOWN, onKeyDown);
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
package ru.m.tankz.engine;
|
||||
|
||||
import ru.m.tankz.core.Direction;
|
||||
import ru.m.tankz.core.Tank.TankAction;
|
||||
import ru.m.tankz.core.Tank;
|
||||
import flash.ui.Keyboard;
|
||||
import ru.m.tankz.core.PlayerTank;
|
||||
import ru.m.tankz.core.ITank;
|
||||
|
||||
class ClientEngine extends Engine {
|
||||
|
||||
@@ -14,9 +13,9 @@ class ClientEngine extends Engine {
|
||||
super();
|
||||
}
|
||||
|
||||
override private function buildTank(id:Int, x:Float, y:Float):ITank {
|
||||
return if (id == personId) {
|
||||
new PlayerTank(id, x, y, [
|
||||
override private function buildTank(personId:Int, id:Int, x:Float, y:Float, direction:Direction):Tank {
|
||||
return if (this.personId == personId) {
|
||||
new PlayerTank(personId, id, x, y, direction, [
|
||||
Keyboard.A => TankAction.MOVE(Direction.LEFT),
|
||||
Keyboard.S => TankAction.MOVE(Direction.BOTTOM),
|
||||
Keyboard.W => TankAction.MOVE(Direction.TOP),
|
||||
@@ -24,7 +23,7 @@ class ClientEngine extends Engine {
|
||||
Keyboard.SPACE => TankAction.SHOT
|
||||
]);
|
||||
} else {
|
||||
super.buildTank(id, x, y);
|
||||
super.buildTank(personId, id, x, y, direction);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package ru.m.tankz.render;
|
||||
|
||||
import ru.m.tankz.core.Bullet;
|
||||
import ru.m.tankz.core.Tank;
|
||||
import flash.display.Sprite;
|
||||
import flash.display.Graphics;
|
||||
import haxework.gui.SpriteView;
|
||||
@@ -46,22 +48,23 @@ class Render extends SpriteView implements IRender {
|
||||
|
||||
var g:Graphics = tankLayer.graphics;
|
||||
g.clear();
|
||||
for (tank in game.tanks) {
|
||||
g.beginFill(0xff0000);
|
||||
g.drawRect(tank.x, tank.y, tank.width, tank.height);
|
||||
g.endFill();
|
||||
g.beginFill(0x990000);
|
||||
g.drawRect(
|
||||
tank.x + tank.width / 2 - tank.width / 8 + tank.direction.x * tank.width / 4,
|
||||
tank.y + tank.height / 2 - tank.height / 8 + tank.direction.y * tank.height / 4,
|
||||
tank.width / 4,
|
||||
tank.height / 4
|
||||
);
|
||||
g.endFill();
|
||||
|
||||
for (bullet in tank.bullets) {
|
||||
for (e in game.mobileEntities) {
|
||||
if (Std.is(e, Tank)) {
|
||||
g.beginFill(0xff0000);
|
||||
g.drawRect(bullet.x, bullet.y, bullet.width, bullet.height);
|
||||
g.drawRect(e.x, e.y, e.width, e.height);
|
||||
g.endFill();
|
||||
g.beginFill(0x990000);
|
||||
g.drawRect(
|
||||
e.x + e.width / 2 - e.width / 8 + e.direction.x * e.width / 4,
|
||||
e.y + e.height / 2 - e.height / 8 + e.direction.y * e.height / 4,
|
||||
e.width / 4,
|
||||
e.height / 4
|
||||
);
|
||||
g.endFill();
|
||||
} else if (Std.is(e, Bullet)) {
|
||||
g.beginFill(0xff0000);
|
||||
g.drawRect(e.x, e.y, e.width, e.height);
|
||||
g.endFill();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,5 @@
|
||||
package ru.m.tankz.view.frames;
|
||||
|
||||
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.engine.ClientEngine;
|
||||
import protohx.Message;
|
||||
import ru.m.tankz.proto.GameUpdateResponse;
|
||||
@@ -33,7 +29,7 @@ class GameFrame extends VGroupView implements ViewBuilder implements IPacketHand
|
||||
var persons = Provider.get(GameData).game.persons;
|
||||
name.text = person.name;
|
||||
engine.personId = person.id;
|
||||
engine.init(persons, DEFAULT.CONFIG);
|
||||
engine.init(DEFAULT.CONFIG);
|
||||
content.addEventListener(Event.ENTER_FRAME, updateGame);
|
||||
Provider.get(IConnection).packetHandler.addListener(this);
|
||||
render.draw(engine);
|
||||
@@ -51,57 +47,7 @@ class GameFrame extends VGroupView implements ViewBuilder implements IPacketHand
|
||||
}
|
||||
|
||||
public function onGameUpdateResponse(packet:GameUpdateResponse):Void {
|
||||
for (change in packet.changes) {
|
||||
switch (change.type) {
|
||||
case GameChangeType.DIRECTION:
|
||||
switch (change.objectType) {
|
||||
case GameObjectType.TANK:
|
||||
for (tank in engine.tanks) {
|
||||
if (tank.id == change.objectId) {
|
||||
tank.direction = new Direction(change.directionX, change.directionY);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
case GameChangeType.MOVED:
|
||||
switch (change.objectType) {
|
||||
case GameObjectType.TANK:
|
||||
for (tank in engine.tanks) {
|
||||
if (tank.id == change.objectId) {
|
||||
tank.x = change.x;
|
||||
tank.y = change.y;
|
||||
break;
|
||||
}
|
||||
}
|
||||
case GameObjectType.BULLET:
|
||||
for (tank in engine.tanks) {
|
||||
if (tank.id == change.parentObjectId) {
|
||||
for (bullet in tank.bullets) {
|
||||
if (bullet.id == change.objectId) {
|
||||
bullet.x = change.x;
|
||||
bullet.y = change.y;
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
case GameChangeType.APPEND:
|
||||
switch (change.objectType) {
|
||||
case GameObjectType.BULLET:
|
||||
for (tank in engine.tanks) {
|
||||
if (tank.id == change.parentObjectId) {
|
||||
var bullet = new MobileEntity(change.objectId, change.x, change.y, 0, new Direction(change.directionX, change.directionY));
|
||||
bullet.width = 10;
|
||||
bullet.height = 10;
|
||||
tank.bullets.push(bullet);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
engine.updateFromChanges(packet.changes);
|
||||
render.draw(engine);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user