I'm having trouble with making multiple lines draw to the screen when using a class. I don't want to have to make several class instances of the same thing, just want to be able to append it to a list and have it fall. I've only managed to make one appear on the screen and that is all. Any help would be appreciated, thx.
import pygame
import random
#Classes
class Drop:
def __init__(self, window, color, x, y,speed):
self.x = x
self.y = y
self.speed = speed
self.window = window
self.color = color
def fall(self):
self.y = self.y + self.speed
pygame.draw.line(self.window , self.color ,[ self.x , self.y],[self.x, self.y + 30], 2)
#functions
#Program Loop
def main():
gameExit = True
#Making the raindrops
for i in range(500):
x = random.randint(10,500)
y = 1
uno = Drop(window , purple,x,y,speed)
rain.append(uno)
while gameExit != False:
for event in pygame.event.get():
if event.type == pygame.QUIT:
gameExit = False
window.fill(white)
uno.fall()
pygame.display.update()
#Variables
DISPLAY_HEIGHT = 500
DISPLAY_WIDTH = 800
rain = []
speed = 0.5
purple = (128,0,128)
white = (255,255,255)
#Game init
pygame.init()
window = pygame.display.set_mode((DISPLAY_WIDTH, DISPLAY_HEIGHT))
pygame.display.set_caption("Purple Rain")
main()
pygame.quit()
This line
uno.fall()
should be in the for-loop. Outside it will refer to the last drop -> You see only one
Right code:
window.fill(white) # screen-cleaning should be done first
for i in range(500):
x = random.randint(10,500)
y = 1
uno = Drop(window , purple,x,y,speed)
rain.append(uno)
uno.fall() # changed
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments