I need to create a spaceship that shoots lasers from the tip of the spaceship and goes up when the mouse is clicked. The lasers just need to go vertically upwards, that’s it.
I HAVE SPENT HOURS trying to figure out how to make the lasers move up and how you can have multiple on the screen if you hit the mouse multiple times.
Everything is done expect for the lasers.
I was hoping someone can help me.
Here is the code:
int rSphere = 0;
int gSphere = 0;
int bSphere = 0;
int speed = 10;
void setup()
{
size(640, 480);
noCursor();
}
void draw()
{
background(0);
glowingSphere();
fill(255);
spaceship();
thrust();
stroke(255);
int laserX = mouseX;
int laserY = mouseY;
}
void glowingSphere()
{
int rInc = (int)(random(0, 3));
int gInc = (int)(random(0, 4));
int bInc = (int)(random(0, 2));
int glowingSphereX = mouseX;
int glowingSphereY = mouseY;
glowingSphereX = constrain(glowingSphereX, 0 + 17, width - 17);
glowingSphereY = constrain(glowingSphereY, 0 + 20, height - 30);
if (rSphere >= 230)
{
rSphere += -215;
}
if (gSphere >= 230)
{
gSphere += -215;
}
if (bSphere >= 230)
{
bSphere += -215;
}
fill(rSphere += rInc, gSphere += gInc, bSphere += bInc);
noStroke();
ellipse(glowingSphereX, glowingSphereY + 10, 27, 36);
}
void spaceship()
{
int spaceshipX = mouseX;
int spaceshipY = mouseY;
spaceshipX = constrain(spaceshipX, 17, width - 17);
spaceshipY = constrain(mouseY, 20, height - 30);
triangle(spaceshipX, spaceshipY - 20, spaceshipX + 17, spaceshipY + 30, spaceshipX - 17, spaceshipY + 30);
fill(0);
triangle(spaceshipX, spaceshipY - 5, spaceshipX + 7, spaceshipY + 22, spaceshipX - 7, spaceshipY + 22);
}
void thrust()
{
int thrustX = mouseX;
int thrustY = mouseY;
thrustX = constrain(thrustX, 0 + 17, width - 17);
thrustY = constrain(thrustY, 0 + 23, height - 23);
fill(200, 0, 0);
int radius = (int)(random(5, 20));
int xPos = (int)(random(-7, 7));
int yPos = (int)(random(-4, 4));
ellipse(thrustX + xPos, thrustY + 42 + yPos, radius, radius);
}