I am making a side scroller where if the user is hit by a fireball or an enemy the program should -1 from the amounts of lives. This is drawn to the user on the screen like so; 'Lives: 3'.
Although I have succeeded in achieving this, I am instead trying to make it so the number of lives is displayed in the form of hearts. This is so the game will have a more appealing user interface to look forward to. Essentially the idea is When one life is lost then the string drawn will go from this: 'Lives: ❤❤❤' to 'Lives: ❤❤' .
Here is my code that works on doing this:
public class GamePanel extends JPanel
private static final int MAX_HITS = 10;
private int numHits = 0;
public void sequenceEnded(String imageName) {
showExplosion = false;
explosionPlayer.restartAt(0);
if (numHits >= MAX_HITS) {
gameOver = true;
score = (int) ((System.nanoTime() - gameStartTime)/1000000000L);
}
private void reportStats(Graphics g) {
if (!gameOver)
timeSpentInGame = (int) ((System.nanoTime() -gameStartTime)/1000000000L);
g.setColor(Color.red);
g.setFont(msgsFont);
int lives = MAX_HITS - numHits;
g.drawString("Lives: " + lives + " ❤", 15, 25);
}
Anyone have any ideas as to how I can go from this: 'Lives = 10 ❤' to
'Lives = ❤❤❤❤❤❤❤❤❤❤' with a working array which will reduce the number of hearts from the string?