Fix drawing issue

Signed-off-by: Chris Cromer <chris@cromer.cl>
This commit is contained in:
Chris Cromer 2019-09-30 23:43:24 -03:00
parent 6953d00782
commit 3662e40d74
3 changed files with 13 additions and 26 deletions

View File

@ -90,7 +90,7 @@ public interface Constantes {
/** /**
* The amount of margin to the left and right of cells * The amount of margin to the left and right of cells
*/ */
int LEFT_MARGIN = 50; int LEFT_MARGIN = 40;
/** /**
* The amount of chests to draw * The amount of chests to draw
*/ */
@ -126,7 +126,7 @@ public interface Constantes {
/** /**
* The default volume * The default volume
*/ */
int DEFAULT_VOLUME = 100; int DEFAULT_VOLUME = 0;
/** /**
* Generates the scene manually instead of from the JSON file if true * Generates the scene manually instead of from the JSON file if true
*/ */

View File

@ -131,12 +131,6 @@ public class Lienzo extends Canvas implements Constantes {
logger.warning(e.getMessage()); logger.warning(e.getMessage());
} }
// Load the hearts
heartAnimation = new Animation();
for (int i = 0; i < 5; i++) {
heartAnimation.addImage(Animation.Direction.NONE, "/img/heart/heart" + i + ".png");
}
// Load the game over // Load the game over
gameOverAnimation = new Animation(); gameOverAnimation = new Animation();
gameOverAnimation.addImage(Animation.Direction.NONE, "/img/gameover/gameover.png"); gameOverAnimation.addImage(Animation.Direction.NONE, "/img/gameover/gameover.png");
@ -247,25 +241,16 @@ public class Lienzo extends Canvas implements Constantes {
gameOver = true; gameOver = true;
} }
int hearts = Player.MAX_HEALTH / 4; int hearts = Player.MAX_HEALTH / 4;
if (heartAnimation == null) {
heartAnimation = new Animation();
for (int i = 0; i < 5; i++) {
heartAnimation.addImage(Animation.Direction.NONE, "/img/heart/heart" + i + ".png");
}
}
for (int i = 0; i < hearts; i++) { for (int i = 0; i < hearts; i++) {
if (health >= 4) {
try {
heartAnimation.setCurrentFrame(4);
}
catch (AnimationException e) {
logger.warning(e.getMessage());
}
}
else {
try {
heartAnimation.setCurrentFrame(health);
}
catch (AnimationException e) {
logger.warning(e.getMessage());
}
}
try { try {
int x = ((HORIZONTAL_CELLS) * CELL_PIXELS) + LEFT_MARGIN - (heartAnimation.getFrame().getWidth() * hearts) + (heartAnimation.getFrame().getWidth() * i); heartAnimation.setCurrentFrame(Math.min(health, 4));
int x = (HORIZONTAL_CELLS * CELL_PIXELS) + LEFT_MARGIN - (heartAnimation.getFrame().getWidth() * hearts) + (heartAnimation.getFrame().getWidth() * i);
graphicBuffer.drawImage(heartAnimation.getFrame(), x, 8, null); graphicBuffer.drawImage(heartAnimation.getFrame(), x, 8, null);
} }
catch (AnimationException e) { catch (AnimationException e) {
@ -312,7 +297,6 @@ public class Lienzo extends Canvas implements Constantes {
escenario.paintComponent(graphicBuffer); escenario.paintComponent(graphicBuffer);
} }
g.drawImage(imageBuffer, 0, 0, null);
if (!gameStarted) { if (!gameStarted) {
gameStarted = true; gameStarted = true;
try { try {
@ -326,6 +310,8 @@ public class Lienzo extends Canvas implements Constantes {
logger.warning(e.getMessage()); logger.warning(e.getMessage());
} }
} }
g.drawImage(imageBuffer, 0, 0, null);
} }
/** /**

View File

@ -39,6 +39,7 @@ public class VentanaPrincipal extends JFrame implements Constantes {
logger.info("Create panels"); logger.info("Create panels");
setExtendedState(this.getExtendedState() | JFrame.MAXIMIZED_BOTH); setExtendedState(this.getExtendedState() | JFrame.MAXIMIZED_BOTH);
setSize(Toolkit.getDefaultToolkit().getScreenSize());
setTitle(TITLE); setTitle(TITLE);
String icon = "/img/icon.png"; String icon = "/img/icon.png";