Voici un jeu Arkanoid complet en p5.js. Copiez ce code dans un fichier HTML ou utilisez l'éditeur p5.js. ```javascript let paddle; let ball; let bricks = []; let score = 0; let lives = 3; let gameState = 'start'; // 'start', 'playing', 'gameover', 'win' function setup() { createCanvas(800, 600); paddle = new Paddle(); ball = new Ball(); resetBricks(); } function draw() { background(0); // Afficher le score et les vies textSize(20); fill(255); text('Score: ' + score, 10, 30); text('Vies: ' + lives, width - 100, 30); if (gameState === 'start') { textAlign(CENTER); textSize(40); fill(255); text('ARKANOID', width/2, height/2 - 20); textSize(20); text('Cliquez pour commencer', width/2, height/2 + 20); textAlign(LEFT); } else if (gameState === 'playing') { paddle.show(); paddle.move(); ball.show(); ball.move(); ball.checkPaddle(paddle); ball.checkBricks(); checkWin(); } else if (gameState === 'gameover') { textAlign(CENTER); textSize(40); fill(255); text('GAME OVER', width/2, height/2 - 20); textSize(20); text('Score final: ' + score, width/2, height/2 + 20); text('Cliquez pour rejouer', width/2, height/2 + 50); textAlign(LEFT); } else if (gameState === 'win') { textAlign(CENTER); textSize(40); fill(255); text('VOUS AVEZ GAGNÉ!', width/2, height/2 - 20); textSize(20); text('Score final: ' + score, width/2, height/2 + 20); text('Cliquez pour rejouer', width/2, height/2 + 50); textAlign(LEFT); } // Afficher les briques for (let brick of bricks) { brick.show(); } } function mousePressed() { if (gameState === 'start') { gameState = 'playing'; } else if (gameState === 'gameover' || gameState === 'win') { resetGame(); } } function resetGame() { score = 0; lives = 3; ball.reset(); resetBricks(); gameState = 'playing'; } function resetBricks() { bricks = []; let rows = 5; let cols = 8; let brickWidth = 80; let brickHeight = 20; let spacing = 10; let offsetX = (width - (cols * (brickWidth + spacing))) / 2; let offsetY = 50; for (let i = 0; i < rows; i++) { for (let j = 0; j < cols; j++) { let x = offsetX + j * (brickWidth + spacing); let y = offsetY + i * (brickHeight + spacing); let colors = [color(255, 0, 0), color(255, 165, 0), color(255, 255, 0), color(0, 255, 0), color(0, 0, 255)]; bricks.push(new Brick(x, y, brickWidth, brickHeight, colors[i])); } } } function checkWin() { if (bricks.length === 0) { gameState = 'win'; } } class Paddle { constructor() { this.width = 100; this.height = 15; this.x = width/2 - this.width/2; this.y = height - 30; this.speed = 8; } show() { fill(255); rect(this.x, this.y, this.width, this.height); } move() { if (keyIsDown(LEFT_ARROW)) { this.x -= this.speed; } if (keyIsDown(RIGHT_ARROW)) { this.x += this.speed; } this.x = constrain(this.x, 0, width - this.width); } } class Ball { constructor() { this.radius = 8; this.reset(); } reset() { this.x = width/2; this.y = height - 50; this.vx = random(-3, 3); this.vy = -4; this.speed = 5; } show() { fill(255); ellipse(this.x, this.y, this.radius * 2); } move() { this.x += this.vx; this.y += this.vy; // Rebondir sur les murs if (this.x - this.radius < 0 || this.x + this.radius > width) { this.vx *= -1; } if (this.y - this.radius < 0) { this.vy *= -1; } // Perdre une vie si la balle tombe if (this.y - this.radius > height) { lives--; if (lives <= 0) { gameState = 'gameover'; } else { this.reset(); } } } checkPaddle(paddle) { if (this.y + this.radius >= paddle.y && this.y + this.radius <= paddle.y + paddle.height && this.x >= paddle.x && this.x <= paddle.x + paddle.width) { this.vy *= -1; // Ajouter un peu de variation à la direction this.vx += (this.x - (paddle.x + paddle.width/2)) * 0.1; this.vx = constrain(this.vx, -5, 5); } } checkBricks() { for (let i = bricks.length - 1; i >= 0; i--) { let brick = bricks[i]; if (this.x + this.radius > brick.x && this.x - this.radius < brick.x + brick.w && this.y + this.radius > brick.y && this.y - this.radius < brick.y + brick.h) { bricks.splice(i, 1); this.vy *= -1; score += 10; } } } } class Brick { constructor(x, y, w, h, color) { this.x = x; this.y = y; this.w = w; this.h = h; this.color = color; } show() { fill(this.color); rect(this.x, this.y, this.w, this.h); } } ``` Ce jeu Arkanoid comprend : - Une raquette contrôlée avec les flèches gauche/droite - Une balle qui rebondit - 40 briques colorées à détruire - Un système de score et de vies - Des écrans de début, de victoire et de défaite - Des mécaniques de rebond avec variation de direction Cliquez pour commencer et utilisez les flèches pour jouer !
De Wikiprompt, l’encyclopédie libre de prompts
Voici un jeu Arkanoid complet en p5.js. Copiez ce code dans un fichier HTML ou utilisez l'éditeur p5.js. ```javascript let paddle; let ball; let bricks = []; let score = 0; let lives = 3; let gameState = 'start'; // 'start', 'playing', 'gameover', 'win' function setup() { createCanvas(800, 600); paddle = new Paddle(); ball = new Ball(); resetBricks(); } function draw() { background(0); // Afficher le score et les vies textSize(20); fill(255); text('Score: ' + score, 10, 30); text('Vies: ' + lives, width - 100, 30); if (gameState === 'start') { textAlign(CENTER); textSize(40); fill(255); text('ARKANOID', width/2, height/2 - 20); textSize(20); text('Cliquez pour commencer', width/2, height/2 + 20); textAlign(LEFT); } else if (gameState === 'playing') { paddle.show(); paddle.move(); ball.show(); ball.move(); ball.checkPaddle(paddle); ball.checkBricks(); checkWin(); } else if (gameState === 'gameover') { textAlign(CENTER); textSize(40); fill(255); text('GAME OVER', width/2, height/2 - 20); textSize(20); text('Score final: ' + score, width/2, height/2 + 20); text('Cliquez pour rejouer', width/2, height/2 + 50); textAlign(LEFT); } else if (gameState === 'win') { textAlign(CENTER); textSize(40); fill(255); text('VOUS AVEZ GAGNÉ!', width/2, height/2 - 20); textSize(20); text('Score final: ' + score, width/2, height/2 + 20); text('Cliquez pour rejouer', width/2, height/2 + 50); textAlign(LEFT); } // Afficher les briques for (let brick of bricks) { brick.show(); } } function mousePressed() { if (gameState === 'start') { gameState = 'playing'; } else if (gameState === 'gameover' || gameState === 'win') { resetGame(); } } function resetGame() { score = 0; lives = 3; ball.reset(); resetBricks(); gameState = 'playing'; } function resetBricks() { bricks = []; let rows = 5; let cols = 8; let brickWidth = 80; let brickHeight = 20; let spacing = 10; let offsetX = (width - (cols * (brickWidth + spacing))) / 2; let offsetY = 50; for (let i = 0; i < rows; i++) { for (let j = 0; j < cols; j++) { let x = offsetX + j * (brickWidth + spacing); let y = offsetY + i * (brickHeight + spacing); let colors = [color(255, 0, 0), color(255, 165, 0), color(255, 255, 0), color(0, 255, 0), color(0, 0, 255)]; bricks.push(new Brick(x, y, brickWidth, brickHeight, colors[i])); } } } function checkWin() { if (bricks.length === 0) { gameState = 'win'; } } class Paddle { constructor() { this.width = 100; this.height = 15; this.x = width/2 - this.width/2; this.y = height - 30; this.speed = 8; } show() { fill(255); rect(this.x, this.y, this.width, this.height); } move() { if (keyIsDown(LEFT_ARROW)) { this.x -= this.speed; } if (keyIsDown(RIGHT_ARROW)) { this.x += this.speed; } this.x = constrain(this.x, 0, width - this.width); } } class Ball { constructor() { this.radius = 8; this.reset(); } reset() { this.x = width/2; this.y = height - 50; this.vx = random(-3, 3); this.vy = -4; this.speed = 5; } show() { fill(255); ellipse(this.x, this.y, this.radius * 2); } move() { this.x += this.vx; this.y += this.vy; // Rebondir sur les murs if (this.x - this.radius < 0 || this.x + this.radius > width) { this.vx *= -1; } if (this.y - this.radius < 0) { this.vy *= -1; } // Perdre une vie si la balle tombe if (this.y - this.radius > height) { lives--; if (lives <= 0) { gameState = 'gameover'; } else { this.reset(); } } } checkPaddle(paddle) { if (this.y + this.radius >= paddle.y && this.y + this.radius <= paddle.y + paddle.height && this.x >= paddle.x && this.x <= paddle.x + paddle.width) { this.vy *= -1; // Ajouter un peu de variation à la direction this.vx += (this.x - (paddle.x + paddle.width/2)) * 0.1; this.vx = constrain(this.vx, -5, 5); } } checkBricks() { for (let i = bricks.length - 1; i >= 0; i--) { let brick = bricks[i]; if (this.x + this.radius > brick.x && this.x - this.radius < brick.x + brick.w && this.y + this.radius > brick.y && this.y - this.radius < brick.y + brick.h) { bricks.splice(i, 1); this.vy *= -1; score += 10; } } } } class Brick { constructor(x, y, w, h, color) { this.x = x; this.y = y; this.w = w; this.h = h; this.color = color; } show() { fill(this.color); rect(this.x, this.y, this.w, this.h); } } ``` Ce jeu Arkanoid comprend : - Une raquette contrôlée avec les flèches gauche/droite - Une balle qui rebondit - 40 briques colorées à détruire - Un système de score et de vies - Des écrans de début, de victoire et de défaite - Des mécaniques de rebond avec variation de direction Cliquez pour commencer et utilisez les flèches pour jouer ! Un prompt simple en une seule fois pour générer un jeu Arkanoid jouable en p5.js, avec la souris contrôlant la raquette. Inclut des instructions de suivi pour la complétion et la correction de bugs.
Contenu du PromptEnregistrer
Connectez-vous pour voir le prompt complet
Continuer avec:
En vous connectant, vous acceptez nos Conditions et Confidentialité
Utilisation
Ce prompt est conçu pour être utilisé avec coding. Copiez le contenu ci-dessus et collez-le dans votre outil d’IA préféré.
Pour de meilleurs résultats, personnalisez les espaces réservés (indiqués par des crochets ou des majuscules) selon vos besoins.
Références
- Catégorie: Prompts coding
- Source: https://x.com/icreatelife/status/1636934371243438080
Discussion
0 commentaires