I’m implementing a game and I have some clases like:
GameObject (Abstract)
CircularGameObject
RectangularGameObject
They basically store the position (x,y) and the different shapes for checking collisions.
Now I want to implement the classes Wall (Rectangular) and Bomb (Circular). Both can be enabled or disabled so I declare
public interface Activable {
public void setEnabled(boolean status);
public boolean isEnabled();
}
And I have one List for storing a reference to the items that kills the player on the collisions (Walls and Bombs).
How can I declare an ArrayList of objects that extends GameObject and implements Activable?
I tried declaring a class:
public class ActivableGameObject extends GameObject implements Activable{};
but the compiler doesn’t allow to assign to that reference a Bomb for example (Because is a CircularGameObject)
One way would be be to have:
then:
That way you can use have make the array use Activable.