python - 我怎样才能让多个水泥块产生,而不是一个改变位置的水泥块?
问题描述
我无法在多个水泥块精灵中产卵。我只对想要生成的精灵使用了一张图像,但我希望能够生成多个相同的水泥块精灵。现在我只能在一个使用随机模块随机改变位置的水泥块中生成。
我的 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)
解决方案
推荐阅读
- masstransit - MassTransit RequestClient 超时处理
- javascript - 无法识别对象属性:Uncaught ReferenceError: fat is not defined
- jsonata - 如何在 Jsonata 中以 $match 模式传递动态字符串?
- waze - 是否可以离线使用 Waze 或使用他们的路由算法进行开发?
- spring-mvc - AsyncRestTemplate + 协程
- azure-maps - 是否有用于地理定位的打字稿或 javascript api - 在 Azure Maps npm 模块 azure-maps-rest 中获取 IP 到位置预览功能
- python - 无法选择正确的 Cookie 以使用 python 代码登录
- python - pythonscript没有用pdflatex编译
- angular - 如何根据屏幕上剩余的可用空间向数组添加更多项目
- python - 在子类 QtCore.QAbstractItemModel 上使用 QSortFilterProxyModel 时,PyQt5 Treeview 不需要扩展索引