[common] update control binding
This commit is contained in:
@@ -24,7 +24,8 @@ class Bot extends Control {
|
|||||||
}
|
}
|
||||||
|
|
||||||
override public function start():Void {
|
override public function start():Void {
|
||||||
action(TankAction.MOVE(Direction.BOTTOM));
|
var tank = handler.entities.get(tankId);
|
||||||
|
action(TankAction.MOVE(tank.rect.direction));
|
||||||
if (shotTimer == null) {
|
if (shotTimer == null) {
|
||||||
shotTimer = new Timer(1000);
|
shotTimer = new Timer(1000);
|
||||||
shotTimer.run = shot;
|
shotTimer.run = shot;
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package ru.m.tankz.control;
|
package ru.m.tankz.control;
|
||||||
|
|
||||||
|
import ru.m.tankz.core.Entity;
|
||||||
import ru.m.tankz.core.EntityType;
|
import ru.m.tankz.core.EntityType;
|
||||||
import ru.m.geom.Direction;
|
import ru.m.geom.Direction;
|
||||||
|
|
||||||
@@ -14,17 +15,17 @@ enum TankAction {
|
|||||||
|
|
||||||
class Control {
|
class Control {
|
||||||
public var tankId(default, default):Int;
|
public var tankId(default, default):Int;
|
||||||
private var listener:ControlListener;
|
private var handler:ControlHandler;
|
||||||
|
|
||||||
public function new() {}
|
public function new() {}
|
||||||
|
|
||||||
public function bind(listener:ControlListener):Void {
|
public function bind(handler:ControlHandler):Void {
|
||||||
this.listener = listener;
|
this.handler = handler;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function action(action:TankAction):Void {
|
public function action(action:TankAction):Void {
|
||||||
if (tankId != 0 && listener != null) {
|
if (tankId != 0 && handler != null) {
|
||||||
listener.onAction(tankId, action);
|
handler.action(tankId, action);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -38,10 +39,11 @@ class Control {
|
|||||||
|
|
||||||
public function dispose():Void {
|
public function dispose():Void {
|
||||||
stop();
|
stop();
|
||||||
listener = null;
|
handler = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
interface ControlListener {
|
interface ControlHandler {
|
||||||
public function onAction(tankId:Int, action:TankAction):Void;
|
public var entities(default, null):Map<Int, Entity>;
|
||||||
|
public function action(tankId:Int, action:TankAction):Void;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -73,7 +73,7 @@ class CollisionProcessor implements EngineListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
class Engine {
|
class Engine implements ControlHandler {
|
||||||
|
|
||||||
public var config(default, default):Config;
|
public var config(default, default):Config;
|
||||||
public var map(default, null):LevelMap;
|
public var map(default, null):LevelMap;
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ typedef PlayerId = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
class Game implements EngineListener implements ControlListener {
|
class Game implements EngineListener {
|
||||||
|
|
||||||
public var type(default, null):GameType;
|
public var type(default, null):GameType;
|
||||||
public var teams(default, null):Map<TeamId, Team>;
|
public var teams(default, null):Map<TeamId, Team>;
|
||||||
@@ -94,7 +94,7 @@ class Game implements EngineListener implements ControlListener {
|
|||||||
player.control.dispose();
|
player.control.dispose();
|
||||||
}
|
}
|
||||||
player.control = control;
|
player.control = control;
|
||||||
player.control.bind(this);
|
player.control.bind(engine);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user