[engine] fix
This commit is contained in:
@@ -35,14 +35,16 @@ class BrickState implements IState<Brick> {
|
|||||||
class EntityState implements IState<Entity> {
|
class EntityState implements IState<Entity> {
|
||||||
private var x:Float;
|
private var x:Float;
|
||||||
private var y:Float;
|
private var y:Float;
|
||||||
|
private var d:Direction;
|
||||||
private var type:Int;
|
private var type:Int;
|
||||||
|
|
||||||
public function new() {}
|
public function new() {}
|
||||||
|
|
||||||
public function update(object:Entity):Bool {
|
public function update(object:Entity):Bool {
|
||||||
if (x != object.rect.x || y != object.rect.y) {
|
if (x != object.rect.x || y != object.rect.y || !d.equals(object.rect.direction)) {
|
||||||
x = object.rect.x;
|
x = object.rect.x;
|
||||||
y = object.rect.y;
|
y = object.rect.y;
|
||||||
|
d = object.rect.direction;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (Std.is(object, Tank)) {
|
if (Std.is(object, Tank)) {
|
||||||
|
|||||||
@@ -23,6 +23,10 @@ class Direction {
|
|||||||
return from(-x, -y);
|
return from(-x, -y);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function equals(other:Direction):Bool {
|
||||||
|
return other.x == x && other.y == y;
|
||||||
|
}
|
||||||
|
|
||||||
public static function from(x:Int, y:Int):Direction {
|
public static function from(x:Int, y:Int):Direction {
|
||||||
return directions.get(x + y * 10);
|
return directions.get(x + y * 10);
|
||||||
}
|
}
|
||||||
@@ -36,4 +40,8 @@ class Direction {
|
|||||||
case _: null;
|
case _: null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function toString():String {
|
||||||
|
return 'Direction{x=$x,y=$y}';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -46,10 +46,10 @@ class Tank extends MobileEntity {
|
|||||||
|
|
||||||
override public function move(direction:Direction):Void {
|
override public function move(direction:Direction):Void {
|
||||||
// ToDo: spike
|
// ToDo: spike
|
||||||
if (direction != this.direction) {
|
/*if (direction != this.direction) {
|
||||||
rect.x -= this.direction.x * 4;
|
rect.x -= this.direction.x * 4;
|
||||||
rect.y -= this.direction.y * 4;
|
rect.y -= this.direction.y * 4;
|
||||||
}
|
}*/
|
||||||
super.move(direction);
|
super.move(direction);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user