Why does my bullet arrayList stop working when the spaceship is moved with void keyPressed????
in
Programming Questions
•
7 months ago
I am new to Processing and was wondering if anyone would be so kind as to help me with this puzzler. The bullets start to fire with the mousePressed option..... however when they do the spaceship will not respond to movements with the left right keys... Any ideas would be appreciatted...
Many thanks..
Star [] star = new Star [50];//Declare as a collection/array of stars and the size - 50.
Enemy [] enemy = new Enemy[3];//Declare classes
Planet [] planet = new Planet[6];
Enemy [] enemy = new Enemy[3];//Declare classes
Planet [] planet = new Planet[6];
ArrayList bulletCollection;
User user;
import ddf.minim.*;
Minim minim;
AudioPlayer player;
AudioSample crash;
AudioPlayer player;
AudioSample crash;
void setup() {
size(1000, 700, P3D);
smooth();
size(1000, 700, P3D);
smooth();
minim = new Minim(this);
player = minim.loadFile("theme.mp3");
player.play();
crash = minim.loadSample("crash.mp3");
player = minim.loadFile("theme.mp3");
player.play();
crash = minim.loadSample("crash.mp3");
bulletCollection = new ArrayList();
//for (int i = 0; i < 20; i ++) {
//Bullets bullets = new Bullets(200, 200, 40, 40);
//bulletCollection.add(bullets);
//}
//for (int i = 0; i < 20; i ++) {
//Bullets bullets = new Bullets(200, 200, 40, 40);
//bulletCollection.add(bullets);
//}
for (int i = 0; i < 6; i ++) {
planet [i] = new Planet(random(0, width), random(0, height), 15, 15);
}
planet [i] = new Planet(random(0, width), random(0, height), 15, 15);
}
for (int i = 0; i < 2; i ++) {
enemy [i] = new Enemy(1050, random(100, 600), 50, 50);//initialize parameters in here
}
enemy [i] = new Enemy(1050, random(100, 600), 50, 50);//initialize parameters in here
}
PImage simg = loadImage("ship.jpg");
user = new User(75, 350, simg);
user = new User(75, 350, simg);
for (int i = 0; i < 50; i ++) {
star [i] = new Star(random (0, width), random(0, height), 5, 5);
}
}
star [i] = new Star(random (0, width), random(0, height), 5, 5);
}
}
void draw() {
background(0);
noStroke();
noStroke();
for (int i = 0; i < bulletCollection.size() ; i ++) {
Bullets bullets = (Bullets) bulletCollection.get(i);
bullets.run();
}
Bullets bullets = (Bullets) bulletCollection.get(i);
bullets.run();
}
for (int i = 0; i < 50; i ++) {
star[i].run();//call upon all elements of the array. If i was a 0 itwould call one star
star[i].move();
if (star[i].x < 0) {
star [i] = new Star( width, random(0, height), 5, 5);
}
}
star[i].run();//call upon all elements of the array. If i was a 0 itwould call one star
star[i].move();
if (star[i].x < 0) {
star [i] = new Star( width, random(0, height), 5, 5);
}
}
for (int i = 0; i < 2; i ++) {
enemy[i].run();
}
enemy[i].run();
}
for (int i = 0; i < 6; i ++) {
planet[i].display();
planet[i].move();
if (planet[i].x < 0) {
planet [i] = new Planet(random(1000, 1200), random(0, height), 15, 15);
}
}
planet[i].display();
planet[i].move();
if (planet[i].x < 0) {
planet [i] = new Planet(random(1000, 1200), random(0, height), 15, 15);
}
}
user.run();
}
}
void keyPressed() {
user.move();
}
user.move();
}
void mousePressed() {
Bullets bullets = new Bullets(user.imgX + 172, user.imgY + 42, 5, 2);
bulletCollection.add(bullets);
}
bulletCollection.add(bullets);
}
void stop()
{
// always close Minim audio classes when you are done with them
crash.close();
minim.stop();
{
// always close Minim audio classes when you are done with them
crash.close();
minim.stop();
super.stop();
}
}
1