Why won’t my code work to make my spaceship blaster shoot?
float shipX; // player spaceship
float shipY; // player spaceship
float enemyX; //enemy UFO
float enemyY; //enemy UFO
float enemySpeed = 2;
float blastX;
float blastY;
void setup() {
size (500, 500);
}
void drawSpaceship(float shipX, float shipY) {
fill (228, 232, 26);
triangle(shipX, shipY+475, shipX+25, shipY+450, shipX+50, shipY+475);
}
void drawEnemy(float enemyX, float enemyY) {
rectMode(CENTER);
ellipse(enemyX, enemyY+250, 30, 20);
rect(enemyX, enemyY+250, 50, 10);
enemyX += 1;
}
void moveEnemy() {
fill (random(200), 0, 0);
enemyX += enemySpeed;
if (enemyX > width || enemyX < 0) {
enemySpeed *= -1;
}
}
void shootBlaster(float blastX, float blastY) {
fill(0, 0, 200);
triangle (blastX, blastY+495, blastX+5, blastY+490, blastX+10, blastY+495);
if (mousePressed) {
blastY += -5;
} // why is this if condition not causing blastY to move? What am I missing?
}
void draw() {
background(200);
moveEnemy();
drawEnemy(enemyX, enemyY); // enemy UFO
drawSpaceship(mouseX, shipY); // player spaceship at canvas bottom
shootBlaster(mouseX+20, blastY-20); //this code should shoot a triangle up the canvas
}