Light Bike
It's time to build a tron-esque light bike game. If you don't know what it is, click the above link and play a few rounds.
The basic idea is that your motorcycle has a trail which never goes away... unless you crash. You can crash by either hitting the walls or any of the light trails--including your own.
|
Directions:
- You need to create this program using classes. You may NOT use sgfx... at all. By using classes, I mean you should not have a massively complex process of if-then statements. Those webs of logic you are used to creating should be broken up into smaller digestible pieces we will use as methods in the larger class.
- Your animation loop CANNOT be a naked while loop like you used in the paddle ball program "Bounce". You need to define a mainloop function and embed the while loop in this function. The game will start when you call mainloop() at the end of the program.
- Your code must be commented for full credit!
- Your game must be two-player.
- You must have text on the screen indicating which player is which based on color.
- You must have a counter on the screen which either displays the score of multiple matches or the elapsed time of a single match.
- Give the user an option to play again or quit
- Give the user an option to play again or quit on the window/canvas so they don't have to go back to the interpreter.
Requirements
Think through the process with me for a moment.
Step 1: We need to leave a trail behind our bike. I can think of two options to do this.
Step 1: We need to leave a trail behind our bike. I can think of two options to do this.
Option 1: Move a bike around a screen and place a trail behind the bike.
Option 2: Place new bikes on the screen in the direction we want to go. I suggest going this route.
Option 2: Place new bikes on the screen in the direction we want to go. I suggest going this route.
Step 2: Create a bike that leaves a trail and responds to keyboard controls for direction.
Step 3: Your bike needs to crash when it runs into walls
Step 4: Your bike needs to crash when it runs into its own trail.
Step 5: You need an opponent to play against.
Step 6: Display text on the screen showing the winner and the amount of time the game lasted and/or the score.
Extension!!
Step 7: Give the user an option to play again or quit.
Step 8: Give the player an option to play again by using your window/canvas rather than having to back to the shell.
Step 8: Give the player an option to play again by using your window/canvas rather than having to back to the shell.
Hint:
Here's the classes and methods I used for the program up to step 6. Once I started step 7 I created a 'game' class which allowed the program to run multiple times.
class Bike (object): def __init__(self,color): def turn_left(self, evt): #changes the self.x, self.y based on keyboard event. def turn_right(self, evt): #changes the self.x, self.y based on keyboard event. def turn_up(self, evt): #changes the self.x, self.y based on keyboard event. def turn_down(self, evt): #changes the self.x, self.y based on keyboard event. def MoveBike(self): #Places the position of the self.id rectangle into the both_trails array. #Creates new rectangles on the screen based on the self.x and self.y given by the turn_left, turn_right, turn_up, turn_down methods above. def checkhit(self): #check to see if your position is in the both_trails array. def new_game(self, game): #you only need this for the extension. --- class Bike2(Bike): #this inherits everything from the Bike1 class, unless you decide to change it. #because you need a second bike with different key bindings. def __init__(self, color): def new_game(self, game): #you only need this for the extensions. --- def mainloop(): #this should contain the while loop used to animate the paddle ball game. both_trails = [] #declare the Bike objects Bike1 = Bike(game, 'Red') Bike2 = Bike2(game, 'Blue') #run the game mainloop() |