| CompSci 190 Fall 2022 |
Programming Games FOCUS Section |
It takes hard work and determination to win a typical race but, in this game, it will take luck and the right sequence of random values. Much like the standard carnival race game where you use a water pistol to squirt a target that makes a character move along the track — even if you shoot as hard and steadily as possible, it does not seem to guarantee a win.
Try writing this game from scratch by creating a New PyCharm project and replace the default code given in the Python file with the basic code below to get started:
""" Created on Sep 22, 2022 @author: YOUR NAME HERE!! This module represents a carnival Racer game, in which a number of turtles randomly race across the screen. """ import random import turtle # Set up the game scene theScreen = turtle.Screen() theScreen.tracer(False) # Play the game forever theScreen.mainloop()
Here is a video discussing getting started on the project
Where will you start when you are completely in control?
Do you want to start by creating a single racer that moves across the screen?
game_step() function to animate the game that calls the function above and ends with these two lines of code:theScreen.update()
theScreen.ontimer(game_step, 10)
game_step() function to stop the turtle after it reaches the other side of the screen (hint: look at the Aim It Game code for ideas about how to do this)By creating all the racers lined up on left side of the screen?
range() of the number of turtles you want to create to:
theScreen.update()
Or setting the look or theme for your game?
theScreen.addshape('IMAGE_NAME.gif')
Whichever order you decide on, make sure to work in small iterative steps so you can quickly see the results to know you are on the right track.
Finally, to actually see a racing games like at the local carnival, you will need to update the game_step() function to:
TrueWhen done, it should appear like the turtles are racing to the right side of the window (but we know they are just moving randomly :)
As of now, it is not much of a game since the player can only watch the action.
Add the ability for the player to impact the game by speeding up a racer by giving it an extra call to your random move function:
def handleMouse (x, y):
# loop over turtles to check which one is closest to x and y
# call YOUR_RANDOM_MOVE_FUNCTION with the found turtle
yurtle.onclick(handleMouse)
'Right' or '.' or '='):def handleKey ():
# call YOUR_RANDOM_MOVE_FUNCTION with the player's turtle
theScreen.onkeypress(handleKey, 'Right')
Or come up with another way to play — it's your game!
Once you have the basic game features working, add more features to experiment and turn your game into one where a player dodges (or catches) obstacles.
Feel free to be creative, but remember to keep your ideas at your skill level since there are still many things we have yet to learn, but here are some ideas to get you started:
Some ideas include Parachute, Night Driver, Frogger, Fruit Ninja, or your experience with other dodging style games.
In the comment at the top of the Python file add: