क्षुद्रग्रह खेल कोड जनरेटर
Wikiprompt से, मुफ्त प्रॉम्प्ट विश्वकोश
क्षुद्रग्रह खेल कोड जनरेटर p5.js एस्टेरॉयड्स गेम को कस्टम टेक्सचर के साथ पूर्ण रूप से उत्पन्न करने के लिए एक प्रॉम्प्ट, जिसमें जीत/हार की शर्तें और माउस नियंत्रण शामिल हों।
प्रॉम्प्ट सामग्रीसहेजें
🌐
यहाँ p5.js कोड है जो आपको स्पेसशिप को माउस से नियंत्रित करने और एस्टेरॉयड को माउस के बाएँ क्लिक से शूट करने की सुविधा देता है। यदि आपका स्पेसशिप एस्टेरॉयड से टकराता है, तो आप हार जाते हैं। यदि आप सभी एस्टेरॉयड को शूट कर देते हैं, तो आप जीत जाते हैं। आप अपने खुद के टेक्सचर का उपयोग कर सकते हैं।
```javascript
let ship;
let asteroids = [];
let bullets = [];
let gameOver = false;
let win = false;
// अपने टेक्सचर फ़ाइलों को यहाँ लोड करें (उदाहरण: 'ship.png', 'asteroid.png')
let shipImg, asteroidImg;
function preload() {
shipImg = loadImage('ship.png'); // अपनी स्पेसशिप की छवि
asteroidImg = loadImage('asteroid.png'); // एस्टेरॉयड की छवि
}
function setup() {
createCanvas(800, 600);
ship = new Ship();
// प्रारंभिक एस्टेरॉयड बनाएँ
for (let i = 0; i < 5; i++) {
asteroids.push(new Asteroid());
}
}
function draw() {
background(0);
if (!gameOver && !win) {
ship.update();
ship.show();
// बुलेट्स को अपडेट और दिखाएँ
for (let i = bullets.length - 1; i >= 0; i--) {
bullets[i].update();
bullets[i].show();
if (bullets[i].offscreen()) {
bullets.splice(i, 1);
}
}
// एस्टेरॉयड को अपडेट और दिखाएँ
for (let i = asteroids.length - 1; i >= 0; i--) {
asteroids[i].update();
asteroids[i].show();
// बुलेट्स और एस्टेरॉयड के बीच टकराव जाँचें
for (let j = bullets.length - 1; j >= 0; j--) {
if (asteroids[i].hits(bullets[j])) {
asteroids.splice(i, 1);
bullets.splice(j, 1);
break;
}
}
// स्पेसशिप और एस्टेरॉयड के बीच टकराव जाँचें
if (asteroids[i] && ship.hits(asteroids[i])) {
gameOver = true;
}
}
// जीत की स्थिति जाँचें
if (asteroids.length === 0) {
win = true;
}
} else {
// गेम ओवर या जीत का संदेश
textAlign(CENTER);
textSize(32);
fill(255);
if (gameOver) {
text("गेम ओवर! आप हार गए।", width/2, height/2);
} else if (win) {
text("बधाई हो! आप जीत गए!", width/2, height/2);
}
}
}
function mousePressed() {
if (mouseButton === LEFT && !gameOver && !win) {
ship.shoot();
}
}
class Ship {
constructor() {
this.pos = createVector(width/2, height/2);
this.size = 40;
}
update() {
// माउस की ओर स्पेसशिप को ले जाएँ
let mouse = createVector(mouseX, mouseY);
this.pos.lerp(mouse, 0.05); // स्मूद मूवमेंट
}
show() {
imageMode(CENTER);
image(shipImg, this.pos.x, this.pos.y, this.size, this.size);
}
shoot() {
// स्पेसशिप से माउस की दिशा में बुलेट दागें
let mouse = createVector(mouseX, mouseY);
let direction = p5.Vector.sub(mouse, this.pos);
direction.normalize();
bullets.push(new Bullet(this.pos.x, this.pos.y, direction));
}
hits(asteroid) {
let d = dist(this.pos.x, this.pos.y, asteroid.pos.x, asteroid.pos.y);
return d < (this.size/2 + asteroid.size/2);
}
}
class Bullet {
constructor(x, y, dir) {
this.pos = createVector(x, y);
this.vel = dir.mult(5);
this.size = 10;
}
update() {
this.pos.add(this.vel);
}
show() {
fill(255, 255, 0);
ellipse(this.pos.x, this.pos.y, this.size);
}
offscreen() {
return (this.pos.x < 0 || this.pos.x > width || this.pos.y < 0 || this.pos.y > height);
}
}
class Asteroid {
constructor() {
this.pos = createVector(random(width), random(height));
this.vel = p5.Vector.random2D().mult(random(1, 3));
this.size = random(30, 60);
// सुनिश्चित करें कि एस्टेरॉयड स्पेसशिप के शुरुआती स्थान से बहुत दूर हों
while (dist(this.pos.x, this.pos.y, width/2, height/2) < 150) {
this.pos = createVector(random(width), random(height));
}
}
update() {
this.pos.add(this.vel);
// स्क्रीन के किनारों पर रैप करें
if (this.pos.x > width) this.pos.x = 0;
if (this.pos.x < 0) this.pos.x = width;
if (this.pos.y > height) this.pos.y = 0;
if (this.pos.y < 0) this.pos.y = height;
}
show() {
imageMode(CENTER);
image(asteroidImg, this.pos.x, this.pos.y, this.size, this.size);
}
hits(bullet) {
let d = dist(this.pos.x, this.pos.y, bullet.pos.x, bullet.pos.y);
return d < (this.size/2 + bullet.size/2);
}
}
```
**निर्देश:**
- `ship.png` और `asteroid.png` फ़ाइलों को अपने स्केच के समान फ़ोल्डर में रखें, या `preload()` में पथ बदलें।
- गेम में 5 एस्टेरॉयड हैं; आप चाहें तो `setup()` में `for` लूप की संख्या बदल सकते हैं।
- स्पेसशिप माउस का पीछा करती है (स्मूद तरीके से), और बाएँ क्लिक से गोली चलती है।
- टकराव का पता लगाने के लिए सर्कल कोलिज़न का उपयोग किया गया है।
पूरा प्रॉम्प्ट देखने के लिए साइन इन करें
Continue with:
By logging in, you agree to our Terms of Use and Privacy Policy
उपयोग
यह प्रॉम्प्ट coding के साथ उपयोग के लिए डिज़ाइन किया गया है। ऊपर प्रॉम्प्ट सामग्री कॉपी करें और अपने पसंदीदा AI टूल में पेस्ट करें।
सर्वोत्तम परिणामों के लिए, आप अपनी विशिष्ट आवश्यकताओं के अनुसार प्लेसहोल्डर (वर्ग कोष्ठक या बड़े अक्षरों में दर्शाए गए) को अनुकूलित कर सकते हैं।
चर्चा
0 टिप्पणियाँ