I have no idea why the score is keep increasing when the Sprite object is destroyed?
<p>I am now trying to make a mini game that making a user to dodge all falling pizzas from the sky. However, after a pizza touches the bottom of the graphic screen, the score of user keep increases infinitely, and I have no idea why is it happening. Please help me to fix this problem.</p>

<pre><code>from livewires import games, color
import random

games.init(screen_width = 640, screen_height = 480, fps = 50)

class Pizza(games.Sprite):
    image = games.load_image("pizza.bmp")
    speed = 2
    pizza_count = 0

    def __init__(self, x, top):
        super(Pizza, self).__init__(image = Pizza.image, x = x,
                                    top = top, dy = Pizza.speed)

    def update(self):
        if self.bottom &gt; games.screen.height:
            Pizza.pizza_count += 1
            self.destroy()

        if self.left &lt; 0:
            self.left = 0

        if self.right &gt; games.screen.width:
            self.right = games.screen.width

    def end_game(self):
        end_message = games.Message(value = "Game Over!",
                                    size = 80,
                                    x = games.screen.width/2,
                                    y = games.screen.height/2,
                                    color = color.red,
                                    after_death = games.screen.quit,
                                    lifetime = 5 * games.screen.fps)
        games.screen.add(end_message)


class Runner(games.Sprite):

    image = games.load_image("chef.bmp")
    score = games.Text(value = 0, size = 50, color = color.black,
                       top = 50, right = games.screen.width - 10)

    def __init__(self, x = games.screen.width/2, bottom = games.screen.height):
        super(Runner, self).__init__(image = Runner.image,
                                      x = x, bottom = bottom)
        games.screen.add(Runner.score)
        self.pizza_x = random.randrange(games.screen.width)

        pizza = Pizza(x = self.pizza_x, top = 0)
        games.screen.add(pizza)

    def update(self):
        if games.keyboard.is_pressed(games.K_LEFT):
            self.x -= 3

        if games.keyboard.is_pressed(games.K_RIGHT):
            self.x += 3

        if self.right &gt; games.screen.width:
            self.right = games.screen.width

        if self.left &lt; 0:
            self.left = 0

        for pizza in self.overlapping_sprites:
            pizza.destroy()
            pizza.end_game()

        Runner.score.value += Pizza.pizza_count * 10
        Runner.score.right = games.screen.width - 10
        games.screen.add(Runner.score)






def main():
    background_image = games.load_image("wall.jpg", transparent = False)
    games.screen.background = background_image

    runner = Runner()
    games.screen.add(runner)
    games.screen.mainloop()

main()
</code></pre>

<p>Instances are removed by the garbage collector as soon as there are no more references to it, so there still must be a reference to it... here;</p>

<pre><code>pizza = Pizza(x = self.pizza_x, top = 0) # pizza is still referring to it!
games.screen.add(pizza)
</code></pre>

<p>Try placing 'pizza = None' under the 'games.screen.add(pizza)' line.
If all is well the self.destroy() function should remove the last reference and have the intended effect.</p>

<p>It might also be a good idea to use a flag to indicate scoring has taken place just in case the garbage collector isn't fast enough to remove the instance..</p>

<pre><code>def __init__(self, x, top):
    super(Pizza, self).__init__(image = Pizza.image, x = x,
                                top = top, dy = Pizza.speed)
    self.scoreFlag = False

def update(self):
    if self.bottom &gt; games.screen.height:
        if self.scoreFlag == False:
            Pizza.pizza_count += 1
            self.scoreFlag = True
        self.destroy()
            self.destroy()
</code></pre>

python object sprite