How to have method called everytime variable increases?

105 Views Asked by At

I'm trying to add some difficulty in "game". Basically I want to call method to increase speed of a sprite everytime players score is multiply of 100 (it should happen on 100, 200, etc.).

I'm using pygame and livewires packages.

How I handled it was by using range like:

if self.score.value in range(0, 10000+1, 100):
                pizza.update_speed()

and update method just increases speed:

def update_speed(self):
        Pizza.speed += 0.25

So... it works but I am sure that it is not elegant and there is a better way of doing it.
How should I code it so I can check the score "infinitely" and in a proper way?

1

There are 1 best solutions below

0
On BEST ANSWER

You can check if the remainder (%) of the division of self.score.value and 100 is 0:

if self.score.value % 100 == 0:
    pizza.update_speed()