I am making a game where random obstacles appear. The obstacles will move towards you. I currently have this code to animate the obstacles.
for (int i = 0; i < obstacle.size(); i++){ // animate walls
obstacle.elementAt(i).x -= 1;
}
My vector multiple instances of the Walls class
Walls w = new Walls ();
Vector<w> obstacle = new Vector<w> (5,5);
and this is what the Walls class looks like
import java.awt.Rectangle;
class Walls {
Walls (){
randomLocation ();
}
public void randomLocation() {
// TODO Auto-generated method stub
x = 510;
y = (int)Math.round (Math.random ()*300);
makeRect ();
}
private void makeRect() {
// TODO Auto-generated method stub
rect = new Rectangle (x,y,10,30);
}
public int x = 510;
public int y;
public Rectangle rect;
}
Eclipse gave me an error if my class that draws the objects didn't look like this
public class CopterG<w> extends JPanel implements KeyListener, ActionListener{
...
...
}
I am not sure what the <w> does in the drawing class.
I am trying to communicate from the class that draws the images (also animates them) with the Walls class which stores the positions of the walls. I don't know how I could fix the issue with the animation. It underlines the .x in the first code. I have made a snake game that works kind of like this, but that didn't give me any errors. I tried comparing the two and they are extremely similar.
If you would like me to re explain it maybe more clearly then I will.
Thanks for any help.