From a3f3de3af5adad7be3177546e6eff70793ff9133 Mon Sep 17 00:00:00 2001 From: shmyga Date: Wed, 17 Apr 2019 22:38:37 +0300 Subject: [PATCH] [engine] fix position fix --- src/common/haxe/ru/m/tankz/engine/Engine.hx | 5 +++-- src/common/haxe/ru/m/tankz/map/Grid.hx | 8 ++++++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/common/haxe/ru/m/tankz/engine/Engine.hx b/src/common/haxe/ru/m/tankz/engine/Engine.hx index cf4f821..63b345a 100755 --- a/src/common/haxe/ru/m/tankz/engine/Engine.hx +++ b/src/common/haxe/ru/m/tankz/engine/Engine.hx @@ -10,6 +10,7 @@ import ru.m.tankz.core.Entity; import ru.m.tankz.core.EntityType; import ru.m.tankz.core.MobileEntity; import ru.m.tankz.core.Tank; +import ru.m.tankz.map.Grid; import ru.m.tankz.map.LevelMap; import ru.m.tankz.Type; @@ -225,14 +226,14 @@ class Engine extends EngineDispatcher implements ControlHandler { var collision:Bool = false; for (cell in cells) { - if (cell.layer >= entity.layer && cell.layer < 3) { + if (cell.getCollision(entity.layer)) { entity.rect.lean(cell.rect); collision = true; var with = EntityTypeResolver.of(cell); collisionSignal.emit(entityType, with); isStop = true; // fix position - if (cells.length == 1) { + if (cells.filter(function(c:GridCell) return c.getCollision(entity.layer)).length == 1) { if (entity.mx != 0) { var d = entity.rect.center.y - cell.rect.center.y; entity.rect.y += d / Math.abs(d); diff --git a/src/common/haxe/ru/m/tankz/map/Grid.hx b/src/common/haxe/ru/m/tankz/map/Grid.hx index d7670c4..bfa081c 100644 --- a/src/common/haxe/ru/m/tankz/map/Grid.hx +++ b/src/common/haxe/ru/m/tankz/map/Grid.hx @@ -26,7 +26,7 @@ class GridCell { this.destroyed = false; } - public function set_destroyed(value:Bool):Bool { + private function set_destroyed(value:Bool):Bool { destroyed = value; if (destroyed) { this.layer = 0; @@ -34,6 +34,10 @@ class GridCell { } return destroyed; } + + public inline function getCollision(layer:Int):Bool { + return this.layer >= layer && this.layer < 3; + } } @@ -77,4 +81,4 @@ class Grid { } return result; } -} \ No newline at end of file +}