basic version without world movement

Co-authored-by: Copilot <copilot@github.com>
This commit is contained in:
2026-04-25 14:23:45 +09:00
parent 3b0d5b4864
commit 5620f1860f
4 changed files with 114 additions and 16 deletions

47
src/game/gameUtils.js Normal file
View File

@@ -0,0 +1,47 @@
// Game utilities for player controls and movement
export function updatePlayerPosition(player, platforms) {
let elevationGain = 0;
// Controls
player.vel.x = 0;
if (keyIsDown(LEFT_ARROW)) {
player.vel.x = -5;
}
if (keyIsDown(RIGHT_ARROW)) {
player.vel.x = 5;
}
// Jumping thrue platforms
for (let plat of platforms) {
if (player.vel.y <= 0 && player.y > plat.y) {
plat.collider = 'none';
} else {
plat.collider = 'static';
}
}
// Automatic jumping
if (player.vel.y >= 0) {
player.collides(platforms, (player, platform) => {
player.vel.y = -7.5;
if (player.elevation < platform.elevation) {
elevationGain = platform.elevation - player.elevation;
player.elevation = platform.elevation;
}
});
}
// Wrap horizontally around canvas edges
if (player.x > width) {
player.x = 0;
} else if (player.x < 0) {
player.x = width;
}
return elevationGain;
}