diff --git a/package.json b/package.json index 9fb0d42..d59f69b 100755 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "tankz", - "version": "0.0.5", + "version": "0.0.6", "private": true, "devDependencies": { "ansi-colors": "^1.0.1", diff --git a/src/common/haxe/ru/m/geom/Rectangle.hx b/src/common/haxe/ru/m/geom/Rectangle.hx index c8d54e3..84a498a 100644 --- a/src/common/haxe/ru/m/geom/Rectangle.hx +++ b/src/common/haxe/ru/m/geom/Rectangle.hx @@ -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) { diff --git a/src/common/haxe/ru/m/tankz/engine/Engine.hx b/src/common/haxe/ru/m/tankz/engine/Engine.hx index 2f4a282..43063d7 100755 --- a/src/common/haxe/ru/m/tankz/engine/Engine.hx +++ b/src/common/haxe/ru/m/tankz/engine/Engine.hx @@ -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) {