1

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?

martineau
  • 119,623
  • 25
  • 170
  • 301
korni
  • 89
  • 9
  • 2
    Make `speed` a `property` of the `Pizza` class. – martineau Sep 16 '20 at 17:49
  • I could include whole code but speed is a property of Pizza class what I want to achievie is to check score everytime it is 100, 200 etc and do it "without an end". – korni Sep 16 '20 at 17:51
  • 1
    In that case, in the setter method of the `speed` property, use the `%` operator to detect when the score value is a whole multiple of 100 (similar to what's in @Rabbid76's answer). – martineau Sep 16 '20 at 17:55

1 Answers1

1

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() 
Rabbid76
  • 202,892
  • 27
  • 131
  • 174