マウスでパドルを操作、クリックでゲームスタート!
// ゲームの状態
let gameState = 'START'; // START, PLAYING, GAMEOVER, CLEAR
function draw() {
if (gameState === 'START') {
drawStartScreen();
} else if (gameState === 'PLAYING') {
updateGame();
drawGame();
} else if (gameState === 'GAMEOVER') {
drawGameOver();
}
}
// ブロックを配列で管理
let blocks = [];
// ブロックの初期化
for (let row = 0; row < blockRows; row++) {
for (let col = 0; col < blockCols; col++) {
blocks.push({
x: col * (blockWidth + 10) + 35,
y: row * (blockHeight + 10) + 50,
visible: true,
color: color(row * 60, 80, 100)
});
}
}
// 矩形同士の衝突判定
if (ballX > block.x && ballX < block.x + blockWidth &&
ballY > block.y && ballY < block.y + blockHeight) {
// 衝突した!
}
// === グローバル変数 ===
let gameState = 'MENU';
let player;
let enemies = [];
let score = 0;
// === セットアップ ===
function setup() {
createCanvas(800, 600);
initGame();
}
// === メインループ ===
function draw() {
updateState();
render();
}
// === 状態更新 ===
function updateState() {
switch(gameState) {
case 'MENU':
updateMenu();
break;
case 'PLAYING':
updatePlayer();
updateEnemies();
checkCollisions();
break;
case 'GAMEOVER':
updateGameOver();
break;
}
}
// === 描画 ===
function render() {
background(0);
switch(gameState) {
case 'MENU':
drawMenu();
break;
case 'PLAYING':
drawPlayer();
drawEnemies();
drawUI();
break;
case 'GAMEOVER':
drawGameOver();
break;
}
}
// === 初期化 ===
function initGame() {
player = {
x: width / 2,
y: height - 50,
size: 30,
speed: 5
};
enemies = [];
score = 0;
}
// === イベントハンドラ ===
function keyPressed() {
// キー入力処理
}
function mousePressed() {
// マウスクリック処理
}