[engine] remove tank grid align

This commit is contained in:
2018-01-16 21:59:11 +03:00
parent f5de852727
commit b3dfc42f0b
3 changed files with 11 additions and 6 deletions

View File

@@ -62,7 +62,7 @@ class Rectangle {
}
public function contain(point:Point):Bool {
return point.x >= x && point.y >= y && point.x <= width && point.y <= height;
return point.x >= left && point.y >= top && point.x <= right && point.y <= bottom;
}
public function intersection(rect:Rectangle):Bool {
@@ -72,6 +72,10 @@ class Rectangle {
rect.bottom < top);
}
public function intersection2(line:Line):Bool {
return contain(line.point1) || contain(line.point2);
}
public function lean(rect:Rectangle):Void {
var side = rect.getSide(direction);
if (direction.x != 0) {

View File

@@ -188,14 +188,14 @@ class Engine {
for (ent in entities) if (Std.is(ent, MobileEntity)) {
var entity:MobileEntity = cast ent;
if (Std.is(entity, Tank)) {
/*if (Std.is(entity, Tank)) {
if (entity.direction.x != 0) {
entity.rect.y = Math.round((entity.rect.y + entity.rect.height / 2) / map.cellHeight) * map.cellHeight - entity.rect.height / 2;
}
if (entity.direction.y != 0) {
entity.rect.x = Math.round((entity.rect.x + entity.rect.width / 2) / map.cellWidth) * map.cellWidth - entity.rect.width / 2;
}
}
}*/
if (entity.mx != 0 || entity.my != 0) {
entity.rect.x += entity.mx * (d / 30);
@@ -215,7 +215,8 @@ class Engine {
for (other in entities.iterator()) {
if (other != ent) {
if (ent.rect.intersection(other.rect)) {
if (other.rect.intersection2(side)) {
//if (ent.rect.intersection(other.rect)) {
var funName = 'collision${ent.type}${other.type}';
var fun:Function = Reflect.field(this, funName);
if (fun != null) {
@@ -228,7 +229,7 @@ class Engine {
if (Std.is(entity, Bullet)) {
var bullet:Bullet = cast ent;
if (collision) {
cells = map.grid.getCells(side.setLength(map.grid.cellWidth * 4));
cells = map.grid.getCells(side.setLength(map.grid.cellWidth * 3));
for (cell in cells) {
if (cell.armor > 0) {
if (cell.armor == bullet.config.piercing) {