started working on page style

Co-authored-by: Copilot <copilot@github.com>
This commit is contained in:
2026-04-28 23:14:30 +09:00
parent 7a0bca9938
commit 9939aab976
4 changed files with 98 additions and 31 deletions

View File

@@ -1,22 +1,85 @@
<script> <script>
import { onMount } from 'svelte'; import { initializeGame, updateGame, getScore } from './game/game.js';
import { initializeGame, updateGame } from './game/game.js';
let id; // the div in the HTML let game;
let score = $state(0);
window.setup = async () => { window.setup = () => {
createCanvas(400, 800).parent(id); createCanvas(400, 800).parent(game);
initializeGame(); initializeGame();
}; };
window.draw = () => { window.draw = () => {
updateGame(); updateGame();
score = getScore();
}; };
// On startup $effect(() => {
onMount(function () {
new p5(); new p5();
}); });
</script> </script>
<div {id}></div> <main class="page">
<h1>Nubzuki Jump</h1>
<div class="layout">
<aside class="scoreboard">
<h2>Score</h2>
<p>{score}</p>
</aside>
<div class="game-wrapper" bind:this={game}></div>
<aside class="right-panel"></aside>
</div>
</main>
<style>
.page {
min-height: 100vh;
background: #2b2d42;
color: white;
font-family: Arial, sans-serif;
text-align: center;
padding: 20px;
}
h1 {
margin: 0 0 20px;
font-size: 42px;
}
.layout {
display: grid;
grid-template-columns: 220px 400px 220px;
gap: 30px;
justify-content: center;
align-items: start;
}
.scoreboard {
background: rgba(255, 255, 255, 0.12);
border-radius: 16px;
padding: 20px;
}
.scoreboard h2 {
margin-top: 0;
}
.scoreboard p {
font-size: 36px;
font-weight: bold;
margin: 0;
}
.game-wrapper {
border-radius: 18px;
overflow: hidden;
box-shadow: 0 8px 30px rgba(0, 0, 0, 0.35);
}
.right-panel {
width: 220px;
}
</style>

View File

@@ -1,12 +1,11 @@
export const GAME_COLORS = { export const GAME_COLORS = {
background: '#e8e2d6', background: '#e8e2d6',
basicPlat: '#6c8ae4', basicPlat: '#6c8ae4',
movingPlat: '#4cc9f0', movingPlat: '#4cc9f0',
springPlat: '#80ed99', springPlat: '#80ed99',
oneTimePlat: '#e76f51', oneTimePlat: '#e76f51',
startingPlat: '#f4a261' startingPlat: '#f4a261' };
};
export const PLATFORMS_GAP = 80; export const PLATFORMS_GAP = 80;
export const PLATFORM_WIDHT = 70; export const PLATFORM_WIDHT = 70;

View File

@@ -7,6 +7,9 @@ let player;
let platforms; let platforms;
let pendingWorldMove = 0; let pendingWorldMove = 0;
export function getScore() {
return (player?.elevation ?? 0);
}
function createPlayer() { function createPlayer() {
player = new Sprite(); player = new Sprite();

View File

@@ -42,16 +42,14 @@ function drawOneTimePlatform() {
} }
function addMovingBehavior(platform) { function addMovingBehavior(platform) {
platform.direction = random() < 0.5 ? -1 : 1; platform.moveDir = random() < 0.5 ? -1 : 1;
platform.speed = random(1, 2); platform.moveSpeed = random(1, 2);
platform.update = function () {
platform.move = function () { this.x += this.moveDir * this.moveSpeed;
this.x += this.direction * this.speed; if (this.x < PLATFORM_WIDHT / 2 || this.x > width - PLATFORM_WIDHT / 2) {
this.moveDir *= -1;
if (this.x < this.w / 2 || this.x > width - this.w / 2) { }
this.direction *= -1; };
}
};
} }
@@ -88,11 +86,11 @@ function addTypeSpecifics(platform, type) {
function selectPlatformType(elevation) { function selectPlatformType(elevation) {
const r = random(); const r = random();
switch (true) { switch (true) {
case elevation >= 0 && r < 0.15: case elevation >= 200 && r < 0.15:
return PLAT_TYPE.ONE_TIME; return PLAT_TYPE.ONE_TIME;
case elevation >= 0 && r < 0.30: case elevation >= 200 && r < 0.30:
return PLAT_TYPE.MOVING; return PLAT_TYPE.MOVING;
case elevation >= 0 && r < 0.45: case elevation >= 200 && r < 0.45:
return PLAT_TYPE.SPRING; return PLAT_TYPE.SPRING;
default: default:
return PLAT_TYPE.BASIC; return PLAT_TYPE.BASIC;
@@ -162,11 +160,15 @@ export function moveWorld(platforms, elevation, move) {
export function initPlatforms() { export function initPlatforms() {
let platforms = new Group(); let platforms = new Group();
const basePlatform = createPlatform(width / 2, height - 10, 0, PLAT_TYPE.BASIC, true); const startingPlat = createPlatform(width / 2, height - 10, 0, PLAT_TYPE.BASIC, true);
basePlatform.color = GAME_COLORS.startingPlat; startingPlat.color = GAME_COLORS.startingPlat;
platforms.add(basePlatform); platforms.add(startingPlat);
let plarform1 = createPlatform(width / 4*3, height - PLATFORMS_GAP, PLATFORMS_GAP, PLAT_TYPE.BASIC);
platforms.add(plarform1);
let plarform2 = createPlatform(width / 4, height - PLATFORMS_GAP*2, PLATFORMS_GAP*2, PLAT_TYPE.BASIC);
platforms.add(plarform2);
generateNewPlatforms(platforms, basePlatform); generateNewPlatforms(platforms, plarform2);
return platforms; return platforms;
} }