From bb6a2052d75d9305245d11649748c82961255bd3 Mon Sep 17 00:00:00 2001 From: Richard Knoll Date: Thu, 14 Dec 2023 12:48:43 -0800 Subject: [PATCH] fix drawing and clear obstacles --- libs/game/physics.ts | 23 ++++++++--------------- libs/game/tilemap.ts | 17 +++++++++-------- 2 files changed, 17 insertions(+), 23 deletions(-) diff --git a/libs/game/physics.ts b/libs/game/physics.ts index f56a047ee..f2f61f547 100644 --- a/libs/game/physics.ts +++ b/libs/game/physics.ts @@ -130,6 +130,14 @@ class ArcadePhysicsEngine extends PhysicsEngine { // clear obstacles if moving on that axis this.sprites.forEach(s => { if (s.vx || s.vy) s.clearObstacles(); + else { + for (const ob of s._obstacles) { + if (ob && (ob.tilemap.vx || ob.tilemap.vy)) { + s.clearObstacles(); + break; + } + } + } }); this.map.clear(); @@ -1000,19 +1008,4 @@ function ___overlapsTilemap(sprite: Sprite, tilemap: tiles.TileMap) { } return false; -} - -function ___overlapsTile(sprite: Sprite, left: Fx8, top: Fx8, col: number, row: number, tileScale: number) { - left = Fx.iadd(col << tileScale, left); - top = Fx.iadd(row << tileScale, top); - - if ( - Fx.compare(sprite._hitbox.left, Fx.iadd(1 << tileScale, left)) > 0 || - Fx.compare(sprite._hitbox.top, Fx.iadd(1 << tileScale, top)) > 0 || - Fx.compare(sprite._hitbox.right, left) < 0 || - Fx.compare(sprite._hitbox.bottom, top) < 0 - ) { - return false; - } - return true; } \ No newline at end of file diff --git a/libs/game/tilemap.ts b/libs/game/tilemap.ts index 4a5683f08..329e37a84 100644 --- a/libs/game/tilemap.ts +++ b/libs/game/tilemap.ts @@ -469,13 +469,14 @@ namespace tiles { const offsetX = camera.drawOffsetX & bitmask; const offsetY = camera.drawOffsetY & bitmask; - const x0 = Math.max(0, camera.drawOffsetX >> this.scale); - const xn = Math.min(this._map.width, ((camera.drawOffsetX + target.width) >> this.scale) + 1); - const y0 = Math.max(0, camera.drawOffsetY >> this.scale); - const yn = Math.min(this._map.height, ((camera.drawOffsetY + target.height) >> this.scale) + 1); + const l = Fx.toInt(this.left) - camera.drawOffsetX; + const t = Fx.toInt(this.top) - camera.drawOffsetY; + + const x0 = Math.max(0, -l >> this.scale); + const xn = Math.min(this._map.width, ((-l + target.width) >> this.scale) + 1); + const y0 = Math.max(0, -t >> this.scale); + const yn = Math.min(this._map.height, ((-t + target.height) >> this.scale) + 1); - const l = Fx.toInt(this.left); - const t = Fx.toInt(this.top); for (let x = x0; x <= xn; ++x) { for (let y = y0; y <= yn; ++y) { @@ -484,8 +485,8 @@ namespace tiles { if (tile) { target.drawTransparentImage( tile, - l + ((x - x0) << this.scale) - offsetX, - t + ((y - y0) << this.scale) - offsetY + l + (x << this.scale), + t + (y << this.scale) ); } }