I'm having trouble spawning in multiple cement block sprites. I am using only one image for the sprite I want to spawn in, but I want to be able to spawn multiple of the same cement block sprite. Right now I can only spawn in one cement block that changes positions randomly using the random module.
My GitHub just incase you want to look at the rest of the code: https://github.com/Enoc-Mena99/AutoPilot
my code:
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)