ソースコードです メモに書いてあります p5jsにて実行してください sketch.jsで
let player, goal, item; let enemies = []; let score = 0, highScore = 0; let started = false, fsButton, flash = 0, osc; class Player { constructor() { this.reset(); } reset() { this.x = 50; this.y = 50; this.speed = 1; this.powerUpTimer = 0; } update() { let moveSpeed = this.powerUpTimer > 0 ? this.speed + 5 : this.speed + 2; if (keyIsDown(32)) this.x += moveSpeed; else this.y += moveSpeed; if (this.powerUpTimer > 0) this.powerUpTimer--; if (this.x > width || this.y > height || this.x < 0 || this.y < 0) this.handlePenalty(); } handlePenalty() { score = max(0, score - 1); this.reset(); flash = 60; playSound(110, 0.5); } display() { fill(this.powerUpTimer > 0 ? 180 : 200, 80, 100); stroke(0, 0, 100); strokeWeight(3); ellipse(this.x, this.y, 50, 50); if (this.powerUpTimer > 0) { noFill(); stroke(180, 50, 100, 50); ellipse(this.x, this.y, 80, 80); } } } class Enemy { constructor() { this.x = random(width); this.y = random(height); this.vx = random(-2, 2); this.vy = random(-2, 2); } update() { let m = 1 + score * 0.05; this.x += this.vx * m; this.y += this.vy * m; if (this.x < 0 || this.x > width) this.vx *= -1; if (this.y < 0 || this.y > height) this.vy *= -1; } display() { fill(0, 80, 100); noStroke(); ellipse(this.x, this.y, 40, 40); } } class GameObject { constructor(c) { this.color = c; this.spawn(); } spawn() { this.x = random(100, width - 100); this.y = random(100, height - 100); this.active = true; } display(isRect = false) { if (!this.active) return; fill(this.color, 80, 100); if (isRect) { push(); translate(this.x, this.y); rotate(frameCount * 0.05); rect(0, 0, 30, 30); pop(); } else { ellipse(this.x, this.y, 60 + sin(frameCount * 0.1) * 10); } } } function setup() { createCanvas(windowWidth, windowHeight); colorMode(HSB, 360, 100, 100, 100); player = new Player(); goal = new GameObject(0); item = new GameObject(60); item.active = false; for (let i = 0; i < 3; i++) enemies.push(new Enemy()); fsButton = createButton('GO'); fsButton.position(windowWidth / 2 - 50, windowHeight / 2 - 25); fsButton.mousePressed(startGame); osc = new p5.Oscillator('sine'); osc.amp(0); osc.start(); highScore = getItem('highScore') || 0; } function draw() { background(0, 0, 10, 20); if (!started) return; if (flash > 0) { background(0, 80, 100, flash * 0.5); flash -= 5; } player.update(); player.display(); goal.color = frameCount % 360; goal.display(); if (dist(player.x, player.y, goal.x, goal.y) < 55) { score++; if (score > highScore) { highScore = score; storeItem('highScore', highScore); } playSound(440 + score * 20, 0.2); goal.spawn(); player.x = 50; player.y = 50; player.speed += 0.5; if (score % 3 === 0) enemies.push(new Enemy()); if (random() > 0.5) item.spawn(); } if (item.active) { item.display(true); if (dist(player.x, player.y, item.x, item.y) < 40) { item.active = false; player.powerUpTimer = 300; playSound(880, 0.5); } } for (let e of enemies) { e.update(); e.display(); if (player.powerUpTimer <= 0 && dist(player.x, player.y, e.x, e.y) < 45) player.handlePenalty(); } fill(0, 0, 100); noStroke(); textSize(24); text("SCORE: " + score, 20, 40); text("HI-SCORE: " + highScore, 20, 70); } function playSound(f, d) { osc.freq(f); osc.amp(0.3, 0.05); osc.amp(0, d); } function startGame() { userStartAudio(); fullscreen(true); started = true; fsButton.hide(); } function windowResized() { resizeCanvas(windowWidth, windowHeight); if (!started) fsButton.position(windowWidth / 2 - 50, windowHeight / 2 - 25); }