Add gameover and overall layout
Co-authored-by: Copilot <copilot@github.com>
This commit is contained in:
@@ -5,7 +5,8 @@ export const GAME_COLORS = {
|
||||
movingPlat: '#4cc9f0',
|
||||
springPlat: '#80ed99',
|
||||
oneTimePlat: '#e76f51',
|
||||
startingPlat: '#f4a261' };
|
||||
startingPlat: '#f4a261'
|
||||
};
|
||||
|
||||
export const PLATFORMS_GAP = 80;
|
||||
export const PLATFORM_WIDHT = 70;
|
||||
@@ -17,5 +18,3 @@ export const PLAT_TYPE = {
|
||||
SPRING: 'spring',
|
||||
ONE_TIME: 'one-time'
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -1,51 +1,46 @@
|
||||
import { updatePlayerPosition } from './gameUtils.js';
|
||||
import { initPlatforms, moveWorld} from './platforms.js';
|
||||
import { updatePlayerPosition, createPlayer } from './gameUtils.js';
|
||||
import { initPlatforms, moveWorld } from './platforms.js';
|
||||
import { GAME_COLORS, PLATFORMS_GAP } from './constants.js';
|
||||
|
||||
// Game state
|
||||
let player;
|
||||
let platforms;
|
||||
let pendingWorldMove = 0;
|
||||
let gameOver = false;
|
||||
|
||||
export function getScore() {
|
||||
return (player?.elevation ?? 0);
|
||||
return (player?.elevation ?? 0) / PLATFORMS_GAP * 10;
|
||||
}
|
||||
|
||||
function createPlayer() {
|
||||
player = new Sprite();
|
||||
player.x = width / 2;
|
||||
player.y = 700;
|
||||
|
||||
player.scale = 0.20;
|
||||
player.img = "assets/nubzuki.png";
|
||||
|
||||
player.rotationLock = true;
|
||||
|
||||
player.w = 20;
|
||||
player.h = 20;
|
||||
player.offset.y = 25;
|
||||
|
||||
player.bounciness = 0;
|
||||
player.elevation = 0;
|
||||
return player;
|
||||
export function isGameOver() {
|
||||
return gameOver;
|
||||
}
|
||||
|
||||
export function resetGame() {
|
||||
allSprites.remove();
|
||||
|
||||
pendingWorldMove = 0;
|
||||
gameOver = false;
|
||||
|
||||
export function initializeGame() {
|
||||
//world.debug = true; //TODO remove
|
||||
//allSprites.debug = true; //TODO remove
|
||||
world.gravity.y = 10;
|
||||
platforms = initPlatforms();
|
||||
player = createPlayer();
|
||||
}
|
||||
|
||||
export function initializeGame() {
|
||||
world.gravity.y = 10;
|
||||
resetGame();
|
||||
}
|
||||
|
||||
export function updateGame() {
|
||||
clear();
|
||||
background(GAME_COLORS.background);
|
||||
|
||||
|
||||
if (gameOver) {
|
||||
return;
|
||||
}
|
||||
|
||||
pendingWorldMove += updatePlayerPosition(player, platforms);
|
||||
|
||||
|
||||
if (pendingWorldMove > PLATFORMS_GAP) {
|
||||
const move = Math.min(pendingWorldMove, 5);
|
||||
pendingWorldMove -= move;
|
||||
@@ -53,13 +48,15 @@ export function updateGame() {
|
||||
player.y += move;
|
||||
player.bounciness = 0;
|
||||
}
|
||||
|
||||
player.rotation = player.vel.x * 1.5;
|
||||
|
||||
if (player.y > height) {
|
||||
gameOver = true;
|
||||
}
|
||||
|
||||
// UI
|
||||
fill(0);
|
||||
textSize(24);
|
||||
textSize(40);
|
||||
textAlign(RIGHT);
|
||||
text(`${Math.floor(player.elevation)}`, width - 20, 30);
|
||||
text(getScore(), width - 20, 50);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,24 @@
|
||||
import { PLAT_TYPE } from './constants.js';
|
||||
|
||||
export function createPlayer() {
|
||||
const player = new Sprite();
|
||||
player.x = width / 2;
|
||||
player.y = 700;
|
||||
|
||||
player.scale = 0.20;
|
||||
player.img = "assets/nubzuki.png";
|
||||
|
||||
player.rotationLock = true;
|
||||
|
||||
player.w = 20;
|
||||
player.h = 20;
|
||||
player.offset.y = 25;
|
||||
|
||||
player.bounciness = 0;
|
||||
player.elevation = 0;
|
||||
return player;
|
||||
}
|
||||
|
||||
|
||||
function handleJump(player, platform) {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user