Ok so I need to get the variables from one class's method and update it in another class.
Class which updates method.
public abstract class MovableObject{
protected int speed;
protected int heading;
public void move(){
setX(finalX);
setY(finalY);
}
Class which needs updating:
public class Car extends MoveableObject{
private int height;
private int width;
public Car(){
super.setX(200);
super.setY(2);
}
I have an iterator that goes through a list and checks the X and Y coordinates, currently it keeps printing out (200, 2) constantly but the Car is moving. So the class MovableObject has the updated coordinates but since I'm calling it from Car it's not getting the right coordinates to the moving car. I need to pass the variables from move()
to more than one class also, that should be the same since the Iterator takes care of what is updated right or is this way very complicated?
listObject = new GameObjectCollection();
car = new Car();
listObject.add(car);
System.out.println("CAR: " + ((Car)gameObj).getX() + " " + ((Car)gameObj).getY());