Game Design: Levels
Game Design: Levels
Earlier we added a "game over" page when a GameOver variable was set to True. We then reset the game. In this chapter we will clean up that code and add in multiple levels.
Duplicate your BB8 Explosion Game and call it BB8 Levels Game. We will be updating that code as you go through this chapter.
In the constant section we are going to remove the trooper_count constant. We are going to have three different levels to our game and we are going to increase the trooper_count for each one, so we will create that variable later.
#22-23: We enter how many levels we will have and we also make a trooper_count list that holds how many troopers to spawn at each level. For testing purposes I just spawned 1 trooper at each level.
#96-#98: Set the initial current_level = 0 which is the INSTRUCTIONS page. Set self.Gameover to True and set self.score = 0
#115-116: Determine if self.current_level is 1-3. If it is create a self.background variable and load the correct texture. (sky1.png, sky2.png or sky3.png) We named the background images according to the levels we wanted to use them on.
#122-133: Indent all of this code to be in the if statement.
#129: Create the troopers from the trooper_count list for the current_level.
Below is the new on_draw() code. It makes the Instructions page, the levels pages or the Gameover page.
Below is the new on_update() code.
#159-162 Check to see if self.current_level is in the range of 1-3 otherwise set self.Gameover = True
#164 Check to see if self.Gameover is NOT True. Indent all the remaining code to be in this IF statement.
#174-175 If all troopers shot, level up and call self.reset()
#182 & #198 Change self.current_level to levels + 1 which will be the Gameover level
Below is the new on_key_press() code.
#229-234 Add in key.P and key.I
Finally, change the game title to "BB8 Levels"
Feel free to implement any new knowledge into your game project.