all entity arrays are now two-dimensional (with map index so entities won't be rendered on any map anymore)
This commit is contained in:
@@ -85,9 +85,9 @@ public class Entity {
|
||||
collisionOn = false;
|
||||
panel.collisionH.checkTile(this);
|
||||
panel.collisionH.checkObject(this, false);
|
||||
panel.collisionH.checkEntity(this, panel.npc);
|
||||
panel.collisionH.checkEntity(this, panel.monster);
|
||||
panel.collisionH.checkEntity(this, panel.iTile);
|
||||
panel.collisionH.checkEntity(this, panel.npc[panel.currentMap.getIndex()]);
|
||||
panel.collisionH.checkEntity(this, panel.monster[panel.currentMap.getIndex()]);
|
||||
panel.collisionH.checkEntity(this, panel.iTile[panel.currentMap.getIndex()]);
|
||||
boolean contactPlayer = panel.collisionH.checkPlayer(this);
|
||||
|
||||
if(this.type == EntityType.MONSTER && contactPlayer) damagePlayer(attack);
|
||||
@@ -205,11 +205,11 @@ public class Entity {
|
||||
|
||||
}
|
||||
public void dropItem(Entity droppedItem) {
|
||||
for(int i = 0; i < panel.obj.length; i++) {
|
||||
if(panel.obj[i] == null) {
|
||||
panel.obj[i] = droppedItem;
|
||||
panel.obj[i].worldX = worldX;
|
||||
panel.obj[i].worldY = worldY;
|
||||
for(int i = 0; i < panel.obj[panel.currentMap.getIndex()].length; i++) {
|
||||
if(panel.obj[panel.currentMap.getIndex()][i] == null) {
|
||||
panel.obj[panel.currentMap.getIndex()][i] = droppedItem;
|
||||
panel.obj[panel.currentMap.getIndex()][i].worldX = worldX;
|
||||
panel.obj[panel.currentMap.getIndex()][i].worldY = worldY;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -72,15 +72,15 @@ public class Player extends Entity {
|
||||
pickObject(objIndex);
|
||||
|
||||
// CHECK ENTITY COLLISION
|
||||
int npcIndex = panel.collisionH.checkEntity(this, panel.npc);
|
||||
int npcIndex = panel.collisionH.checkEntity(this, panel.npc[panel.currentMap.getIndex()]);
|
||||
interactNPC(npcIndex);
|
||||
|
||||
// CHECK MONSTER COLLISION
|
||||
int monsterIndex = panel.collisionH.checkEntity(this, panel.monster);
|
||||
int monsterIndex = panel.collisionH.checkEntity(this, panel.monster[panel.currentMap.getIndex()]);
|
||||
interactMonster(monsterIndex);
|
||||
|
||||
// CHECK INTERACTIVE TILE COLLISION
|
||||
int iTileIndex = panel.collisionH.checkEntity(this, panel.iTile);
|
||||
int iTileIndex = panel.collisionH.checkEntity(this, panel.iTile[panel.currentMap.getIndex()]);
|
||||
|
||||
// CHECK EVENT
|
||||
panel.eventH.checkEvent();
|
||||
@@ -136,11 +136,11 @@ public class Player extends Entity {
|
||||
|
||||
// INTERACTION
|
||||
public void pickObject(int index) {
|
||||
if(index == 999 || panel.obj[index] == null) return;
|
||||
if(index == 999 || panel.obj[panel.currentMap.getIndex()][index] == null) return;
|
||||
|
||||
// PICKUP ONLY
|
||||
if(panel.obj[index].type == EntityType.PICKUP) {
|
||||
panel.obj[index].use(this);
|
||||
if(panel.obj[panel.currentMap.getIndex()][index].type == EntityType.PICKUP) {
|
||||
panel.obj[panel.currentMap.getIndex()][index].use(this);
|
||||
}
|
||||
// INVENTORY ITEMS
|
||||
else {
|
||||
@@ -148,18 +148,18 @@ public class Player extends Entity {
|
||||
panel.ui.addMessage("Your inventory is full!");
|
||||
return;
|
||||
}
|
||||
inventory.add(panel.obj[index]);
|
||||
inventory.add(panel.obj[panel.currentMap.getIndex()][index]);
|
||||
panel.playSE(1);
|
||||
panel.ui.addMessage("Picked up " + panel.obj[index].name + "!");
|
||||
panel.ui.addMessage("Picked up " + panel.obj[panel.currentMap.getIndex()][index].name + "!");
|
||||
}
|
||||
panel.obj[index] = null;
|
||||
panel.obj[panel.currentMap.getIndex()][index] = null;
|
||||
}
|
||||
|
||||
public void interactMonster(int index) {
|
||||
if(index == 999) return;
|
||||
if(invincible || panel.monster[index].dying || !panel.monster[index].alive) return;
|
||||
if(invincible || panel.monster[panel.currentMap.getIndex()][index].dying || !panel.monster[panel.currentMap.getIndex()][index].alive) return;
|
||||
|
||||
int damage = panel.monster[index].attack - defense;
|
||||
int damage = panel.monster[panel.currentMap.getIndex()][index].attack - defense;
|
||||
|
||||
if(damage > 0) {
|
||||
panel.playSE(6);
|
||||
@@ -188,10 +188,10 @@ public class Player extends Entity {
|
||||
solidArea.width = attackArea.width;
|
||||
solidArea.height = attackArea.height;
|
||||
|
||||
int monsterIndex = panel.collisionH.checkEntity(this, panel.monster);
|
||||
int monsterIndex = panel.collisionH.checkEntity(this, panel.monster[panel.currentMap.getIndex()]);
|
||||
damageMonster(monsterIndex, attack);
|
||||
|
||||
int iTileIndex = panel.collisionH.checkEntity(this, panel.iTile);
|
||||
int iTileIndex = panel.collisionH.checkEntity(this, panel.iTile[panel.currentMap.getIndex()]);
|
||||
interactTile(iTileIndex);
|
||||
|
||||
worldX = currentWorldX;
|
||||
@@ -208,32 +208,32 @@ public class Player extends Entity {
|
||||
}
|
||||
public void damageMonster(int index, int attack) {
|
||||
if(index == 999) return;
|
||||
if(panel.monster[index].invincible) return;
|
||||
if(panel.monster[panel.currentMap.getIndex()][index].invincible) return;
|
||||
|
||||
int damage = attack - panel.monster[index].defense;
|
||||
int damage = attack - panel.monster[panel.currentMap.getIndex()][index].defense;
|
||||
|
||||
if(damage > 0) {
|
||||
panel.playSE(5);
|
||||
panel.monster[index].life -= damage;
|
||||
panel.monster[index].invincible = true;
|
||||
panel.monster[panel.currentMap.getIndex()][index].life -= damage;
|
||||
panel.monster[panel.currentMap.getIndex()][index].invincible = true;
|
||||
}
|
||||
|
||||
panel.monster[index].damageReaction();
|
||||
if(panel.monster[index].life <= 0) {
|
||||
panel.monster[index].dying = true;
|
||||
panel.ui.addMessage("Gained +" + panel.monster[index].exp + " XP!");
|
||||
exp += panel.monster[index].exp;
|
||||
panel.monster[panel.currentMap.getIndex()][index].damageReaction();
|
||||
if(panel.monster[panel.currentMap.getIndex()][index].life <= 0) {
|
||||
panel.monster[panel.currentMap.getIndex()][index].dying = true;
|
||||
panel.ui.addMessage("Gained +" + panel.monster[panel.currentMap.getIndex()][index].exp + " XP!");
|
||||
exp += panel.monster[panel.currentMap.getIndex()][index].exp;
|
||||
checkLevelUp();
|
||||
}
|
||||
}
|
||||
public void interactTile(int index) {
|
||||
if(index == 999 || !panel.iTile[index].destructible || panel.iTile[index].invincible) return;
|
||||
if(!panel.iTile[index].meetItemReq(this)) return;
|
||||
panel.iTile[index].playSE();
|
||||
panel.iTile[index].life--;
|
||||
panel.iTile[index].invincible = true;
|
||||
generateParticle(panel.iTile[index], panel.iTile[index]);
|
||||
if(panel.iTile[index].life == 0) panel.iTile[index] = panel.iTile[index].getDestroyedForm();
|
||||
if(index == 999 || !panel.iTile[panel.currentMap.getIndex()][index].destructible || panel.iTile[panel.currentMap.getIndex()][index].invincible) return;
|
||||
if(!panel.iTile[panel.currentMap.getIndex()][index].meetItemReq(this)) return;
|
||||
panel.iTile[panel.currentMap.getIndex()][index].playSE();
|
||||
panel.iTile[panel.currentMap.getIndex()][index].life--;
|
||||
panel.iTile[panel.currentMap.getIndex()][index].invincible = true;
|
||||
generateParticle(panel.iTile[panel.currentMap.getIndex()][index], panel.iTile[panel.currentMap.getIndex()][index]);
|
||||
if(panel.iTile[panel.currentMap.getIndex()][index].life == 0) panel.iTile[panel.currentMap.getIndex()][index] = panel.iTile[panel.currentMap.getIndex()][index].getDestroyedForm();
|
||||
}
|
||||
|
||||
public void interactNPC(int index) {
|
||||
@@ -241,7 +241,7 @@ public class Player extends Entity {
|
||||
//if(!panel.keyH.spacePressed) return; //Only uncomment if text should only appear if player hits space
|
||||
attackCancel = true;
|
||||
panel.gameState = GameState.DIALOGUE;
|
||||
panel.npc[index].speak();
|
||||
panel.npc[panel.currentMap.getIndex()][index].speak();
|
||||
}
|
||||
public void speak() {
|
||||
//This method only exists for character specific things later...
|
||||
@@ -293,8 +293,10 @@ public class Player extends Entity {
|
||||
|
||||
// SETTING THINGS UP
|
||||
public void setDefaultValues() {
|
||||
worldX = panel.tileSize * 23;
|
||||
worldY = panel.tileSize * 21;
|
||||
// worldX = panel.tileSize * 23;
|
||||
// worldY = panel.tileSize * 21;
|
||||
worldX = panel.tileSize * 12;
|
||||
worldY = panel.tileSize * 13;
|
||||
speed = 4;
|
||||
direction = Direction.DOWN;
|
||||
|
||||
|
||||
@@ -25,10 +25,10 @@ public class Projectile extends Entity {
|
||||
public void update() {
|
||||
|
||||
if(user.type == EntityType.PLAYER) {
|
||||
int monsterIndex = panel.collisionH.checkEntity(this, panel.monster);
|
||||
int monsterIndex = panel.collisionH.checkEntity(this, panel.monster[panel.currentMap.getIndex()]);
|
||||
if(monsterIndex != 999) {
|
||||
panel.player.damageMonster(monsterIndex, attack);
|
||||
generateParticle(user.projectile, panel.monster[monsterIndex]);
|
||||
generateParticle(user.projectile, panel.monster[panel.currentMap.getIndex()][monsterIndex]);
|
||||
alive = false;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user