Don't deactivate the portal if a gem wasn't purified

Signed-off-by: Chris Cromer <chris@cromer.cl>
This commit is contained in:
Chris Cromer 2019-10-14 09:26:14 -03:00
parent c32efe7db0
commit 5b8e36876c
3 changed files with 18 additions and 8 deletions

View File

@ -369,7 +369,7 @@ public class Canvas extends java.awt.Canvas implements Constants {
}
}
ArrayList<Gem> gems = player.getInventoryGems();
ArrayList<Gem> gems = player.getInventoryGems(false);
for (Gem gem : gems) {
gem.drawAnimation(graphicBuffer, xPixels, 8);
xPixels = xPixels + 3 + (gem.getAnimationWidth());

View File

@ -82,7 +82,7 @@ public class Player extends Object implements Constants {
*/
public void keyPressed(int keyCode) {
if (getScene().isDoorOpen()) {
ArrayList<Gem> gems = getInventoryGems();
ArrayList<Gem> gems = getInventoryGems(true);
if (gems.size() < 2) {
getScene().openDoor(false);
}
@ -485,13 +485,17 @@ public class Player extends Object implements Constants {
/**
* Get the gems the player has
*
* @param all Whether or not to return the gems that are still in transition to inventory
* @return Returns an array of the gems the player is carrying
*/
public ArrayList<Gem> getInventoryGems() {
public ArrayList<Gem> getInventoryGems(boolean all) {
ArrayList<Gem> gems = new ArrayList<>();
for (Object object : carrying) {
if (object instanceof Gem && object.getCell().getObjectOnTop() == null) {
if (object instanceof Gem) {
if (!all && object.getCell().getObjectOnTop() != null) {
// Only count the gem as in inventory once it stops showing
continue;
}
gems.add((Gem) object);
}
}

View File

@ -92,15 +92,21 @@ public class Portal extends Object implements Constants {
*/
public void purifyGems() {
if (state == State.ACTIVE) {
ArrayList<Gem> gems = getScene().getCanvas().getPlayer().getInventoryGems();
ArrayList<Gem> gems = getScene().getCanvas().getPlayer().getInventoryGems(true);
boolean purified = false;
for (Gem gem : gems) {
if (gem.getState() == Gem.State.TAINTED) {
gem.setState(Gem.State.PURIFIED);
getScene().getCanvas().getPlayer().gainHealth(2);
if (!purified) {
purified = true;
}
}
}
if (purified) {
setState(State.INACTIVE);
playPortalSound();
}
if (gems.size() == 2) {
getScene().openDoor(true);
}