[engine] fix position fix

This commit is contained in:
2019-04-17 22:38:37 +03:00
parent 4a4ca463c3
commit a3f3de3af5
2 changed files with 9 additions and 4 deletions

View File

@@ -10,6 +10,7 @@ import ru.m.tankz.core.Entity;
import ru.m.tankz.core.EntityType; import ru.m.tankz.core.EntityType;
import ru.m.tankz.core.MobileEntity; import ru.m.tankz.core.MobileEntity;
import ru.m.tankz.core.Tank; import ru.m.tankz.core.Tank;
import ru.m.tankz.map.Grid;
import ru.m.tankz.map.LevelMap; import ru.m.tankz.map.LevelMap;
import ru.m.tankz.Type; import ru.m.tankz.Type;
@@ -225,14 +226,14 @@ class Engine extends EngineDispatcher implements ControlHandler {
var collision:Bool = false; var collision:Bool = false;
for (cell in cells) { for (cell in cells) {
if (cell.layer >= entity.layer && cell.layer < 3) { if (cell.getCollision(entity.layer)) {
entity.rect.lean(cell.rect); entity.rect.lean(cell.rect);
collision = true; collision = true;
var with = EntityTypeResolver.of(cell); var with = EntityTypeResolver.of(cell);
collisionSignal.emit(entityType, with); collisionSignal.emit(entityType, with);
isStop = true; isStop = true;
// fix position // fix position
if (cells.length == 1) { if (cells.filter(function(c:GridCell) return c.getCollision(entity.layer)).length == 1) {
if (entity.mx != 0) { if (entity.mx != 0) {
var d = entity.rect.center.y - cell.rect.center.y; var d = entity.rect.center.y - cell.rect.center.y;
entity.rect.y += d / Math.abs(d); entity.rect.y += d / Math.abs(d);

View File

@@ -26,7 +26,7 @@ class GridCell {
this.destroyed = false; this.destroyed = false;
} }
public function set_destroyed(value:Bool):Bool { private function set_destroyed(value:Bool):Bool {
destroyed = value; destroyed = value;
if (destroyed) { if (destroyed) {
this.layer = 0; this.layer = 0;
@@ -34,6 +34,10 @@ class GridCell {
} }
return destroyed; return destroyed;
} }
public inline function getCollision(layer:Int):Bool {
return this.layer >= layer && this.layer < 3;
}
} }