1 Star 0 Fork 0

sysdl132/platformre

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
stableplatscript.js 968 Bytes
一键复制 编辑 原始数据 按行查看 历史
function checkAxis(movement, currentCoord, otherCoord, isSolid, setPosition, onCollision, onNoCollision) {
const anchor = movement < 0 ? currentCoord : currentCoord + PLAYER_SIZE;
let next = movement < 0 ? Math.floor(anchor + Number.EPSILON) : Math.ceil(anchor - Number.EPSILON);
let collided = false;
while (movement < 0 ? next - anchor >= movement : next - anchor <= movement) {
const min = Math.floor(otherCoord);
const max = Math.ceil(otherCoord + PLAYER_SIZE);
const loc = movement < 0 ? next - 1 : next;
let collision = false;
for (let i = min; i < max; i++) if (isSolid(loc, i)) {
collision = true;
break;
}
if (collision) {
setPosition(movement < 0 ? next : next - PLAYER_SIZE);
if (onCollision) onCollision();
collided = true;
break;
}
movement < 0 ? next-- : next++;
}
if (!collided) {
setPosition(currentCoord + movement);
if (onNoCollision) onNoCollision();
}
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
HTML
1
https://gitee.com/sysdl132/platformre.git
git@gitee.com:sysdl132/platformre.git
sysdl132
platformre
platformre
master

搜索帮助

0d507c66 1850385 C8b1a773 1850385