MONT 105S, Spring 2009
Home | | Course Schedule | | Assignments | | Lecture NotesLaboratory 11
The World's Easiest Video Game
In this lab, you will create a game window with a graphic background. Several sprites
(Goombas) will
move in a square pattern on the background. You will control another sprite (Mario) with
the mouse. When Mario encounters a Goomba, the Goomba will disappear.
Before you begin, download the following images into the same folder that will have your
python program in it. (You can download an image by right-clicking and choosing
"Save image" from the menu).
Step 1: Start with the program from lab 10
Test your program. If correct, the Mario sprite should move in a square on the
screen background.
Step 2: Creating four Goombas
In this game, we will have Goombas moving in the square pattern, so your first task
is to change the Mario class into a Goomba class and add four Goombas to your
scene. You can accomplish this by making the
following changes:
Test your program. You should see four Goombas moving in a square pattern.
Step 3: Adding a mouse-controlled Mario
Test your program. You should see your four moving Goombas and there should be a Mario that
will move with the cursor (For this lab we will leave the cursor visible).
Step 4: Detect Collisions
Test your program. Now, when Mario touches a Goomba, the Goomba should disappear. You should
be able to make all four Goombas disappear.
What To Turn In. Reminder. Be sure to save a copy of
each program on your
Due at the end of today's class
Start with the program from lab 10. You may copy and paste the following code into
your python file.
from livewires import games
class Mario(games.Sprite):
"""A bouncing Mario"""
def update(self):
if self.dx == 1 and self.left >= 500:
self.dx = 0
self.dy = -1
elif self.dy == -1 and self.top <= 120:
self.dx = -1
self.dy = 0
elif self.dx == -1 and self.right <= 300:
self.dx = 0
self.dy = 1
elif self.dy == 1 and self.top >= 320:
self.dx = 1
self.dy = 0
games.init(screen_width = 800, screen_height = 438, fps = 50)
wall_image = games.load_image("super_mario_scene.jpg", transparent = False)
games.screen.background = wall_image
mario_image = games.load_image("mario.gif")
the_mario = Mario(image = mario_image, x = games.screen.width/2,
y = games.screen.height/2,
dx = 1, dy = 0)
games.screen.add(the_mario)
games.screen.mainloop( )
Create a mouse-controlled Mario as follows:
Add code to detect collisions of Mario and a Goomba. When a collision occurs, the Goomba should
disappear. Add the following code: