refactor collision handling and improve game state reset functionality
This commit is contained in:
@@ -29,7 +29,7 @@ public class UI {
|
||||
private int transCount;
|
||||
private int sleepCount;
|
||||
private int charIndex;
|
||||
private String combinedText = "";
|
||||
private String combinedText;
|
||||
|
||||
// SUB-STATES
|
||||
public TradeState tradeState = TradeState.SELECT;
|
||||
@@ -757,7 +757,6 @@ public class UI {
|
||||
if(commandNum == 1) {
|
||||
graphics2d.drawString(">", textX-25, textY);
|
||||
if(panel.keyH.spacePressed) optionState = OptionState.OVERVIEW;
|
||||
panel.resetGame(true);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -59,6 +59,10 @@ public class CollisionHandler {
|
||||
}
|
||||
public int checkObject(Entity entity, boolean player) {
|
||||
int index = 999;
|
||||
|
||||
Direction direction = entity.direction;
|
||||
if(entity.knockback) direction = entity.knockbackDirection;
|
||||
|
||||
int c = -1;
|
||||
|
||||
for(Entity obj : panel.obj[panel.currentMap.getIndex()]) {
|
||||
@@ -71,7 +75,7 @@ public class CollisionHandler {
|
||||
obj.solidArea.x += obj.worldX;
|
||||
obj.solidArea.y += obj.worldY;
|
||||
|
||||
parseSolidArea(entity);
|
||||
parseSolidArea(entity, direction);
|
||||
|
||||
if (entity.solidArea.intersects(obj.solidArea)) {
|
||||
if (obj.collision) entity.collisionOn = true;
|
||||
@@ -90,6 +94,10 @@ public class CollisionHandler {
|
||||
//NPC OR MONSTER COLLISION
|
||||
public int checkEntity(Entity entity, Entity[] target) {
|
||||
int index = 999;
|
||||
|
||||
Direction direction = entity.direction;
|
||||
if(entity.knockback) direction = entity.knockbackDirection;
|
||||
|
||||
int c = -1;
|
||||
|
||||
for(Entity e : target) {
|
||||
@@ -102,7 +110,7 @@ public class CollisionHandler {
|
||||
e.solidArea.x += e.worldX;
|
||||
e.solidArea.y += e.worldY;
|
||||
|
||||
parseSolidArea(entity);
|
||||
parseSolidArea(entity, direction);
|
||||
|
||||
if (entity.solidArea.intersects(e.solidArea) && e != entity) {
|
||||
entity.collisionOn = true;
|
||||
@@ -149,4 +157,13 @@ public class CollisionHandler {
|
||||
}
|
||||
}
|
||||
|
||||
private void parseSolidArea(Entity entity, Direction direction) {
|
||||
switch (direction) {
|
||||
case UP -> entity.solidArea.y -= entity.speed;
|
||||
case DOWN -> entity.solidArea.y += entity.speed;
|
||||
case LEFT -> entity.solidArea.x -= entity.speed;
|
||||
case RIGHT -> entity.solidArea.x += entity.speed;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -33,6 +33,7 @@ public class KeyHandler implements KeyListener {
|
||||
switch (panel.ui.commandNum) {
|
||||
case 0:
|
||||
panel.gameState = GameState.PLAY;
|
||||
panel.resetGame(true);
|
||||
panel.playMusic(0);
|
||||
break;
|
||||
case 1:
|
||||
|
||||
@@ -118,7 +118,7 @@ public class SaveLoad {
|
||||
panel.obj[mapNum][i] = getObject(ds.mapObjectNames[mapNum][i]);
|
||||
panel.obj[mapNum][i].worldX = ds.mapObjectWorldX[mapNum][i];
|
||||
panel.obj[mapNum][i].worldY = ds.mapObjectWorldY[mapNum][i];
|
||||
if (ds.mapObjectLootNames[mapNum][i] != null) panel.obj[mapNum][i].loot = getObject(ds.mapObjectLootNames[mapNum][i]);
|
||||
if (ds.mapObjectLootNames[mapNum][i] != null) panel.obj[mapNum][i].setLoot(getObject(ds.mapObjectLootNames[mapNum][i]));
|
||||
panel.obj[mapNum][i].opened = ds.mapObjectOpened[mapNum][i];
|
||||
panel.obj[mapNum][i].setDialogue();
|
||||
if(panel.obj[mapNum][i].opened) panel.obj[mapNum][i].down1 = panel.obj[mapNum][i].image2;
|
||||
|
||||
@@ -367,7 +367,6 @@ public class Player extends Entity {
|
||||
inventory.add(currentWeapon);
|
||||
inventory.add(currentShield);
|
||||
inventory.add(new KeyObj(panel));
|
||||
inventory.add(new LanternObj(panel));
|
||||
}
|
||||
public void setDialogue() {
|
||||
dialogue[0][0] = "You are level " + level + " now!\nYou feel stronger!";
|
||||
|
||||
Reference in New Issue
Block a user