//Global Variables
PImage player, enemy, rocket;
int playerX;
int rocketX;
int rocketY;
//Following variables from funprogramming.org
float[] x = new float[250];// creates x values for 250 stars
float[] y = new float[250];// creates y values for 250 stars
float[] speed = new float[250];// creates speed values for 250 stars
void setup() {
size(625, 1000);
background(0);
stroke(255);
player = loadImage("spaceship.png");
enemy = loadImage("enemy.png");
rocket = loadImage("rocket.png");
//from funprogramming.org
int i = 0;
while (i < 250) {
x[i] = random(0, width);//assigns a random value to all xs
y[i] = random(0, height);//assigns a random value to all ys
speed[i] = random(1, 7);//assigns a random value to all speeds
i = i + 1;
}
}//end setup
void draw() {
background(0);
imageMode(CENTER);
image(player, playerX, 900);
playerX = mouseX;
rocketX = int(mouseX);
rocketY = 760;
if (mouseButton == LEFT){
rocket();
rocketY += 4;
}
//from funprogramming
int i = 0;
while (i < 250) {//draws the stars in point function and adds motion
float co = map(speed[i], 1, 5, 100, 255);
stroke(co);
strokeWeight(speed[i]);
point(x[i], y[i]);
y[i] = y[i] + speed[i] / 2;
if (y[i] > 1000) {
y[i] = 0;
}
i = i + 1;//adds 1 to i to stop more iterations of the star than needed
}
}//end draw
void rocket(){
image(rocket, rocketX, rocketY);
}
I have been able to create a character but when I try shooting the rocket the Y value won’t go up and when the mouse is moved the rocket disappears. How should I go about this problem?