feat: Implement pixel-art rendering with new level loading, tile maps, palettes, and pixel fonts, alongside a game over screen.
This commit is contained in:
parent
5b15e63ac3
commit
cf04677511
41 changed files with 793 additions and 331 deletions
|
|
@ -1,4 +1,6 @@
|
|||
import { System } from '../core/System.js';
|
||||
import { PixelFont } from '../core/PixelFont.js';
|
||||
import { Palette } from '../core/Palette.js';
|
||||
|
||||
/**
|
||||
* System to handle game menus (start, pause)
|
||||
|
|
@ -31,11 +33,22 @@ export class MenuSystem extends System {
|
|||
this.startGame();
|
||||
} else if (this.gameState === 'paused') {
|
||||
this.resumeGame();
|
||||
} else if (this.gameState === 'gameOver') {
|
||||
this.restartGame();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
showGameOver() {
|
||||
this.gameState = 'gameOver';
|
||||
this.paused = true;
|
||||
}
|
||||
|
||||
restartGame() {
|
||||
window.location.reload(); // Simple and effective for this project
|
||||
}
|
||||
|
||||
startGame() {
|
||||
this.gameState = 'playing';
|
||||
this.paused = false;
|
||||
|
|
@ -75,27 +88,50 @@ export class MenuSystem extends System {
|
|||
const width = this.engine.canvas.width;
|
||||
const height = this.engine.canvas.height;
|
||||
|
||||
// Dark overlay
|
||||
ctx.fillStyle = 'rgba(0, 0, 0, 0.7)';
|
||||
// Darker overlay matching palette
|
||||
ctx.fillStyle = 'rgba(32, 21, 51, 0.8)'; // Semi-transparent VOID
|
||||
ctx.fillRect(0, 0, width, height);
|
||||
|
||||
ctx.fillStyle = '#ffffff';
|
||||
ctx.font = 'bold 48px Courier New';
|
||||
ctx.textAlign = 'center';
|
||||
ctx.textBaseline = 'middle';
|
||||
|
||||
if (this.gameState === 'start') {
|
||||
ctx.fillText('SLIME GENESIS', width / 2, height / 2 - 100);
|
||||
ctx.font = '24px Courier New';
|
||||
ctx.fillText('Press ENTER or SPACE to Start', width / 2, height / 2);
|
||||
ctx.font = '16px Courier New';
|
||||
ctx.fillText('WASD: Move | Mouse: Aim | Click/Space: Attack', width / 2, height / 2 + 50);
|
||||
ctx.fillText('Shift: Stealth | 1-9: Skills | ESC: Pause', width / 2, height / 2 + 80);
|
||||
const title = 'SLIME GENESIS';
|
||||
const titleW = PixelFont.getTextWidth(title, 2);
|
||||
PixelFont.drawText(ctx, title, (width - titleW) / 2, height / 2 - 40, Palette.CYAN, 2);
|
||||
|
||||
const start = 'PRESS ENTER TO START';
|
||||
const startW = PixelFont.getTextWidth(start, 1);
|
||||
PixelFont.drawText(ctx, start, (width - startW) / 2, height / 2, Palette.WHITE, 1);
|
||||
|
||||
const instructions = [
|
||||
'WASD: MOVE | CLICK: ATTACK',
|
||||
'NUMS: SKILLS | ESC: PAUSE',
|
||||
'COLLECT DNA TO EVOLVE'
|
||||
];
|
||||
|
||||
instructions.forEach((line, i) => {
|
||||
const lineW = PixelFont.getTextWidth(line, 1);
|
||||
PixelFont.drawText(ctx, line, (width - lineW) / 2, height / 2 + 25 + i * 10, Palette.ROYAL_BLUE, 1);
|
||||
});
|
||||
|
||||
} else if (this.gameState === 'paused') {
|
||||
ctx.fillText('PAUSED', width / 2, height / 2 - 50);
|
||||
ctx.font = '24px Courier New';
|
||||
ctx.fillText('Press ENTER or SPACE to Resume', width / 2, height / 2);
|
||||
ctx.fillText('Press ESC to Pause/Unpause', width / 2, height / 2 + 40);
|
||||
const paused = 'PAUSED';
|
||||
const pausedW = PixelFont.getTextWidth(paused, 2);
|
||||
PixelFont.drawText(ctx, paused, (width - pausedW) / 2, height / 2 - 20, Palette.SKY_BLUE, 2);
|
||||
|
||||
const resume = 'PRESS ENTER TO RESUME';
|
||||
const resumeW = PixelFont.getTextWidth(resume, 1);
|
||||
PixelFont.drawText(ctx, resume, (width - resumeW) / 2, height / 2 + 10, Palette.WHITE, 1);
|
||||
} else if (this.gameState === 'gameOver') {
|
||||
const dead = 'YOU PERISHED';
|
||||
const deadW = PixelFont.getTextWidth(dead, 2);
|
||||
PixelFont.drawText(ctx, dead, (width - deadW) / 2, height / 2 - 30, Palette.WHITE, 2);
|
||||
|
||||
const sub = 'YOUR DNA SUSTAINS THE CYCLE';
|
||||
const subW = PixelFont.getTextWidth(sub, 1);
|
||||
PixelFont.drawText(ctx, sub, (width - subW) / 2, height / 2 - 5, Palette.ROYAL_BLUE, 1);
|
||||
|
||||
const restart = 'PRESS ENTER TO REBORN';
|
||||
const restartW = PixelFont.getTextWidth(restart, 1);
|
||||
PixelFont.drawText(ctx, restart, (width - restartW) / 2, height / 2 + 30, Palette.CYAN, 1);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue