[bot] fixes
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "tankz",
|
"name": "tankz",
|
||||||
"version": "0.0.6",
|
"version": "0.0.7",
|
||||||
"private": true,
|
"private": true,
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"ansi-colors": "^1.0.1",
|
"ansi-colors": "^1.0.1",
|
||||||
|
|||||||
@@ -38,7 +38,8 @@ class GameFrame extends VGroupView implements ViewBuilder implements IPacketHand
|
|||||||
content.addEventListener(Event.ENTER_FRAME, redraw);
|
content.addEventListener(Event.ENTER_FRAME, redraw);
|
||||||
for (index in 0...game.players.length) {
|
for (index in 0...game.players.length) {
|
||||||
var playerId:Int = game.players[index].id;
|
var playerId:Int = game.players[index].id;
|
||||||
controls.set(engine.playerTanks.get(playerId).id, PlayerControl.forPlayer(index, playerId, engine));
|
var tankId:Int = engine.playerTanks.get(playerId).id;
|
||||||
|
controls.set(tankId, PlayerControl.forPlayer(index, tankId, engine));
|
||||||
}
|
}
|
||||||
Provider.get(IConnection).packetHandler.addListener(this);
|
Provider.get(IConnection).packetHandler.addListener(this);
|
||||||
render.draw(engine);
|
render.draw(engine);
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ class Bot implements EngineListener {
|
|||||||
private var engine:Engine;
|
private var engine:Engine;
|
||||||
|
|
||||||
private var shotTimer:Timer;
|
private var shotTimer:Timer;
|
||||||
|
private var turnTimer:Timer;
|
||||||
|
|
||||||
public function new(engine:Engine, tankId:Int) {
|
public function new(engine:Engine, tankId:Int) {
|
||||||
this.engine = engine;
|
this.engine = engine;
|
||||||
@@ -34,6 +35,8 @@ class Bot implements EngineListener {
|
|||||||
engine.action(tankId, TankAction.MOVE(Direction.BOTTOM));
|
engine.action(tankId, TankAction.MOVE(Direction.BOTTOM));
|
||||||
shotTimer = new Timer(1000);
|
shotTimer = new Timer(1000);
|
||||||
shotTimer.run = shot;
|
shotTimer.run = shot;
|
||||||
|
turnTimer = new Timer(3000);
|
||||||
|
turnTimer.run = turn;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function shot():Void {
|
public function shot():Void {
|
||||||
@@ -41,7 +44,16 @@ class Bot implements EngineListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function turn():Void {
|
public function turn():Void {
|
||||||
engine.action(tankId, TankAction.MOVE(Direction.TOP));
|
engine.action(tankId, TankAction.MOVE(randomDirection()));
|
||||||
|
}
|
||||||
|
|
||||||
|
private function randomDirection():Direction {
|
||||||
|
return [
|
||||||
|
Direction.TOP,
|
||||||
|
Direction.BOTTOM,
|
||||||
|
Direction.LEFT,
|
||||||
|
Direction.RIGHT,
|
||||||
|
][Math.floor(Math.random() * 4)];
|
||||||
}
|
}
|
||||||
|
|
||||||
public function dispose():Void {
|
public function dispose():Void {
|
||||||
@@ -49,6 +61,10 @@ class Bot implements EngineListener {
|
|||||||
shotTimer.stop();
|
shotTimer.stop();
|
||||||
shotTimer = null;
|
shotTimer = null;
|
||||||
}
|
}
|
||||||
|
if (turnTimer != null) {
|
||||||
|
turnTimer.stop();
|
||||||
|
turnTimer = null;
|
||||||
|
}
|
||||||
engine = null;
|
engine = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -91,6 +91,7 @@ class Engine {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function action(tankId:Int, action:TankAction):Void {
|
public function action(tankId:Int, action:TankAction):Void {
|
||||||
|
if (!entities.exists(tankId)) return;
|
||||||
var tank:Tank = cast entities.get(tankId);
|
var tank:Tank = cast entities.get(tankId);
|
||||||
switch (action) {
|
switch (action) {
|
||||||
case TankAction.MOVE(direction):
|
case TankAction.MOVE(direction):
|
||||||
@@ -184,7 +185,7 @@ class Engine {
|
|||||||
removedEntities.push(entity.key);
|
removedEntities.push(entity.key);
|
||||||
if (Std.is(entity, Bullet)) {
|
if (Std.is(entity, Bullet)) {
|
||||||
var tank:Tank = cast entities.get(cast(entity, Bullet).tankId);
|
var tank:Tank = cast entities.get(cast(entity, Bullet).tankId);
|
||||||
tank.onDestroyBullet();
|
if (tank != null) tank.onDestroyBullet();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (bots.exists(entity.id)) {
|
if (bots.exists(entity.id)) {
|
||||||
|
|||||||
Reference in New Issue
Block a user