首页 > 解决方案 > 我怎样才能让多个水泥块产生,而不是一个改变位置的水泥块?

问题描述

我无法在多个水泥块精灵中产卵。我只对想要生成的精灵使用了一张图像,但我希望能够生成多个相同的水泥块精灵。现在我只能在一个使用随机模块随机改变位置的水泥块中生成。

我的 GitHub 只是以防您想查看其余代码:https ://github.com/Enoc-Mena99/AutoPilot

我的代码:

import time
import pygame
import random

#screen height & width
WIDTH = 1000
HEIGHT = 400

screen = pygame.display.set_mode((WIDTH,HEIGHT))

#debris class
class Debris(pygame.sprite.Sprite):
    def __init__(self, scale, speed):
        pygame.sprite.Sprite.__init__(self)

        self.y = HEIGHT/2 - 200
        self.speed = speed

        #load debris
        self.images = []
        img = pygame.image.load('debris/cement.png').convert_alpha()
        img = pygame.transform.scale(img, (int(img.get_width()) * scale, (int(img.get_height()) * scale)))
        self.images.append(img)
        self.image = self.images[0]
        self.rect = self.image.get_rect()

    #draw debris to screen
    def draw(self):
        #random spawns
        rand_x = random.randint(1,1000)
        screen.blit(self.image,(rand_x,self.y))
        time.sleep(3)

标签: pythonpygame

解决方案


推荐阅读