main code
main code
function setup() {
createCanvas(600, 600);
centerX = width / 2;
centerY = height / 2;
function draw() {
background(30);
if (gameOver) {
showGameOverScreen();
return;
}
// Move obstacles
obs.angle += obs.speed;
}
// Display score
fill(255);
textSize(16);
text(`Score: ${score}`, 10, 20);
function keyPressed() {
if (keyCode === UP_ARROW) {
speed += 0.01; // Increase speed
} else if (keyCode === DOWN_ARROW) {
speed = max(speed - 0.01, 0.01); // Decrease speed
} else if (keyCode === LEFT_ARROW) {
radius = max(radius - 10, 50); // Decrease radius
} else if (keyCode === RIGHT_ARROW) {
radius = min(radius + 10, width / 2 - 20); // Increase radius
} else if (key === 'R' || key === 'r') {
resetGame();
}
}
function resetGame() {
angle = 0;
speed = 0.02;
radius = 200;
score = 0;
gameOver = false;
obstacles = [];
collectibles = [];
function createObstacle() {
let obstacleAngle = random(TWO_PI);
let obstacleRadius = radius + random(-50, 50);
obstacles.push({
angle: obstacleAngle,
radius: obstacleRadius,
size: 20,
speed: random(0.01, 0.03),
});
}
function createCollectible() {
let collectibleAngle = random(TWO_PI);
let collectibleRadius = radius + random(-100, 100);
collectibles.push({
x: centerX + collectibleRadius * cos(collectibleAngle),
y: centerY + collectibleRadius * sin(collectibleAngle),
size: 15,
value: 50,
});
}
function increaseDifficulty() {
for (let obs of obstacles) {
obs.speed += 0.005; // Increase obstacle speed
}
}
function showGameOverScreen() {
textAlign(CENTER, CENTER);
fill(255, 0, 0);
textSize(32);
text("Game Over!", width / 2, height / 2 - 20);
textSize(20);
text("Press 'R' to Restart", width / 2, height / 2 + 20);
}