Juego de Arkanoid con p5.js
De Wikiprompt, la enciclopedia libre de prompts
Juego de Arkanoid con p5.js Un prompt de una sola toma para generar un juego Arkanoid jugable en p5.js, con la paleta controlada por el rat贸n. Incluye instrucciones de seguimiento para continuar o depurar el c贸digo.
Contenido del PromptGuardar
馃寪
let paddle;
let ball;
let bricks = [];
let cols = 8;
let rows = 5;
let brickWidth, brickHeight;
let score = 0;
let gameOver = false;
let gameWin = false;
function setup() {
createCanvas(800, 600);
brickWidth = width / cols;
brickHeight = 30;
// Initialize paddle
paddle = {
x: width / 2,
y: height - 30,
w: 100,
h: 15
};
// Initialize ball
ball = {
x: width / 2,
y: height - 50,
vx: 3,
vy: -3,
radius: 8
};
// Create bricks
for (let i = 0; i < rows; i++) {
for (let j = 0; j < cols; j++) {
bricks.push({
x: j * brickWidth,
y: i * brickHeight + 50,
w: brickWidth - 2,
h: brickHeight - 2,
alive: true
});
}
}
}
function draw() {
background(0);
if (gameOver) {
textSize(32);
fill(255);
text("Game Over - Score: " + score, width/2 - 150, height/2);
return;
}
if (gameWin) {
textSize(32);
fill(255);
text("You Win! Score: " + score, width/2 - 150, height/2);
return;
}
// Move paddle with mouse
paddle.x = mouseX;
paddle.x = constrain(paddle.x, paddle.w / 2, width - paddle.w / 2);
// Move ball
ball.x += ball.vx;
ball.y += ball.vy;
// Ball collision with walls
if (ball.x < ball.radius || ball.x > width - ball.radius) {
ball.vx *= -1;
}
if (ball.y < ball.radius) {
ball.vy *= -1;
}
// Ball falls below screen
if (ball.y > height + ball.radius) {
gameOver = true;
}
// Ball collision with paddle
if (ball.y + ball.radius > paddle.y &&
ball.y - ball.radius < paddle.y + paddle.h &&
ball.x > paddle.x - paddle.w / 2 &&
ball.x < paddle.x + paddle.w / 2) {
ball.vy *= -1;
// Add slight angle based on hit position
let hitPos = (ball.x - paddle.x) / (paddle.w / 2);
ball.vx = hitPos * 5;
}
// Ball collision with bricks
for (let i = 0; i < bricks.length; i++) {
let brick = bricks[i];
if (brick.alive) {
if (ball.x + ball.radius > brick.x &&
ball.x - ball.radius < brick.x + brick.w &&
ball.y + ball.radius > brick.y &&
ball.y - ball.radius < brick.y + brick.h) {
brick.alive = false;
ball.vy *= -1;
score += 10;
}
}
}
// Check win condition
let allDead = true;
for (let i = 0; i < bricks.length; i++) {
if (bricks[i].alive) {
allDead = false;
break;
}
}
if (allDead) {
gameWin = true;
}
// Draw everything
background(0);
// Draw bricks
for (let i = 0; i < bricks.length; i++) {
let brick = bricks[i];
if (brick.alive) {
fill(255, 0, 0);
rect(brick.x, brick.y, brick.w, brick.h);
}
}
// Draw paddle
fill(255);
rect(paddle.x - paddle.w / 2, paddle.y, paddle.w, paddle.h);
// Draw ball
fill(255);
ellipse(ball.x, ball.y, ball.radius * 2);
// Draw score
textSize(20);
fill(255);
text("Score: " + score, 10, 30);
}
Inici谩 sesi贸n para ver el prompt completo
Continuar con:
Al iniciar sesi贸n, acept谩s nuestros T茅rminos de uso y Pol铆tica de privacidad
Uso
Este prompt est谩 dise帽ado para usarse con coding. Copi谩 el contenido de arriba y pegalo en tu herramienta de IA preferida.
Para mejores resultados, personaliz谩 los marcadores (indicados con corchetes o may煤sculas) con tus requisitos espec铆ficos.
Referencias
- Categor铆a: Prompts de coding
- Fuente: https://x.com/icreatelife/status/1636940552632401920
Discusi贸n
0 comentarios