Initial commit: Add existing project files
This commit is contained in:
commit
40377caaa3
4 changed files with 1263 additions and 0 deletions
28
index.html
Normal file
28
index.html
Normal file
|
|
@ -0,0 +1,28 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
|
||||||
|
<title>Pop! Pop! Pop!</title>
|
||||||
|
<style>
|
||||||
|
body {
|
||||||
|
margin: 0;
|
||||||
|
padding: 0;
|
||||||
|
background-color: #f0f0f0;
|
||||||
|
overflow: hidden;
|
||||||
|
display: flex;
|
||||||
|
justify-content: center;
|
||||||
|
align-items: center;
|
||||||
|
height: 100vh;
|
||||||
|
width: 100vw;
|
||||||
|
}
|
||||||
|
canvas {
|
||||||
|
display: block;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div id="game-container"></div>
|
||||||
|
<script type="module" src="/src/main.ts"></script>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
1098
package-lock.json
generated
Normal file
1098
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load diff
19
package.json
Normal file
19
package.json
Normal file
|
|
@ -0,0 +1,19 @@
|
||||||
|
{
|
||||||
|
"name": "demo-pop-game",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"description": "A simple pop game for toddlers",
|
||||||
|
"type": "module",
|
||||||
|
"scripts": {
|
||||||
|
"dev": "npx vite --host",
|
||||||
|
"build": "npx tsc && npx vite build",
|
||||||
|
"preview": "npx vite preview"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"phaser": "^3.80.1"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"@types/node": "^20.19.43",
|
||||||
|
"typescript": "^5.9.3",
|
||||||
|
"vite": "^5.4.21"
|
||||||
|
}
|
||||||
|
}
|
||||||
118
src/main.ts
Normal file
118
src/main.ts
Normal file
|
|
@ -0,0 +1,118 @@
|
||||||
|
import Phaser from 'phaser';
|
||||||
|
|
||||||
|
// Simple Web Audio API helper for a "pop" sound
|
||||||
|
const playPopSound = (scene) => {
|
||||||
|
const audioCtx = scene.sound.context;
|
||||||
|
const oscillator = audioCtx.createOscillator();
|
||||||
|
const gainNode = audioCtx.createGain();
|
||||||
|
|
||||||
|
oscillator.type = 'sine';
|
||||||
|
oscillator.frequency.setValueAtTime(400, audioCtx.currentTime);
|
||||||
|
oscillator.frequency.exponentialRampToValueAtTime(0.01, audioCtx.currentTime + 0.1);
|
||||||
|
|
||||||
|
gainNode.gain.setValueAtTime(0.3, audioCtx.currentTime);
|
||||||
|
gainNode.gain.exponentialRampToValueAtTime(0.01, audioCtx.currentTime + 0.1);
|
||||||
|
|
||||||
|
oscillator.connect(gainNode);
|
||||||
|
gainNode.connect(audioCtx.destination);
|
||||||
|
|
||||||
|
oscillator.start();
|
||||||
|
oscillator.stop(audioCtx.currentTime + 0.1);
|
||||||
|
};
|
||||||
|
|
||||||
|
class PopScene extends Phaser.Scene {
|
||||||
|
constructor() {
|
||||||
|
super('PopScene');
|
||||||
|
}
|
||||||
|
|
||||||
|
create() {
|
||||||
|
// Fill the background with a soft color
|
||||||
|
this.cameras.main.setBackgroundColor('#e0f7fa');
|
||||||
|
|
||||||
|
// Spawn a circle every 1 second
|
||||||
|
this.time.addEvent({
|
||||||
|
delay: 1000,
|
||||||
|
callback: this.spawnCircle,
|
||||||
|
callbackScope: this,
|
||||||
|
loop: true
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
spawnCircle() {
|
||||||
|
const x = Phaser.Math.Between(50, this.scale.width - 50);
|
||||||
|
const y = Phaser.Math.Between(50, this.scale.height - 50);
|
||||||
|
const radius = Phaser.Math.Between(30, 60);
|
||||||
|
|
||||||
|
// Pick a random bright color (bulletproof method)
|
||||||
|
const color = Math.floor(Math.random() * 0xffffff);
|
||||||
|
|
||||||
|
// Create a graphics object for the circle
|
||||||
|
const circle = this.add.graphics();
|
||||||
|
circle.fillStyle(color, 1);
|
||||||
|
circle.fillCircle(0, 0, radius);
|
||||||
|
|
||||||
|
// We use a container to make the circle a single interactive object
|
||||||
|
const container = this.add.container(x, y);
|
||||||
|
container.add(circle);
|
||||||
|
container.setSize(radius * 2, radius * 2);
|
||||||
|
container.setInteractive(new Phaser.Geom.Circle(radius, radius, radius), Phaser.Geom.Circle.Contains);
|
||||||
|
|
||||||
|
// Add a little "pulse" animation on spawn
|
||||||
|
container.setScale(0);
|
||||||
|
this.tweens.add({
|
||||||
|
targets: container,
|
||||||
|
scale: 1,
|
||||||
|
duration: 300,
|
||||||
|
ease: 'Back.easeOut'
|
||||||
|
});
|
||||||
|
|
||||||
|
// Handle click/touch
|
||||||
|
container.on('pointerdown', () => {
|
||||||
|
this.popCircle(container, circle, radius, color);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
popCircle(container, graphics, radius, color) {
|
||||||
|
// 1. Play sound (with safety check for Web Audio API)
|
||||||
|
try {
|
||||||
|
playPopSound(this);
|
||||||
|
} catch (e) {
|
||||||
|
console.warn("Audio playback failed (user interaction might be required):", e);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 2. Create "Confetti" particles
|
||||||
|
// Instead of complex particles, let's just spawn a few small circles manually for the "vibe"
|
||||||
|
for(let i = 0; i < 8; i++) {
|
||||||
|
const p = this.add.circle(container.x, container.y, 5, color);
|
||||||
|
this.tweens.add({
|
||||||
|
targets: p,
|
||||||
|
x: p.x + Phaser.Math.Between(-100, 100),
|
||||||
|
y: p.y + Phaser.Math.Between(-100, 100),
|
||||||
|
alpha: 0,
|
||||||
|
duration: 500,
|
||||||
|
onComplete: () => p.destroy()
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// 3. Destroy the circle
|
||||||
|
container.destroy();
|
||||||
|
}
|
||||||
|
|
||||||
|
update() {
|
||||||
|
// Optional: check if circles should disappear if not clicked
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const config = {
|
||||||
|
type: Phaser.AUTO,
|
||||||
|
width: window.innerWidth,
|
||||||
|
height: window.innerHeight,
|
||||||
|
parent: 'game-container',
|
||||||
|
scene: [PopScene],
|
||||||
|
physics: {
|
||||||
|
default: 'arcade',
|
||||||
|
arcade: { debug: false }
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
new Phaser.Game(config);
|
||||||
Loading…
Add table
Reference in a new issue