I'm working on a school project with pygame and the main objectives is to make a lot of objects appear and move randomly. So I wanted to make some particles spawn and move randomly and I came up with this.
import pygame, random
# -- Variables --
pygame.init()
clock = pygame.time.Clock()
fps_limit = 60.0
resx = 1600
resy = 900
screen = pygame.display.set_mode([resx,resy])
# -- Classes --
class Particule():
def __init__ (self,color,radius):
pygame.sprite.Sprite.__init__(self)
self.color = color
self.radius = radius
self.position_x = resx/2
self.position_y = resy/2
def update(self):
pygame.draw.circle(screen, self.color, (self.position_x,self.position_y),self.radius)
def random_movement(self):
self.position_x += random.randint(0,10)
self.position_y -= random.randint(0,5)
def life(self):
self.radius -= 1
# -- Objects --
particule1 = Particule((255,0,0),100)
# -- Game loop --
running = True
while running:
clock.tick(fps_limit)
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
screen.fill((0,0,0))
particule1.update()
particule1.random_movement()
particule1.life()
pygame.display.set_caption("Baguette")
pygame.display.flip()
pygame.quit()
I tried doing some while/if/for loops but only one object appears and then none