dimanche 3 novembre 2019

How to keep generating random numers from a differant class than the class you're using the numbers for

I need to keep gerating random accelarations for my random movemement in my brain class to change the direction and the possibility to clone the movement from my dots,but right it generates one number and keeps adding it to my velocity.In short my dot is moving in a straight line.How do I fix this.

I haven't tried much because I just don't know how to do it. I'm a beginner so I just don't know the specific code.

def wander(self):
        if self.pos[0] < 5 or self.pos[0] > WIDTH - 5 or self.pos[1] < 5 or self.pos[1] > HEIGHT - 5:
            self.vel = 0
        else:
            self.vel = self.vel + acc
            self.pos = self.pos +self.vel



#--------------------------------------------------------------------------
#--------------------------------------------------------------------------

class brain:
    acc = 0.02 * np.random.random(2) - 0.01



#--------------------------------------------------------------------------

dots = []
for i in range(200): #generate n cells
    Dot = dot()
    dots.append(Dot)

#--------------------------------------------------------------------------

def mainloop():
    while True:
        for event in pygame.event.get():
            if event.type== QUIT: #if pressing the X, quit the program
                pygame.quit() #stop pygame
                sys.exit() #stop the program
        screen.fill((0,0,0)) #clear the screen;
        for i in dots: #update all dots
            i.wander()
            i.draw()
        pygame.display.update() #update display
mainloop()



Aucun commentaire:

Enregistrer un commentaire