from JMSSGraphics import *
from Particle import *
import random 

jmss = Graphics(width = 800, height = 600, title = "Luigi", fps = 60)

luigi_list = []

n = 0
r = 1
tree = jmss.loadImage("road1.jpg")

def Particles():
    global n, y, x, img, luigi
    while n < 1000:
        luigi = Particle()
        luigi.img = jmss.loadImage("leaf1.png")
        luigi.x = random.randint(0, 800)
        luigi.y = random.randint(600, 1200)
        luigi_list.append(luigi)
        n += 1


@jmss.mainloop
def game():
    global x, y, img, luigi, n,r

    jmss.drawImage(tree, x = 200, y = 0, width = 500, height = 545)
    Particles()
    
    jmss.clear(0, 0, 0, 1)
    n = 0

    while n < len(luigi_list):
        luigi_list[n].y = luigi_list[n].y - 5
        jmss.drawImage(luigi_list[n].img, luigi_list[n].x, luigi_list[n].y, width = 30, height = 40, anchorX= 0.5, anchorY = 0.5, rotation = r)
        n += 1
        r += 0.05

    n = 0
    while n < len(luigi_list):
        luigi_list[n].y = luigi_list[n].y - random.randint(0,600)
        if luigi_list[n].y < 0:
            luigi_list.pop(n)
            Particles()

    
jmss.run()
