upgraded movement and platforms generation

Co-authored-by: Copilot <copilot@github.com>
This commit is contained in:
2026-04-27 14:49:48 +09:00
parent 498efb70df
commit d79726cae4
3 changed files with 80 additions and 48 deletions

View File

@@ -1,9 +1,6 @@
// Game utilities for player controls and movement
export function updatePlayerPosition(player, platforms) {
let elevationGain = 0;
// Controls
player.vel.x = 0;
if (keyIsDown(LEFT_ARROW)) {
@@ -13,6 +10,13 @@ export function updatePlayerPosition(player, platforms) {
player.vel.x = 5;
}
// Wrap horizontally around canvas edges
if (player.x > width) {
player.x = 0;
} else if (player.x < 0) {
player.x = width;
}
// Jumping thrue platforms
for (let plat of platforms) {
if (player.vel.y <= 0 && player.y > plat.y) {
@@ -22,26 +26,20 @@ export function updatePlayerPosition(player, platforms) {
}
}
// 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;
if(player.vel.y >= 0) {
for (let plat of platforms) {
if (player.colliding(plat)) {
player.vel.y = -7.5;
if (player.elevation < plat.elevation) {
elevationGain = plat.elevation - player.elevation;
player.elevation = plat.elevation;
}
break;
}
});
}
}
// Wrap horizontally around canvas edges
if (player.x > width) {
player.x = 0;
} else if (player.x < 0) {
player.x = width;
}
return elevationGain;
}