from livewires import games
SCREEN_WIDTH = 640
SCREEN_HEIGHT = 480
Expand|Select|Wrap|Line Numbers
- class Pizza(games.Sprite, games.Mover):
- """ A falling pizza. """
- def __init__(self, screen, x, y, image, dx, dy):
- """ Initialize pizza object. """
- self.init_sprite(screen = screen, x = x, y = y,
- image = image)
- self.init_mover(dx = dx, dy = dy)
- def moved(self):
- """ Reverse a velocity component if edge of screen reached. """
- dx, dy = self.get_velocity()
- if self.get_right() > SCREEN_WIDTH or self.get_left() < 0:
- self.set_velocity(-dx, dy)
- if self.get_bottom() > SCREEN_HEIGHT or self.get_top() < 0:
- self.set_velocity (dx, -dy)
- # main
- my_screen = games.Screen(SCREEN_WIDTH, SCREEN_HEIGHT)
- wall_image = games.load_image("1.jpg", transparent = False)
- my_screen.set_background(wall_image)
- pizza_image = games.load_image ("tt1.gif")
- Pizza(screen = my_screen, x = SCREEN_WIDTH/2, y = SCREEN_HEIGHT/2,
- image = pizza_image, dx = 1, dy =1)
- my_screen.mainloop()
I met some problems. Then I traced down to find out that there are no functions named get_right, get_left, get_top and get_bottom in class Sprite in the file games.py under the directory C:\Python25\Lib\site-packages\livewires.
I do not know whether it is an installation problem or there are no such functions at all. But I really want this script to run smoothly. So I add something in class Sprite:
Expand|Select|Wrap|Line Numbers
- def get_right (self):
- return self._x
- def get_bottom (self):
- return self._y
BTW, the version of my python is 2.5, livewires v2.1, pygame v 1.7, and my os is winxp2002 SP2
Thanks