Learning a thing is much more efficient when you are interested in said thing. Just saying.
There are numerous methods to display a player's progress in a game, the numerical scoreboard being a common way to do so. Giving players respectable goals and endings to work towards is a sure way to retain their interests in your game. It is up to you to interpret what counts as a respectable goal in your game of varied length.
The tutorial provides two simple goals for our game: shoot bullets at enemies to earn points and deplete their health bar to kill them.
Pygame contains many fonts to style your UIs with, not limited to Arial, Comic Sans, and Times New Roman. If none of these are to your liking, you can import TrueType (.ttf) files that contain the mathematical outline of each character in a font.
Whereas the tutorial wrote the score system into the runtime loop, you can make it a class variable for a more malleable development experience in the future, whether for multiclass competitive scoring and such.
Like any object class in Pygame, make sure to type it into the redrawGameWindow() function so that your running window will visualize it.
Just add a simple addition line for the layer score in the enemy hitbox function afterwards, and your rudimentary scoring system is fully set up.
What do you feel when seeing the scoreboard's value add up?
Besides specific exceptions (e.g., horror sequence), an invincible enemy is boring to deal with. Especially one that gets in your way. It might also discourage them from progressing any further. While our case is not that complex, making the enemy defeatable is a step towards building a complete game.
The logic of "getting hit loses you health" is a necessity in the oldest combat games, along with the bonus feature of "running out of health makes you dead." For some smaller games, invisible corpses are also an enhancing staple.
The enemy sprite disappears when its health reaches 0, which is performed by simply adding an if gate above the move() function fetcher.
With our health and damage logics complete, what comes next is the health bar system. While games such as Monster Hunter hide their monsters' health, as well as some arcade games from the 20th century, we are learning older ways to tell players their progress with game obstacles.
The script below constantly draws two rectangles – a red one first, then green one overlapping. The draw.rect() function takes in the parameters surface, color, rectangle size (x, y, width, height), and border width (fills by default). Referencing the new fractional variable healthWidth, the green rectangle's width shrinks as its owner's health drops.
You might want to consider your health bar's characteristics when making them for different genres of video games.