MONT 105S, Spring 2009
Home | | Course Schedule | | Assignments | | Lecture NotesImages and Code for Lectures 22 and 23
Pizza pan game--1st demo
from livewires import games import random class Pizza(games.Sprite): """A bouncing pizza""" def update(self): if self.right > games.screen.width or self.left < 0: self.dx = -self.dx if self.bottom > games.screen.height or self.top < 0: self.dy = -self.dy class Pan(games.Sprite): """A mouse controlled pan""" def update( self ): self.x = games.mouse.x self.y = games.mouse.y games.init(screen_width = 640, screen_height = 480, fps = 50) wall_image = games.load_image("wall.jpg", transparent = False) games.screen.background = wall_image pizza_image = games.load_image("pizza.bmp") the_pizza = Pizza(image = pizza_image, x = 320, y = 240, dx = 1, dy = 1) games.screen.add(the_pizza) pan_image = games.load_image("pan.bmp") the_pan = Pan(image = pan_image, x = games.mouse.x, y = games.mouse.y) games.screen.add(the_pan) #games.mouse.is_visible = False #games.screen.event_grab = True games.screen.mainloop( ) games.mouse.is_visible = True
Pizza Pan demo 2
from livewires import games import random class Pizza(games.Sprite): """A bouncing pizza""" def update(self): if self.right > games.screen.width or self.left < 0: self.dx = -self.dx if self.bottom > games.screen.height or self.top < 0: self.dy = -self.dy def handle_collide(self): self.x = random.randrange(games.screen.width) self.y = random.randrange(games.screen.height) class Pan(games.Sprite): """A mouse controlled pan""" def update( self ): self.x = games.mouse.x self.y = games.mouse.y self.check_collide( ) def check_collide(self): for the_pizza in self.overlapping_sprites: the_pizza.handle_collide( ) games.init(screen_width = 640, screen_height = 480, fps = 50) wall_image = games.load_image("wall.jpg", transparent = False) games.screen.background = wall_image pizza_image = games.load_image("pizza.bmp") the_pizza = Pizza(image = pizza_image, x = 320, y = 240, dx = 1, dy = 1) games.screen.add(the_pizza) pan_image = games.load_image("pan.bmp") the_pan = Pan(image = pan_image, x = games.mouse.x, y = games.mouse.y) games.screen.add(the_pan) games.mouse.is_visible = False games.screen.event_grab = True games.screen.mainloop( ) games.mouse.is_visible = True
Constance Royden--croyden@mathcs.holycross.edu
MONT 105S--Computer Science of Graphics and Games
Date Created: September 1, 2002
Last Modified: January 12, 2009
Page Expires: January 12, 2010