Hi everyone,
I am a newbie in processing, at my early stages of learning and playing with this amazing language. I am trying to create a kind of “space invader” program from scratch.
I don’t want to get inspired by the real one, just trying to make my own version to challenge myself.
I have divided my reflexion into smaller manageable parts and now i am stucked. I am currently working on the “bullets part”. The idea is to create two shots (controlled by mouseX & mouseY) every time that mousePressed is activated.
I am using an ArrayList, and i can’t understand why but it says that the functions get() & remove() do not exist.
Can someone help me on this one please?
Thank you,
Rémy
ArrayList<Bullet> bullets;
void setup(){
size(400,400);
smooth();
bullets = new ArrayList<Bullet>();
bullets.add(new Bullet(mouseX,mouseY));
}
void display(){
background(255);
for (int i = bullets.size()-1; i >= 0; i--) {
Bullet bullets = bullets.get(i);
bullets.move();
bullets.display();
if (bullets.finished()){
bullets.remove(i);
}
}
}
void mousePressed(){
bullets.add(new Bullet(mouseX,mouseY));
}
class Bullet{
float bulletX1, bulletY1;
float bulletX2, bulletY2;
int r;
int bulletSpeed;
Bullet(float _x, float _y){
bulletX1 = _x - 10;
bulletY1 = _y;
bulletX2 = _x +10;
bulletY2 = _y;
r = 6;
bulletSpeed = 1;
}
void move(){
bulletY1 -= bulletSpeed;
bulletY2 -= bulletSpeed;
}
boolean finished() {
if ((bulletY1<0) || (bulletY2<0)) {
return true;
} else {
return false;
}
}
void display(){
fill(255,0,0);
noStroke();
ellipse (bulletX1,bulletY1,r,r);
ellipse (bulletX2,bulletY2,r,r);
}
}