[common] player tank levels

This commit is contained in:
2018-01-08 22:28:35 +03:00
parent 3061a4088c
commit d3294a04f5
8 changed files with 125 additions and 30 deletions

View File

@@ -6,12 +6,14 @@ class Rectangle {
public var width(default, default):Float;
public var height(default, default):Float;
public var center(get, set):Point;
public var direction(default, set):Direction;
public function new(x:Float, y:Float, width:Float, height:Float) {
this.x = x;
this.y = y;
this.width = width;
this.height = height;
this.direction = Direction.RIGHT;
}
private function get_center():Point {
@@ -28,4 +30,17 @@ class Rectangle {
return center.add(new Point(direction.x * width / 2, direction.y * height / 2));
}
public function set_direction(value:Direction):Direction {
if (direction != value) {
if (direction != null && direction.x * value.x == 0 && direction.y * value.y == 0) {
var w = width;
var h = height;
width = h;
height = w;
}
direction = value;
}
return value;
}
}