Skip to content
Snippets Groups Projects
Commit d544faa8 authored by Schlütter Yannik's avatar Schlütter Yannik
Browse files

Fixed the addition of explosion collisionHandler

parent 22e03c8d
No related branches found
No related tags found
4 merge requests!74V1,!73Initial commit,!71Merge DataBase into Development,!33Update: Items, spawn locations of items, hit rate, i-frames
......@@ -23,7 +23,7 @@ public class Explosion implements IEntity {
private Image[] frames = new Image[6];
private final GraphicsContext graphicsContext;
private BoundingBox boxCollider;
private final ObjectType OBJECT_TYPE = ObjectType.BOMB;
private final ObjectType OBJECT_TYPE = ObjectType.EXPLOSION;
private ObjectStatus OBJECT_STATUS = ObjectStatus.UNUSED;
public Explosion(int posX, int posY, GraphicsContext graphicsContext) {
this.posX = posX;
......
......@@ -305,7 +305,7 @@ class Player implements IEntity {
}
} else if (gameplayObject.getOBJECT_TYPE() == ObjectType.EXPLOSION) {
if (gameplayObject.getBoxCollider().intersects(boxCollider)) {
log.info("Collision with explosion");
log.debug("Collision with explosion");
gotHit(10);
}
}
......@@ -337,7 +337,7 @@ class Player implements IEntity {
gameplayObjects.add(explosion);
runtimeInfo.setGameplayObjects(gameplayObjects);
log.info("explosion placed");
checkTileDestroyable(graphicsContext);
changeCheckedTileDestructable(graphicsContext);
}
public void checkChangeTiles(GraphicsContext graphicsContext) {
......@@ -345,14 +345,14 @@ class Player implements IEntity {
boolean stopDown = false, stopUp = false, stopRight = false, stopLeft = false;
boolean stopUpRight = false, stopUpLeft = false, stopDownRight = false, stopDownLeft = false;
int xTile = mapPosX / scaledTileSize;
int xTile = mapPosX / scaledTileSize; //TODO: Fix sometimes bad bomb spawning
int yTile = mapPosY / scaledTileSize;
int yUp = yTile;
int xRight = xTile;
int yDown = yTile;
int xLeft = xTile;
final int blastradius = 2; //should be 1-2
isDestructible = checkPlacingTileDestructible(yTile, xTile);
isDestructible = checkTilePlacing(yTile, xTile);
if (isDestructible) {
for (int i = 0; i < blastradius; i++) {
yDown += 1;
......@@ -360,9 +360,9 @@ class Player implements IEntity {
xRight += 1;
xLeft -= 1;
if(yDown < 18 && yDown >= 0 && xTile < 18 && xTile >= 0) {
checkTileDestroyable(graphicsContext);
//changeCheckedTileDestroyable(graphicsContext);
//DOWN
isDestructible = checkPlacingTileDestructible(yDown, xTile);
isDestructible = checkTilePlacing(yDown, xTile);
if (isDestructible && !stopDown) {
spawnExplosion(yDown, xTile, graphicsContext);
//log.info("UP: Explosion should spawn at " + yDown + " and " + xTile);
......@@ -371,8 +371,8 @@ class Player implements IEntity {
}
}//UP
if(yUp < 18 && yUp >= 0 && xTile < 18 && xTile >= 0) {
checkTileDestroyable(graphicsContext);
isDestructible = checkPlacingTileDestructible(yUp, xTile);
//changeCheckedTileDestroyable(graphicsContext);
isDestructible = checkTilePlacing(yUp, xTile);
if (isDestructible && !stopUp) {
spawnExplosion(yUp, xTile, graphicsContext);
//log.info("UP: Explosion should spawn at " + yUp + " and " + xTile);
......@@ -380,8 +380,8 @@ class Player implements IEntity {
stopUp = true;
}//RIGHT
}if(yTile < 18 && yTile >= 0 && xRight < 18 && xRight >= 0) {
checkTileDestroyable(graphicsContext);
isDestructible = checkPlacingTileDestructible(yTile, xRight);
//changeCheckedTileDestroyable(graphicsContext);
isDestructible = checkTilePlacing(yTile, xRight);
if (isDestructible && !stopRight) {
spawnExplosion(yTile, xRight, graphicsContext);
//log.info("RIGHT: Explosion should spawn at " + yTile + " and " + xRight);
......@@ -389,8 +389,8 @@ class Player implements IEntity {
stopRight = true;
}//LEFT
}if(yTile < 18 && yTile >= 0 && xLeft < 18 && xLeft >= 0) {
checkTileDestroyable(graphicsContext);
isDestructible = checkPlacingTileDestructible(yTile, xLeft);
//changeCheckedTileDestroyable(graphicsContext);
isDestructible = checkTilePlacing(yTile, xLeft);
if (isDestructible && !stopLeft) {
spawnExplosion(yTile, xLeft, graphicsContext);
//log.info("LEFT: Explosion should spawn at " + yTile + " and " + xLeft);
......@@ -430,8 +430,8 @@ class Player implements IEntity {
}
} //DownRight
if(yDown < 18 && yDown >= 0 && xRight < 18 && xRight >= 0) {
checkTileDestroyable(graphicsContext);
isDestructible = checkTileDestructible(yDown, xRight);
changeCheckedTileDestroyable(graphicsContext);
isDestructible = checkPlacingTileDestructible(yDown, xRight);
if (isDestructible && !stopDownRight) {
spawnExplosion(yDown, xRight, graphicsContext);
//log.info("LEFT: Explosion should spawn at " + yDown + " and " + xRight);
......@@ -442,24 +442,27 @@ class Player implements IEntity {
}
}
}
public boolean checkPlacingTileDestructible(int y, int x) { //Change it with a DestructionHandler like CollisionHandler //tileSet[xTile].getDestruction();
public boolean checkTilePlacing(int y, int x) { //Change it with a DestructionHandler like CollisionHandler //tileSet[xTile].getDestruction();
return TileManager.tileMap[y][x] >= 20 || TileManager.tileMap[y][x] <= 9;
}
public void checkTileDestroyable(GraphicsContext graphicsContext){
int x,y;
public void changeCheckedTileDestructable(GraphicsContext graphicsContext){ //TODO: This Method gets used 2 in different methods
int x,y; //TODO Fix Explosion
List<IEntity> gameplayObjects = runtimeInfo.getGameplayObjects();
List<IEntity> explosionList = gameplayObjects.stream().filter(obj -> obj.getOBJECT_TYPE() != ObjectType.EXPLOSION)
.toList();
for (IEntity iEntity : explosionList) {
y = iEntity.getMapPosY() / scaledTileSize;
x = iEntity.getMapPosX() / scaledTileSize;
if (TileManager.tileMap[y][x] >= 19) {
List<IEntity> explosionList = gameplayObjects.stream().filter(obj -> obj.getOBJECT_TYPE() == ObjectType.EXPLOSION)
.collect(Collectors.toList());
for (int i =0; i < explosionList.size(); i++) {
y = (explosionList.get(i).getMapPosY()) / scaledTileSize;
x = (explosionList.get(i).getMapPosX()) / scaledTileSize;
if (TileManager.tileMap[y][x] > 19) {
TileManager.tileMap[y][x] = 0;
//spawning heart entity
spawnHeart(x * scaledTileSize, y * scaledTileSize, graphicsContext);
/*List<IEntity> updateList = gameplayObjects.stream().filter(obj -> obj.getOBJECT_STATUS() != ObjectStatus.USED)
.collect(Collectors.toList());
runtimeInfo.setGameplayObjects(updateList);*/
}
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment