diff --git a/.idea/misc.xml b/.idea/misc.xml
index ac13b03..d6be02d 100644
--- a/.idea/misc.xml
+++ b/.idea/misc.xml
@@ -5,7 +5,7 @@
-
+
\ No newline at end of file
diff --git a/Game.iml b/Game.iml
index 1d6ac6a..769a53e 100644
--- a/Game.iml
+++ b/Game.iml
@@ -8,6 +8,7 @@
+
@@ -15,5 +16,21 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/cl/cromer/game/Celda.java b/src/cl/cromer/game/Celda.java
index 43eafc3..21e09ce 100644
--- a/src/cl/cromer/game/Celda.java
+++ b/src/cl/cromer/game/Celda.java
@@ -48,10 +48,6 @@ public class Celda extends JComponent implements Constantes {
* The type of cell
*/
private Type type = Type.SPACE;
- /**
- * If the cell is selected
- */
- private boolean selected = false;
/**
* The sprites that can be used in the cell
*/
@@ -224,46 +220,6 @@ public class Celda extends JComponent implements Constantes {
}
break;
}
-
- // The cell is selected
- if (isSelected()) {
- g.setColor(Color.black);
- g.drawRect(xPixels, yPixels, CELL_PIXELS - 1, CELL_PIXELS - 1);
- }
- }
-
- /**
- * Check if the cell is selected
- *
- * @return Returns true if the cell is selected
- */
- public boolean isSelected() {
- return selected;
- }
-
- /**
- * Set the call as selected or unselected
- *
- * @param selected True if the cell is selected
- */
- public void setSelected(boolean selected) {
- this.selected = selected;
- }
-
- /**
- * Called when the player uses mouse to select cell
- *
- * @param clickX The x coordinate
- * @param clickY They y coordinate
- * @return Returns true if the cell is selected
- */
- public boolean selected(int clickX, int clickY) {
- Rectangle rectangle = new Rectangle(xPixels, yPixels, CELL_PIXELS, CELL_PIXELS);
- if (rectangle.contains(new Point(clickX, clickY))) {
- selected = !selected;
- return true;
- }
- return false;
}
/**
diff --git a/src/cl/cromer/game/Constantes.java b/src/cl/cromer/game/Constantes.java
index b387cc4..78a326d 100644
--- a/src/cl/cromer/game/Constantes.java
+++ b/src/cl/cromer/game/Constantes.java
@@ -84,11 +84,11 @@ public interface Constantes {
/**
* The amount of chests to draw
*/
- int CHESTS = 4;
+ int CHESTS = 2;
/**
* The amount of enemies to draw
*/
- int ENEMIES = 4;
+ int ENEMIES = 2;
/**
* The player's start x position
*/
diff --git a/src/cl/cromer/game/Escenario.java b/src/cl/cromer/game/Escenario.java
index 1e1be2f..4f61b1b 100644
--- a/src/cl/cromer/game/Escenario.java
+++ b/src/cl/cromer/game/Escenario.java
@@ -82,6 +82,10 @@ public class Escenario extends JComponent implements Constantes {
* The enemies
*/
private ArrayList enemies = new ArrayList<>();
+ /**
+ * The chests
+ */
+ private ArrayList chests = new ArrayList<>();
/**
* Initialize the scene
@@ -225,6 +229,8 @@ public class Escenario extends JComponent implements Constantes {
break;
case CHEST:
celdas[x][y].setAnimation(sprites.get(Animation.SpriteType.CHEST));
+ celdas[x][y].setCoords(x, y);
+ chests.add(celdas[x][y]);
break;
case PORTAL:
celdas[x][y].setAnimation(sprites.get(Animation.SpriteType.PORTAL));
@@ -514,7 +520,7 @@ public class Escenario extends JComponent implements Constantes {
stringBuilder.insert(0, 0);
}
stringBuilder.append(".png");
- animation.addImage(Animation.Direction.NONE, "/img/portal/gray/" + stringBuilder.toString());
+ animation.addImage(Animation.Direction.NONE, "/img/portal/green/" + stringBuilder.toString());
}
sprites.put(Animation.SpriteType.PORTAL, animation);
@@ -546,19 +552,6 @@ public class Escenario extends JComponent implements Constantes {
animation.setYOffset(0);
}
- /**
- * This method will remove the selected attribute from all cells
- */
- public void emptyEscenario() {
- for (int i = 0; i < HORIZONTAL_CELLS; i++) {
- for (int j = 0; j < VERTICAL_CELLS; j++) {
- if (celdas[i][j].isSelected()) {
- celdas[i][j].setSelected(false);
- }
- }
- }
- }
-
/**
* Get the cells of the game
*
@@ -783,6 +776,15 @@ public class Escenario extends JComponent implements Constantes {
return enemies;
}
+ /**
+ * Get the chests
+ *
+ * @return Returns an array list containing the chests
+ */
+ public ArrayList getChests() {
+ return chests;
+ }
+
/**
* Get the parent canvas of this scene
* @return Returns the parent canvas
diff --git a/src/cl/cromer/game/Lienzo.java b/src/cl/cromer/game/Lienzo.java
index 5cd134c..62d7df0 100644
--- a/src/cl/cromer/game/Lienzo.java
+++ b/src/cl/cromer/game/Lienzo.java
@@ -15,15 +15,16 @@
package cl.cromer.game;
+import cl.cromer.game.object.Chest;
import cl.cromer.game.object.Enemy;
import cl.cromer.game.object.Portal;
import cl.cromer.game.sound.Sound;
import cl.cromer.game.sound.SoundException;
-import cl.cromer.game.sprite.AnimationException;
import javax.sound.sampled.Clip;
import java.awt.*;
-import java.awt.event.*;
+import java.awt.event.KeyAdapter;
+import java.awt.event.KeyEvent;
import java.util.ArrayList;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
@@ -37,22 +38,6 @@ public class Lienzo extends Canvas implements Constantes {
* The game scene
*/
private Escenario escenario;
- /**
- * Check if the mouse button is being held down or not
- */
- private boolean holdMouseButton = false;
- /**
- * Check if the selected cell is the player or not
- */
- private boolean playerSelected = false;
- /**
- * The current mouse x position
- */
- private int mouseX;
- /**
- * The current mouse y position
- */
- private int mouseY;
/**
* The graphics buffer
*/
@@ -95,47 +80,10 @@ public class Lienzo extends Canvas implements Constantes {
setBackground(Color.black);
setSize(escenario.width, escenario.height);
- addMouseListener(new MouseAdapter() {
- @Override
- public void mousePressed(MouseEvent event) {
- super.mouseClicked(event);
- if (event.getButton() == MouseEvent.BUTTON1) {
- escenario.emptyEscenario();
- setMousePosition(event);
- holdMouseButton = true;
- repaint();
- }
- }
-
- @Override
- public void mouseReleased(MouseEvent event) {
- super.mouseClicked(event);
- if (event.getButton() == MouseEvent.BUTTON1) {
- escenario.emptyEscenario();
- setMousePosition(event);
- holdMouseButton = false;
- activateCell(event);
- repaint();
- }
- }
- });
-
- addMouseMotionListener(new MouseMotionAdapter() {
- @Override
- public void mouseDragged(MouseEvent event) {
- super.mouseDragged(event);
- escenario.emptyEscenario();
- setMousePosition(event);
- repaint();
- }
- });
-
addKeyListener(new KeyAdapter() {
@Override
public void keyPressed(KeyEvent event) {
super.keyPressed(event);
- escenario.emptyEscenario();
- playerSelected = false;
escenario.keyPressed(event);
repaint();
}
@@ -162,6 +110,11 @@ public class Lienzo extends Canvas implements Constantes {
threads.add(new Thread(enemy));
}
+ for (Celda celda : escenario.getChests()) {
+ Chest chest = new Chest(escenario, celda);
+ threads.add(new Thread(chest));
+ }
+
portal = new Portal(escenario);
threads.add(new Thread(portal));
@@ -179,48 +132,6 @@ public class Lienzo extends Canvas implements Constantes {
}
}
- /**
- * Activate the cell that was clicked
- *
- * @param event The mouse click event
- */
- private void activateCell(MouseEvent event) {
- for (int i = 0; i < HORIZONTAL_CELLS; i++) {
- for (int j = 0; j < VERTICAL_CELLS; j++) {
- if (escenario.getCeldas()[i][j].selected(event.getX(), event.getY())) {
- logger.info("Cell x: " + i + " y: " + j + " selected");
- escenario.getCeldas()[i][j].setSelected(true);
-
- if (playerSelected) {
- if (escenario.getCeldas()[i][j].getType() == Celda.Type.SPACE) {
- int x = escenario.getPlayer().getX();
- int y = escenario.getPlayer().getY();
-
- // Put the player in the new place
- escenario.getCeldas()[i][j].setType(Celda.Type.PLAYER);
- escenario.getCeldas()[i][j].setAnimation(escenario.getCeldas()[x][y].getAnimation());
- escenario.getPlayer().setCoords(i, j);
- playerSelected = false;
-
- // Remove the player from previous place
- escenario.getCeldas()[x][y].setType(Celda.Type.SPACE);
- escenario.getCeldas()[x][y].setAnimation(null);
-
- escenario.emptyEscenario();
- break;
- }
- }
-
- if (escenario.getCeldas()[i][j].getType() == Celda.Type.PLAYER) {
- playerSelected = true;
- }
-
- break;
- }
- }
- }
- }
-
/**
* Override the paint method of Canvas to paint all the scene components
* @param g The graphics object to paint
@@ -244,34 +155,12 @@ public class Lienzo extends Canvas implements Constantes {
graphicBuffer.setColor(getBackground());
graphicBuffer.fillRect(0, 0, this.getWidth(), this.getHeight());
- //graphicBuffer.drawImage()
+ // This is needed if there is a background image
+ //graphicBuffer.drawImage();
escenario.paintComponent(graphicBuffer);
g.drawImage(imageBuffer, 0, 0, null);
- if (holdMouseButton && playerSelected) {
- try {
- int x = escenario.getPlayer().getX();
- int y = escenario.getPlayer().getY();
- Celda celda = escenario.getCeldas()[x][y];
- if (celda.getAnimation() != null) {
- g.drawImage(celda.getAnimation().getNextFrame(), mouseX, mouseY, null);
- }
- }
- catch (AnimationException e) {
- logger.warning(e.getMessage());
- }
- }
- }
-
- /**
- * Set the position of the mouse while it is being dragged
- *
- * @param event The event
- */
- private void setMousePosition(MouseEvent event) {
- mouseX = event.getX();
- mouseY = event.getY();
}
/**
diff --git a/src/cl/cromer/game/object/Chest.java b/src/cl/cromer/game/object/Chest.java
index a2d2fa0..6bf60e4 100644
--- a/src/cl/cromer/game/object/Chest.java
+++ b/src/cl/cromer/game/object/Chest.java
@@ -15,14 +15,44 @@
package cl.cromer.game.object;
+import cl.cromer.game.Celda;
+import cl.cromer.game.Escenario;
+
/**
* This class handles the chests
*/
-public class Chest {
+public class Chest implements Runnable {
/**
* The current state of the chest
*/
private State state = State.CLOSED;
+ /**
+ * The scene the chest is in
+ */
+ private Escenario escenario;
+ /**
+ * The cell the chest is in
+ */
+ private Celda celda;
+
+ /**
+ * Initialize the chest
+ *
+ * @param escenario The scene the chest is in
+ * @param celda The cell that contains the chest
+ */
+ public Chest(Escenario escenario, Celda celda) {
+ this.escenario = escenario;
+ this.celda = celda;
+ }
+
+ /**
+ * This method is run when the thread starts
+ */
+ @Override
+ public void run() {
+
+ }
/**
* The possible states of the chest
@@ -32,6 +62,10 @@ public class Chest {
* The chest is closed
*/
CLOSED,
+ /**
+ * The chest is opening
+ */
+ OPENING,
/**
* The chest is opened
*/
diff --git a/src/cl/cromer/game/panel/Menu.java b/src/cl/cromer/game/panel/Menu.java
deleted file mode 100644
index d242b5e..0000000
--- a/src/cl/cromer/game/panel/Menu.java
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- * Copyright 2019 Chris Cromer
- *
- * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
- *
- * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
- *
- * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
- *
- * 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- */
-
-package cl.cromer.game.panel;
-
-import cl.cromer.game.Constantes;
-
-import javax.swing.*;
-import java.awt.*;
-
-/**
- * The menu panel
- */
-public class Menu extends JPanel implements Constantes {
-
- /**
- * Initialize the menu panel
- *
- * @param ventanaPrincipal The main window
- */
- public Menu(JFrame ventanaPrincipal) {
- this.setName("La Aventura de Azaraka");
- this.setLayout(null);
- this.setSize(SCREEN_SIZE.width, SCREEN_SIZE.height);
-
- JLabel name = new JLabel("NAME: ");
- name.setFont(new Font("monospaced", Font.BOLD, 40));
- name.setForeground(Color.orange);
- name.setBounds(20, 20, 400, 200);
-
- add(name);
- }
-}