Help with processing shooting game
in
Programming Questions
•
2 years ago
This is what I just started:
int life=20;
int level=1;
Enemy[]Enemies=new Enemy[level*3];
void setup(){
size(1000,500);
smooth();
for (int i=0;i<Enemies.length;i++){
Enemies[i]=new Enemy(1000,random(height), level*10, 5);
}
}
void draw(){
background(255);
for (int i=0;i<Enemies.length;i++){
Enemies[i].display();
Enemies[i].move();
}
}
class Enemy{
float xpos;
float ypos;
int health;
float speed;
Enemy(float tempXpos, float tempYpos, int tempHealth, float tempSpeed){
xpos= tempXpos;
ypos= tempXpos;
health= tempHealth;
speed= tempSpeed;
}
void display(){
stroke(1,1,33);
fill(72,7,7);
beginShape();
vertex(xpos-4,ypos);
vertex(xpos,ypos-2);
vertex(xpos+2,ypos-4);
vertex(xpos+1,ypos);
vertex(xpos+2,ypos+4);
vertex(xpos,ypos+2);
endShape(CLOSE);
}
void move(){
xpos=xpos-speed;
if(xpos+2<0){
life-=1;
}
}
}
what happens is that I don't see the Enemies. Also, my teacher thought that it would be too hard to explain how to do something so she skipped it and I need someone to help me with it. Whenever a condition is met for a class, all of the objects disappear(ex.I shoot one and all of them disappear). How do you fix that?
1