Gere o jogo Arkanoid em p5.js
De Wikiprompt, a enciclopédia livre de prompts
Gere o jogo Arkanoid em p5.js Um prompt único e simples para gerar um jogo Arkanoid jogável em p5.js, com o mouse controlando a raquete. Inclui instruções de acompanhamento para conclusão e correção de bugs.
Conteúdo do PromptSalvar
🌐
Aqui está o código p5.js para um jogo Arkanoid onde o mouse controla a raquete:
```javascript
let ball;
let paddle;
let bricks = [];
let score = 0;
let gameOver = false;
let gameWin = false;
function setup() {
createCanvas(800, 600);
paddle = new Paddle();
ball = new Ball();
// Criar blocos
for (let row = 0; row < 5; row++) {
for (let col = 0; col < 8; col++) {
bricks.push(new Brick(col * 100 + 10, row * 30 + 20));
}
}
}
function draw() {
background(0);
if (!gameOver && !gameWin) {
paddle.show();
paddle.update();
ball.show();
ball.update();
ball.checkPaddle(paddle);
ball.checkBricks();
// Mostrar blocos
for (let brick of bricks) {
brick.show();
}
// Verificar vitória
if (bricks.length === 0) {
gameWin = true;
}
// Verificar derrota
if (ball.y > height) {
gameOver = true;
}
} else {
// Tela final
textAlign(CENTER);
textSize(32);
fill(255);
if (gameWin) {
text("Você venceu!", width / 2, height / 2);
} else {
text("Game Over", width / 2, height / 2);
}
textSize(16);
text("Clique para reiniciar", width / 2, height / 2 + 40);
}
// Placar
textAlign(LEFT);
textSize(20);
fill(255);
text("Pontos: " + score, 10, 30);
}
function mousePressed() {
if (gameOver || gameWin) {
resetGame();
}
}
function resetGame() {
score = 0;
gameOver = false;
gameWin = false;
bricks = [];
for (let row = 0; row < 5; row++) {
for (let col = 0; col < 8; col++) {
bricks.push(new Brick(col * 100 + 10, row * 30 + 20));
}
}
ball.reset();
}
class Paddle {
constructor() {
this.width = 100;
this.height = 15;
this.y = height - 30;
}
update() {
this.x = mouseX;
this.x = constrain(this.x, this.width / 2, width - this.width / 2);
}
show() {
fill(255);
rectMode(CENTER);
rect(this.x, this.y, this.width, this.height);
}
}
class Ball {
constructor() {
this.radius = 10;
this.reset();
}
reset() {
this.x = width / 2;
this.y = height - 50;
this.vx = random(-3, 3);
this.vy = -4;
}
update() {
this.x += this.vx;
this.y += this.vy;
// Colisão com paredes
if (this.x < this.radius || this.x > width - this.radius) {
this.vx *= -1;
}
if (this.y < this.radius) {
this.vy *= -1;
}
}
checkPaddle(paddle) {
if (this.y + this.radius > paddle.y - paddle.height / 2 &&
this.y - this.radius < paddle.y + paddle.height / 2 &&
this.x > paddle.x - paddle.width / 2 &&
this.x < paddle.x + paddle.width / 2) {
this.vy *= -1;
// Adicionar variação baseada na posição do impacto
let hitPos = (this.x - paddle.x) / (paddle.width / 2);
this.vx = hitPos * 5;
}
}
checkBricks() {
for (let i = bricks.length - 1; i >= 0; i--) {
let brick = bricks[i];
if (this.x > brick.x - brick.w / 2 &&
this.x < brick.x + brick.w / 2 &&
this.y > brick.y - brick.h / 2 &&
this.y < brick.y + brick.h / 2) {
bricks.splice(i, 1);
this.vy *= -1;
score += 10;
}
}
}
show() {
fill(255, 0, 0);
ellipse(this.x, this.y, this.radius * 2);
}
}
class Brick {
constructor(x, y) {
this.x = x;
this.y = y;
this.w = 90;
this.h = 20;
}
show() {
fill(0, 255, 0);
rectMode(CENTER);
rect(this.x, this.y, this.w, this.h);
}
}
```
Entre para ver o prompt completo
Continuar com:
Ao entrar, você concorda com nossos Termos de uso e Política de privacidade
Uso
Este prompt foi projetado para uso com coding. Copie o conteúdo acima e cole na sua ferramenta de IA preferida.
Para melhores resultados, personalize os marcadores (indicados por colchetes ou maiúsculas) com seus requisitos específicos.
Referências
- Categoria: Prompts de coding
- Fonte: https://x.com/icreatelife/status/1636934371243438080
Discussão
0 comentários