diff --git a/lib/index.js b/lib/index.js index 0be923d..69dbb61 100644 --- a/lib/index.js +++ b/lib/index.js @@ -6,6 +6,7 @@ var AnimManager = require("./AnimManager.js"), math = require("./utilities/math.js"), entity = require("./utilities/entity.js"), wallslide = require("./movement/wallslide.js"), + deadInTracks = require("./movement/deadInTracks.js"), Sound = require("./sound/Sound.js"), Rect = require("./Rect.js"), KeyControls = require("./controls/KeyControls.js"), @@ -29,6 +30,7 @@ module.exports = { math, entity, wallslide, + deadInTracks, Sound, Rect, KeyControls, diff --git a/lib/movement/deadInTracks.js b/lib/movement/deadInTracks.js new file mode 100644 index 0000000..cc51fbf --- /dev/null +++ b/lib/movement/deadInTracks.js @@ -0,0 +1,16 @@ +const entity = require("../utilities/entity"); + +function deadInTracks(ent, map, x = 0, y = 0) { + const bounds = entity.bounds(ent); + const tiles = map.tilesAtCorners(bounds, x, y); + const walks = tiles.map(t => t && t.frame.walkable); + const blocked = walks.some(w => !w); + if (blocked) { + x = 0, + y = 0; + } + return { x, y }; +} +module.exports = { + deadInTracks +}; \ No newline at end of file