From 1452b287322db2994bdf05a2d820daae8045629c Mon Sep 17 00:00:00 2001 From: Arne van Iterson Date: Sun, 12 Apr 2020 14:03:06 +0200 Subject: [PATCH] Removed module that should not have been deleted --- lib/index.js | 2 ++ lib/movement/deadInTracks.js | 16 ++++++++++++++++ 2 files changed, 18 insertions(+) create mode 100644 lib/movement/deadInTracks.js 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