xxxxxxxxxx
let ball; // ボールスプライト
let speed = 50; // ボールの速度
let wallThickness = 30; // 壁の厚さ
let obstacles = []; // 障害物の配列
let ballSize = 10; // ボールと障害物のサイズ
function setup() {
createCanvas(400, 400); // キャンバスのサイズを300x400に設定
noStroke();
// 四方の壁を作成
// 上の壁
new Sprite(width / 2, 0 - wallThickness / 2, width, wallThickness, 'static');
// 下の壁
new Sprite(width / 2, height + wallThickness / 2, width, wallThickness, 'static');
// 左の壁
new Sprite(0 - wallThickness / 2, height / 2, wallThickness, height, 'static');
// 右の壁
new Sprite(width + wallThickness / 2, height / 2, wallThickness, height, 'static');
// ボールのスプライトを作成
ball = new Sprite(width / 2, height / 2, ballSize); // 半径20の円
ball.color = "pink"; // ボールの色を薄いピンクに設定
ball.shape = 'circle'; // ボールを円に設定
// 障害物の生成
for (let i = 0; i < 53; i++) {
// ランダムな位置に障害物を生成
let obstacleX = random(ballSize, width - ballSize);
let obstacleY = random(ballSize, height - ballSize);
let obstacle = new Sprite(obstacleX, obstacleY, ballSize, ballSize, 'static');
obstacle.color = "white"; // 障害物の色をグレーに設定
obstacles.push(obstacle);
}
}
function draw() {
background(200); // 背景色をグレーに設定
// ボールが壁にぶつかったらスローモーション
if (ball.x - ball.w / 2 < 0 || ball.x + ball.w / 2 > width || ball.y - ball.h / 2 < 0 || ball.y + ball.h / 2 > height) {
world.timeScale = 0.01; // スローモーション
} else {
world.timeScale = 1; // 通常速度
}
}
// タッチまたはマウスクリックでボールに速度を与える
function touchStarted() {
// ランダムな方向にボールを動かす
ball.vel.x = random(-speed, speed); // x方向の速度
ball.vel.y = random(-speed, speed); // y方向の速度
}