I have parent classes that create shape entities and I can choose to make the entity a collidable entity or a Non-Collidable Entity. So far, in this project, Circles and Rectangles are collidables. Whereas, the ellipse is a Non-Collidable. The funny thing is even though I have created multiple circles and rectangles. Only 1 pair of circles and rectangles are collidable whereas the rest isn't. I am really confused as I thought the child always inherits the property from the parent. Therefore, if all shapes have the same parent. I do not see how is it possible that the child does not behave the same way.
// CIRCLE ENTITY
public class daCircle extends Collidable{
protected float circleRadius;
protected int upKey;
protected int downKey;
protected int leftKey;
protected int rightKey;
public daCircle(int circleXPos, int circleYPos, float circleRadius, int circleSpeed, Color circleColor,
int upKey, int downKey, int leftKey, int rightKey) {
super(circleXPos, circleYPos, circleColor, circleSpeed);
this.circleRadius = circleRadius;
super.keyMovementList.set(0, upKey);
super.keyMovementList.set(1, downKey);
super.keyMovementList.set(2, leftKey);
super.keyMovementList.set(3, rightKey);
}
}
// Collidable
public void checkForCollision(ArrayList<GeometricObjects> listOfAllShapes, String direction) {
for (GeometricObjects daShape : listOfAllShapes) {
if (daShape instanceof Collidable) {
Iterator<GeometricObjects> iter = listOfAllShapes.iterator();
while(iter.hasNext()) {
GeometricObjects nextShape = iter.next();
if (daShape != nextShape) {
if (daShape instanceof daCircle && nextShape instanceof daCircle) {
setCirclesCollisionFlag(isCirclesColliding((daCircle)daShape, (daCircle)nextShape, direction));
}
if (daShape instanceof daRect && nextShape instanceof daRect) {
setRectanglesCollisionFlag(isRectanglesColliding((daRect)daShape, (daRect)nextShape, direction));
}
if (daShape instanceof daCircle && nextShape instanceof daRect ) {
setCircleRectangleCollisionFlag(circIntersectRect((daCircle)daShape, (daRect)nextShape, direction));
}
}
}
}
}
}
// Controller
public void movementController(ArrayList<GeometricObjects> allGeometricShapes) {
int temporaryObjSpeedHolder = 0;
GeometricObjects daObject = (GeometricObjects) this;
if (daObject instanceof Collidable) {
collidableShape = (Collidable) daObject;
daObject = collidableShape;
}
// if (Gdx.input.isTouched()) {
// daObject.setXPos(Gdx.input.getX());
// daObject.setYPos(Gdx.graphics.getHeight() - Gdx.input.getY());
// }
if(Gdx.input.isKeyPressed(keyMovementList.get(0))){
if (daObject instanceof Collidable) {
collidableShape.checkForCollision(allGeometricShapes, "UP");
}
if (circlesAreColliding || rectanglesAreColliding || circleRectangleAreColliding) {
temporaryObjSpeedHolder = incomingCollisionSpeed;
} else {
temporaryObjSpeedHolder = objectSpeed;
}
daObject.yPos += temporaryObjSpeedHolder;
} else if(Gdx.input.isKeyPressed(keyMovementList.get(1))){
if (daObject instanceof Collidable) {
collidableShape.checkForCollision(allGeometricShapes, "DOWN");
}
if (circlesAreColliding || rectanglesAreColliding || circleRectangleAreColliding) {
temporaryObjSpeedHolder = incomingCollisionSpeed;
} else {
temporaryObjSpeedHolder = objectSpeed;
}
daObject.yPos -= temporaryObjSpeedHolder;
}
if(Gdx.input.isKeyPressed(keyMovementList.get(2))){
if (daObject instanceof Collidable) {
collidableShape.checkForCollision(allGeometricShapes, "LEFT");
}
if (circlesAreColliding || rectanglesAreColliding || circleRectangleAreColliding) {
temporaryObjSpeedHolder = incomingCollisionSpeed;
} else {
temporaryObjSpeedHolder = objectSpeed;
}
daObject.xPos -= temporaryObjSpeedHolder;
} else if(Gdx.input.isKeyPressed(keyMovementList.get(3))){
if (daObject instanceof Collidable) {
collidableShape.checkForCollision(allGeometricShapes, "RIGHT");
}
if (circlesAreColliding || rectanglesAreColliding || circleRectangleAreColliding) {
temporaryObjSpeedHolder = incomingCollisionSpeed;
} else {
temporaryObjSpeedHolder = objectSpeed;
}
daObject.xPos += temporaryObjSpeedHolder;
}
I have created many circles and rectangles and discovered that only the latest created shapes are able to collide. I thought that maybe since the shapes are all on different layers that it might not be able to collide. I really dk what else I can be testing to see why it is the way it is. If you guys got suggestions of testing. I'm all for it!