18
Июл
2021

Pygame window не отвечает

Пайгейм не отвечает, вот код:

from superwires import games, color
games.init(screen_width = 530, screen_height = 600, fps = 60)

#Car sprite
class Car(games.Sprite):
    image = games.load_image("C:/python/car.bmp")
    def __init__(self):
        super(Car, self).__init__(image = Car.image,
                                  x = games.mouse.x,
                                  bottom = games.screen.height - 10)
        self.score = games.Text(value = 0, size = 25, color = color.yellow,
                                top = 5, right = games.screen.width/2)
        games.screen.add(self.score)
    def update(self):
        self.x = games.mouse.x
        if self.left < 65:
            self.left = 65
        if self.right > games.screen.width - 65:
            self.right = games.screen.width - 65

#Bush sprite
class Bush(games.Sprite):
    image = games.load_image("C:/python/bush.bmp")
    speed = 1
    def __init__(self, x = 20, y = 100):
        super(Bush, self).__init__(image = Bush.image,
                                   x = x, y = y,
                                   dy = Bush.speed)
    #Bush spawn algorithm
    def update(self):
        bushes_list = [Bush()]
        while True:
            for bush in bushes_list:
                if bushes_list[0].bottom > games.screen.height/2 and len(bushes_list) < 3:
                    bushes_list.append(Bush(), Bush(515, -100))
                if bushes_list[0].bottom > games.screen.height:
                    bushes_list.pop(0)

#Start
def main(): 
    road = games.load_image("road.jpg", transparent = False)
    games.screen.background = road
    bush1 = Bush()
    bush2 = Bush(515, 100)
    car = Car()
    games.screen.add(bush1)
    games.screen.add(bush2)
    games.screen.add(car)
    games.mouse.is_visible = False
    games.screen.event_grab = True
    games.screen.mainloop()

main()

Источник: https://ru.stackoverflow.com/questions/1306476/pygame-window-%D0%BD%D0%B5-%D0%BE%D1%82%D0%B2%D0%B5%D1%87%D0%B0%D0%B5%D1%82

Тебе может это понравится...

Добавить комментарий