diff --git a/.idea/misc.xml b/.idea/misc.xml
index d6be02d..ac13b03 100644
--- a/.idea/misc.xml
+++ b/.idea/misc.xml
@@ -5,7 +5,7 @@
-
+
\ No newline at end of file
diff --git a/res/snd/Success.wav b/res/snd/Success.wav
new file mode 100644
index 0000000..b1b670b
Binary files /dev/null and b/res/snd/Success.wav differ
diff --git a/src/cl/cromer/azaraka/Celda.java b/src/cl/cromer/azaraka/Celda.java
index 6d45797..d05e85c 100644
--- a/src/cl/cromer/azaraka/Celda.java
+++ b/src/cl/cromer/azaraka/Celda.java
@@ -168,12 +168,12 @@ public class Celda extends JComponent implements Constantes {
*/
@Override
public void update(Graphics g) {
- // Set the text font
- //g.setFont(new Font("monospaced", Font.BOLD, 10));
-
- for (BufferedImage tile : textures) {
- if (tile != null) {
- g.drawImage(tile, xPixels, yPixels, null);
+ // 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);
+ if (texture != null) {
+ g.drawImage(texture, xPixels, yPixels, null);
}
}
diff --git a/src/cl/cromer/azaraka/Escenario.java b/src/cl/cromer/azaraka/Escenario.java
index 900c88e..6955017 100644
--- a/src/cl/cromer/azaraka/Escenario.java
+++ b/src/cl/cromer/azaraka/Escenario.java
@@ -585,6 +585,9 @@ public class Escenario extends JComponent implements Constantes {
sound = new Sound("/snd/GetKey.wav");
sounds.put(Sound.SoundType.GET_KEY, sound);
+
+ sound = new Sound("/snd/Success.wav");
+ sounds.put(Sound.SoundType.SUCCESS, sound);
}
catch (SoundException e) {
logger.warning(e.getMessage());
diff --git a/src/cl/cromer/azaraka/Lienzo.java b/src/cl/cromer/azaraka/Lienzo.java
index e6e57f0..56ff57a 100644
--- a/src/cl/cromer/azaraka/Lienzo.java
+++ b/src/cl/cromer/azaraka/Lienzo.java
@@ -23,6 +23,7 @@ import cl.cromer.azaraka.sprite.Animation;
import cl.cromer.azaraka.sprite.AnimationException;
import javax.sound.sampled.Clip;
+import javax.swing.*;
import java.awt.*;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
@@ -201,7 +202,7 @@ public class Lienzo extends Canvas implements Constantes {
case 2:
try {
keyAnimation = escenario.getSprites().get(Animation.SpriteType.KEY);
- keyAnimation.setFrame(4);
+ keyAnimation.setCurrentFrame(4);
graphicBuffer.drawImage(keyAnimation.getFrame(), 69, 8, null);
}
catch (AnimationException e) {
@@ -211,7 +212,7 @@ public class Lienzo extends Canvas implements Constantes {
try {
if (keyAnimation == null) {
keyAnimation = escenario.getSprites().get(Animation.SpriteType.KEY);
- keyAnimation.setFrame(4);
+ keyAnimation.setCurrentFrame(4);
}
graphicBuffer.drawImage(keyAnimation.getFrame(), 40, 8, null);
}
@@ -230,7 +231,7 @@ public class Lienzo extends Canvas implements Constantes {
Animation heartAnimation = escenario.getSprites().get(Animation.SpriteType.HEART);
if (health >= 4) {
try {
- heartAnimation.setFrame(4);
+ heartAnimation.setCurrentFrame(4);
}
catch (AnimationException e) {
logger.warning(e.getMessage());
@@ -238,7 +239,7 @@ public class Lienzo extends Canvas implements Constantes {
}
else {
try {
- heartAnimation.setFrame(health);
+ heartAnimation.setCurrentFrame(health);
}
catch (AnimationException e) {
logger.warning(e.getMessage());
@@ -261,33 +262,11 @@ public class Lienzo extends Canvas implements Constantes {
if (gameOver) {
if (!gameOverRan) {
- try {
- if (backgroundMusic.isPlaying()) {
- backgroundMusic.stop();
- backgroundMusicThread.interrupt();
- }
- }
- catch (SoundException e) {
- logger.warning(e.getMessage());
- }
+ stopBackgroundMusic();
new Thread(escenario.getSounds().get(Sound.SoundType.GAME_OVER)).start();
- // Stop all the active threads
- for (Map.Entry