Занимаюсь по Доусону. В 11 главе он разработал программу "Ускользающая пицца". Я переписал код, но на моменте столкновения двух спрайтов программа закрывается.
from livewires import games
import random
games.init(screen_width = 640, screen_height = 480, fps = 50)
class Pan(games.Sprite):
def update(self):
self.x = games.mouse.x
self.y = games.mouse.y
self.check_collide()
def check_collide(self):
for pizza in self.overlapping_sprites:
pizza.handle_collide()
class Pizza(games.Sprite):
def handle_collide(self):
self.x = random.randrande(games.screen.width)
self.y = random.randrange(games.screen.height)
def main():
wall_image = games.load_image("qwerty.jpeg", transparent = False)
games.screen.background = wall_image
pizza_image = games.load_image("qwerty2.jpeg")
pizza_x = random.randrange(games.screen.width)
pizza_y = random.randrange(games.screen.height)
the_pizza = Pizza(image = pizza_image,
x = pizza_x,
y = pizza_y)
games.screen.add(the_pizza)
pan_image = games.load_image("qwerty3.jpeg")
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()
main()