CodingTrain / CodingTrain/Suggestion-Box
ADD OBJECT to ARRAY when MOUSEPRESSED
- Dominant language
- No language data
- Stars
- 570
- Forks
- 85
- PR merge metrics
- No merged PRs in 30d
Description
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;
}
}
}
}*/`
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.