You probably recognize that displaying a score requires some text, which you want Pygame to draw on the screen. You can think of this in terms of variables and functions or, if that doesn't come naturally to you yet, you can think generically. Once you've determined your desired outcome, think about what components are required for it. In this case, you want to display the player's score and health on the screen. The first thing to do, before bothering with a library's documentation, is to think about what you are trying to achieve. If you're not comfortable referring to descriptions of code components, this can be overwhelming. They're technical documents, and they list each class and function available in the module, what kind of inputs each expects, and so on. However, Pygame is a big module with a lot of documentation, and its docs aren't exactly written in the same approachable (and friendly and elucidating and helpful) narrative style as articles on. Pygame's main page links to its documentation. Most Python modules have documentation, and even those that do not can be minimally documented by Python's Help function. This article teaches you to display these statistics in a font of your choice on the game screen during gameplay. You already have variables that track score and health, but it all happens in the background. You can also track the player's health so that when they hit one of the enemies, it has a consequence. Now that you have loot that your player can collect, there's every reason to keep score so that your player sees just how much loot they've collected. But the not-so-secret agenda of this lesson is to teach you how to find out what a library offers and how you can use new features. For the practical purpose of making your platform game more polished, in this article, you will add a score and health display to your game screen. Luckily, the fact that you're reading this article is a sign that you're comfortable with documentation. This component isn't important just for programming games in Python it's something you must master no matter what branch of computing you explore: Learning new tricks as a programmer by reading a language's or library's documentation. However, it still lacks one vital component. If you've followed along with this series, you've learned all the essential syntax and patterns you need to create a video game with Python. Enable your Python game player to run forward and backward.Add jumping to your Python platformer game.What's a hero without a villain? How to add one to your Python game. ![]() ![]() Using Pygame to move your game character around.How to add a player to your Python game.Build a game framework with Python using the Pygame module.Learn how to program in Python by building a simple dice game.This is part 11 in an ongoing series about creating video games in Python 3 using the Pygame module.
0 Comments
Leave a Reply. |