CodingTrain / CodingTrain/Suggestion-Box

ADD OBJECT to ARRAY when MOUSEPRESSED

Aperta
#678 1 commento 0 reazioni 0 assegnatari Vedi su GitHub
Lingua principale
Nessun dato sulla lingua
Stelle
570
Fork
85
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Descrizione

Hey guys, I want to add an object to the screen every time I click in a specific area of the screen. It works that when I click the screen, for example 10 objects, 10 is the length of the array, appear but all on the same spot, I want them to appear after and after, every time I click. Hope you understand my problem, it's for a game where you can shoot lasers from a spaceship. Heres the code :

`/*-------------------------------------------------------------VARIABLES*/
//PLAYBUTTON
boolean playButtonFSCheck = true;
boolean playButtonFSMouseActive = true;
boolean shotActive = false;
**int i = 0;**
/*-------------------------------------------------------------OBJECTS*/
Ship ship;
**LaserShot[] lasershots = new LaserShot[10];**
/*-------------------------------------------------------------SETUP*/
void setup() {
//size(600,1000);
fullScreen();
ship = new Ship();

**for(int i = 0; i < lasershots.length; i++) {
lasershots[i] = new LaserShot();
}**
}

/*-------------------------------------------------------------DRAW*/
void draw() {
background(51);

//starttext
fill(255);
textSize(150);
if(playButtonFSCheck) {
text("SHOOTER", width/2-325, height/4);
}

//playbutton
fill(102, 255, 51);
stroke(0);
strokeWeight(5);
if(playButtonFSCheck) {
triangle(width/2-150,height/2-200, width/2+250, height/2, width/2-150, height/2+200);
}

//SHIP DISPLAY
ship.display();
//SHIP MOVE
ship.move();

**if(shotActive) {
for(i = 0; i < lasershots.length; i++) {
lasershots[i].Laser();
}
}**
}
/*-------------------------------------------------------------MOUSEPRESSED*/
void mousePressed() {
//Playbutton
if(playButtonFSMouseActive) {
if(mouseX > width/2-160 && mouseX < width/2+260 && mouseY > height/2-210 && mouseY < height/2+210) {
playButtonFSCheck = !playButtonFSCheck;
playButtonFSMouseActive = false;
ship.triangleCheck = true;
}
}

**if(ship.triangleCheck) {
if(mouseX > 0 && mouseX < width/2 && mouseY > 0 && mouseY < height/2-200) {
shotActive = !shotActive;
}
}**
}

/*-------------------------------------------------------------CLASS LASERSHOTS*/
class LaserShot {
float x = ship.x1 ;
float y = ship.y1-10;

**void Laser() {**
noFill();
stroke(255,0,200);
strokeWeight(5);
ellipse(x,y,20,20);
y -= 10;
//x = random(width/2-10, width/2+10);
}
}

/*-------------------------------------------------------------CLASS SHIP*/
/*class Ship {
float x1 = width/2;
float y1 = height-300;
float x2 = width/2+125;
float y2 = height-100;
float x3 = width/2-125;
float y3 = height-100;

boolean triangleCheck = false;

void display() {
if(triangleCheck) {
fill(255);
stroke(255,0,200);
strokeWeight(10);
triangle(x1, y1, x2, y2, x3, y3);
}
}

void move() {
if(triangleCheck) {
if(mouseX > 0 && mouseX < width && mouseY > height-350 && mouseY < height-50) {
x1 = mouseX;
x2 = mouseX-125;
x3 = mouseX+125;
}
if(x1 > width-150) {
x1 = width-150;
x2 = width-275;
x3 = width-25;
}
if(x1 < 150) {
x1 = 150;
x2 = 275;
x3 = 25;
}
}
}
}*/`

Guida per i contributori

Nessuna guida per i contributori indicizzata per questo repository

Direzione di ricerca

Non è identificato alcun file del repository né alcun test. Riproduci il comportamento di setup(), draw(), mousePressed() e della classe LaserShot, quindi verifica che clic ripetuti creino oggetti laser separati con posizioni correnti distinte, invece di eseguire il rendering di ogni oggetto nello stesso punto.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Ambito
game-dev
Tipo di issue
Bug
Difficoltà
3/5
Tempo stimato
1-2 giorni
Stato di attività
Ferma
Chiarezza
Da chiarire
Idoneità per principianti
25/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.