diff --git a/.idea/gradle.xml b/.idea/gradle.xml
index 310e0f2..13a8247 100644
--- a/.idea/gradle.xml
+++ b/.idea/gradle.xml
@@ -1,5 +1,6 @@
+
-
+
\ No newline at end of file
diff --git a/build.gradle b/build.gradle
index 3137788..6831dc3 100644
--- a/build.gradle
+++ b/build.gradle
@@ -22,6 +22,7 @@ group 'cl.cromer.azaraka'
version '1.0.0'
sourceCompatibility = 1.8
+targetCompatibility = 1.8
mainClassName = "cl.cromer.azaraka.Main"
@@ -37,7 +38,9 @@ dependencies {
jar {
manifest {
attributes "Main-Class": "$mainClassName",
- 'Class-Path': configurations.default.files.collect { "$it.name" }.join(' ')
+ 'Class-Path': configurations.default.files.collect { "$it.name" }.join(' '),
+ "Implementation-Title": "Gradle",
+ "Implementation-Version": "$gradle.gradleVersion"
}
// This adds the libs into the jar
diff --git a/src/main/java/cl/cromer/azaraka/Celda.java b/src/main/java/cl/cromer/azaraka/Celda.java
index ec4ed66..e4d704f 100644
--- a/src/main/java/cl/cromer/azaraka/Celda.java
+++ b/src/main/java/cl/cromer/azaraka/Celda.java
@@ -21,6 +21,8 @@ import javax.swing.*;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.util.ArrayList;
+import java.util.LinkedHashMap;
+import java.util.Map;
/**
* This class is a cell that will contain a game element such as a player, enemy, prize, etc
@@ -43,17 +45,21 @@ public class Celda extends JComponent implements Constantes {
*/
private final int y;
/**
- * The textures to show in this cell
+ * A map containing the textures used in the cell, LinkedHashMap is used to maintain the order of images
*/
- private final ArrayList textures = new ArrayList<>();
- /**
- * The texture numbers
- */
- private final ArrayList textureNumbers = new ArrayList<>();
+ private final LinkedHashMap textures = new LinkedHashMap<>();
/**
* The object in the cell
*/
private Object object = null;
+ /**
+ * An object that doesn't collide and is drawn on top of the other sprites
+ */
+ private Object objectOnTop = null;
+ /**
+ * An object that doesn't collide and is drawn below the other sprites
+ */
+ private Object objectOnBottom = null;
/**
* Initialize the cell with its coordinates
@@ -88,6 +94,51 @@ public class Celda extends JComponent implements Constantes {
this.object = object;
}
+ /**
+ * Get the top object
+ *
+ * @return Returns the top object
+ */
+ public Object getObjectOnTop() {
+ return objectOnTop;
+ }
+
+ /**
+ * Set a top object
+ *
+ * @param object The top object
+ */
+ public void setObjectOnTop(Object object) {
+ this.objectOnTop = object;
+ }
+
+ /**
+ * Get a bottom object
+ *
+ * @return Returns the bottom object
+ */
+ public Object getObjectOnBottom() {
+ return objectOnBottom;
+ }
+
+ /**
+ * Set a bottom object
+ *
+ * @param object The object
+ */
+ public void setObjectOnBottom(Object object) {
+ this.objectOnBottom = object;
+ }
+
+ /**
+ * Check if cell contains an object
+ *
+ * @return Returns true if it contains an object or false otherwise
+ */
+ public boolean containsObject() {
+ return (object != null || objectOnTop != null || objectOnBottom != null);
+ }
+
/**
* Get the x coordinate of the cell
*
@@ -113,25 +164,27 @@ public class Celda extends JComponent implements Constantes {
* @param textureNumber The texture's number
*/
public void addTexture(BufferedImage texture, int textureNumber) {
- textures.add(texture);
- textureNumbers.add(textureNumber);
+ textures.put(textureNumber, texture);
}
/**
- * Remove the texture that is on the top of the stack
+ * Remove the texture from the map
*/
- public void removeTopTexture() {
- textures.remove(textures.size() - 1);
- textureNumbers.remove(textureNumbers.size() - 1);
+ public void removeTexture(int texture) {
+ textures.remove(texture);
}
/**
- * Get the numbers of the textures
+ * Get an array list of the texture numbers used
*
- * @return Returns an array list containing the texture numbers
+ * @return Returns an array list of texture numbers
*/
public ArrayList getTextureNumbers() {
- return textureNumbers;
+ ArrayList arrayList = new ArrayList<>();
+ for (Map.Entry entry : textures.entrySet()) {
+ arrayList.add(entry.getKey());
+ }
+ return arrayList;
}
/**
@@ -151,18 +204,27 @@ public class Celda extends JComponent implements Constantes {
*/
@Override
public void update(Graphics g) {
- // Don't replace with foreach because it can cause a race condition
- //noinspection ForLoopReplaceableByForEach
- for (int i = 0; i < textures.size(); i++) {
- BufferedImage texture = textures.get(i);
+ // Draw the textures in the cell
+ for (Map.Entry entry : textures.entrySet()) {
+ BufferedImage texture = entry.getValue();
if (texture != null) {
g.drawImage(texture, xPixels, yPixels, null);
}
}
+ // Draw the bottom sprite
+ if (objectOnBottom != null) {
+ objectOnBottom.drawAnimation(g, xPixels, yPixels);
+ }
+
// Draw a sprite in the cell if needed
if (object != null) {
object.drawAnimation(g, xPixels, yPixels);
}
+
+ // Draw the top sprite
+ if (objectOnTop != null) {
+ objectOnTop.drawAnimation(g, xPixels, yPixels);
+ }
}
}
\ No newline at end of file
diff --git a/src/main/java/cl/cromer/azaraka/Constantes.java b/src/main/java/cl/cromer/azaraka/Constantes.java
index 46e5eeb..64c4443 100644
--- a/src/main/java/cl/cromer/azaraka/Constantes.java
+++ b/src/main/java/cl/cromer/azaraka/Constantes.java
@@ -203,7 +203,7 @@ public interface Constantes {
/**
* The global log level is used if the individual log levels are not
*/
- GLOBAL(Level.WARNING),
+ GLOBAL(Level.SEVERE),
/**
* The main log level
*/
@@ -256,6 +256,10 @@ public interface Constantes {
* The json log level
*/
JSON(Level.INFO),
+ /**
+ * The gem log level
+ */
+ GEM(Level.INFO),
/**
* The portal log level
*/
diff --git a/src/main/java/cl/cromer/azaraka/Escenario.java b/src/main/java/cl/cromer/azaraka/Escenario.java
index 1d86847..0ff8e0d 100644
--- a/src/main/java/cl/cromer/azaraka/Escenario.java
+++ b/src/main/java/cl/cromer/azaraka/Escenario.java
@@ -190,14 +190,14 @@ public class Escenario extends JComponent implements Constantes {
}
random = randomCoordinates();
- celdas[random[0]][random[1]].setObject(new Portal(this, celdas[random[0]][random[1]]));
- objectArrayList.add(celdas[random[0]][random[1]].getObject());
+ celdas[random[0]][random[1]].setObjectOnBottom(new Portal(this, celdas[random[0]][random[1]]));
+ objectArrayList.add(celdas[random[0]][random[1]].getObjectOnBottom());
// Generate enough keys for the chests that will exist
for (int i = 0; i < CHESTS; i++) {
random = randomCoordinates();
- celdas[random[0]][random[1]].setObject(new Key(this, celdas[random[0]][random[1]]));
- objectArrayList.add(celdas[random[0]][random[1]].getObject());
+ celdas[random[0]][random[1]].setObjectOnBottom(new Key(this, celdas[random[0]][random[1]]));
+ objectArrayList.add(celdas[random[0]][random[1]].getObjectOnBottom());
}
// Chests need to be last to make sure they are openable
@@ -206,14 +206,14 @@ public class Escenario extends JComponent implements Constantes {
int random_y = random(0, VERTICAL_CELLS - 1);
// Don't put a chest if it can't be opened
while (random_y + 1 == VERTICAL_CELLS ||
- celdas[random_x][random_y].getObject() != null ||
- celdas[random_x][random_y + 1].getObject() != null ||
- celdas[random_x][random_y - 1].getObject() != null) {
+ celdas[random_x][random_y].containsObject() ||
+ celdas[random_x][random_y + 1].containsObject() ||
+ celdas[random_x][random_y - 1].containsObject()) {
random_x = random(0, HORIZONTAL_CELLS - 1);
random_y = random(0, VERTICAL_CELLS - 1);
}
- celdas[random_x][random_y].setObject(new Chest(this, celdas[random_x][random_y]));
- objectArrayList.add(celdas[random_x][random_y].getObject());
+ celdas[random_x][random_y].setObjectOnBottom(new Chest(this, celdas[random_x][random_y]));
+ objectArrayList.add(celdas[random_x][random_y].getObjectOnBottom());
}
return objectArrayList;
@@ -228,7 +228,7 @@ public class Escenario extends JComponent implements Constantes {
int[] random = new int[2];
random[0] = random(0, HORIZONTAL_CELLS - 1);
random[1] = random(0, VERTICAL_CELLS - 1);
- while (celdas[random[0]][random[1]].getObject() != null) {
+ while (celdas[random[0]][random[1]].containsObject()) {
random[0] = random(0, HORIZONTAL_CELLS - 1);
random[1] = random(0, VERTICAL_CELLS - 1);
}
@@ -486,16 +486,18 @@ public class Escenario extends JComponent implements Constantes {
*/
public void setDoorClosed(boolean doorClosed) {
if (doorClosed && !isDoorClosed()) {
+ celdas[2][0].setObject(new Obstacle(this, celdas[2][0]));
try {
celdas[2][0].addTexture(textureSheet.getTexture(193), 193);
}
catch (SheetException e) {
- e.printStackTrace();
+ logger.warning(e.getMessage());
}
this.doorClosed = true;
}
else if (!doorClosed && isDoorClosed()) {
- celdas[2][0].removeTopTexture();
+ celdas[2][0].removeTexture(193);
+ celdas[2][0].setObject(null);
this.doorClosed = false;
}
}
diff --git a/src/main/java/cl/cromer/azaraka/Lienzo.java b/src/main/java/cl/cromer/azaraka/Lienzo.java
index 768a284..2d6a7d4 100644
--- a/src/main/java/cl/cromer/azaraka/Lienzo.java
+++ b/src/main/java/cl/cromer/azaraka/Lienzo.java
@@ -139,15 +139,24 @@ public class Lienzo extends Canvas implements Constantes {
Enemy.Direction enemyDirection = Enemy.Direction.DOWN;
+ // Create the gems and later place them in 2 of the chests
+ ArrayList gems = new ArrayList<>();
+ Gem lifeGem = new Gem(escenario, new Celda(0, 0, 0, 0));
+ lifeGem.setType(Gem.Type.LIFE);
+ Gem deathGem = new Gem(escenario, new Celda(0, 0, 0, 0));
+ deathGem.setType(Gem.Type.DEATH);
+ gems.add(lifeGem);
+ gems.add(deathGem);
+
ArrayList