[engine] fix position fix
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user