last polishing of code
This commit is contained in:
@@ -8,12 +8,9 @@ let platforms;
|
|||||||
let pendingWorldMove = 0;
|
let pendingWorldMove = 0;
|
||||||
let gameOver = false;
|
let gameOver = false;
|
||||||
|
|
||||||
export function getScore() {
|
export function initializeGame() {
|
||||||
return (player?.elevation ?? 0) / PLATFORMS_GAP * 10;
|
world.gravity.y = 10;
|
||||||
}
|
resetGame();
|
||||||
|
|
||||||
export function isGameOver() {
|
|
||||||
return gameOver;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function resetGame() {
|
export function resetGame() {
|
||||||
@@ -24,11 +21,6 @@ export function resetGame() {
|
|||||||
player = createPlayer();
|
player = createPlayer();
|
||||||
}
|
}
|
||||||
|
|
||||||
export function initializeGame() {
|
|
||||||
world.gravity.y = 10;
|
|
||||||
resetGame();
|
|
||||||
}
|
|
||||||
|
|
||||||
export function updateGame() {
|
export function updateGame() {
|
||||||
clear();
|
clear();
|
||||||
background(GAME_COLORS.background);
|
background(GAME_COLORS.background);
|
||||||
@@ -40,6 +32,7 @@ export function updateGame() {
|
|||||||
pendingWorldMove += movePlayer(player, platforms);
|
pendingWorldMove += movePlayer(player, platforms);
|
||||||
player.rotation = player.vel.x * 1.5;
|
player.rotation = player.vel.x * 1.5;
|
||||||
|
|
||||||
|
// move
|
||||||
if (pendingWorldMove > PLATFORMS_GAP) {
|
if (pendingWorldMove > PLATFORMS_GAP) {
|
||||||
const move = Math.min(pendingWorldMove, 5);
|
const move = Math.min(pendingWorldMove, 5);
|
||||||
pendingWorldMove -= move;
|
pendingWorldMove -= move;
|
||||||
@@ -57,3 +50,12 @@ export function updateGame() {
|
|||||||
textAlign(RIGHT);
|
textAlign(RIGHT);
|
||||||
text(getScore(), width - 20, 50);
|
text(getScore(), width - 20, 50);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
export function getScore() {
|
||||||
|
return (player?.elevation ?? 0) / PLATFORMS_GAP * 10;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function isGameOver() {
|
||||||
|
return gameOver;
|
||||||
|
}
|
||||||
@@ -14,7 +14,6 @@ function drawSpringPlatform() {
|
|||||||
noStroke();
|
noStroke();
|
||||||
textAlign(CENTER, CENTER);
|
textAlign(CENTER, CENTER);
|
||||||
textSize(15);
|
textSize(15);
|
||||||
//textStyle(BOLD);
|
|
||||||
text('⮝ ⮝ ⮝', 0, 2);
|
text('⮝ ⮝ ⮝', 0, 2);
|
||||||
textStyle(NORMAL);
|
textStyle(NORMAL);
|
||||||
}
|
}
|
||||||
@@ -51,8 +50,6 @@ function addMovingBehavior(platform) {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
export function addTypeSpecifics(platform, type) {
|
export function addTypeSpecifics(platform, type) {
|
||||||
switch (platform.type) {
|
switch (platform.type) {
|
||||||
case PLAT_TYPE.MOVING:
|
case PLAT_TYPE.MOVING:
|
||||||
|
|||||||
@@ -20,7 +20,6 @@ export function createPlayer() {
|
|||||||
|
|
||||||
|
|
||||||
function handleJump(player, platform) {
|
function handleJump(player, platform) {
|
||||||
|
|
||||||
let elevationGain = 0;
|
let elevationGain = 0;
|
||||||
if (player.elevation < platform.elevation) {
|
if (player.elevation < platform.elevation) {
|
||||||
elevationGain = platform.elevation - player.elevation;
|
elevationGain = platform.elevation - player.elevation;
|
||||||
@@ -52,7 +51,6 @@ export function movePlayer(player, platforms) {
|
|||||||
player.vel.x = 5;
|
player.vel.x = 5;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Wrap horizontally
|
// Wrap horizontally
|
||||||
if (player.x > width) {
|
if (player.x > width) {
|
||||||
player.x = 0;
|
player.x = 0;
|
||||||
|
|||||||
Reference in New Issue
Block a user