[common] bullet with bricks collision

This commit is contained in:
2018-01-07 20:33:05 +03:00
parent 12328a8a5e
commit 348d31d754
33 changed files with 277 additions and 217 deletions

View File

@@ -0,0 +1,29 @@
package ru.m.geom;
import haxe.ds.IntMap;
class Direction {
private static var directions:IntMap<Direction> = new IntMap<Direction>();
public static var LEFT(default, null) = new Direction(-1, 0);
public static var TOP(default, null) = new Direction(0, -1);
public static var RIGHT(default, null) = new Direction(1, 0);
public static var BOTTOM(default, null) = new Direction(0, 1);
public var x(default, null):Int;
public var y(default, null):Int;
private function new(x, y) {
this.x = x;
this.y = y;
directions.set(x + y * 10, this);
}
public function reverse():Direction {
return from(-x, -y);
}
public static function from(x:Int, y:Int):Direction {
return directions.get(x + y * 10);
}
}

View File

@@ -0,0 +1,15 @@
package ru.m.geom;
class Point {
public var x(default, default):Float;
public var y(default, default):Float;
public function new(x:Float, y:Float) {
this.x = x;
this.y = y;
}
public function add(point:Point):Point {
return new Point(x + point.x, y + point.y);
}
}

View File

@@ -0,0 +1,31 @@
package ru.m.geom;
class Rectangle {
public var x(default, default):Float;
public var y(default, default):Float;
public var width(default, default):Float;
public var height(default, default):Float;
public var center(get, set):Point;
public function new(x:Float, y:Float, width:Float, height:Float) {
this.x = x;
this.y = y;
this.width = width;
this.height = height;
}
private function get_center():Point {
return new Point(x + width / 2, y + height / 2);
}
private function set_center(value:Point):Point {
this.x = value.x - width / 2;
this.y = value.y - height / 2;
return value;
}
public function getSide(direction:Direction):Point {
return center.add(new Point(direction.x * width / 2, direction.y * height / 2));
}
}