I am making a game using pygame and livewires. I am having trouble with the scoreboard- it updates appropriately but does not delete the old scoreboard, thus creating a blob of numbers:
class Ship(games.Sprite):
"""Ship, represents the player"""
image = games.load_image("ship.bmp")
DELAY = 25
def __init__(self, x, y):
super(Ship, self).__init__(image = Ship.image, x = x, y = y)
self.missile_wait = 0
self.score = games.Text(value = Missile.SCORE,
size = 30,
color = color.white,
top = 5,
right = games.screen.width - 10,
is_collideable = False)
games.screen.add(self.score)
def update(self):
#move based on input
if games.keyboard.is_pressed(games.K_LEFT):
self.x -= 2
if games.keyboard.is_pressed(games.K_RIGHT):
self.x += 2
#stops ship from moving off screen
if self.x < 1:
self.x = 1
if self.x > games.screen.width:
self.x = games.screen.width
#update missile wait
if self.missile_wait > 0:
self.missile_wait -= 1
#fire missile if space pressed and no delay
if games.keyboard.is_pressed(games.K_SPACE) and self.missile_wait == 0:
new_missile = Missile(self.x, self.top)
games.screen.add(new_missile)
self.missile_wait = Ship.DELAY
#check for overlap, die accordingly
if self.overlapping_sprites:
for sprite in self.overlapping_sprites:
sprite.die()
self.die()
def die(self):
boom = Explosion(self.x, self.y)
games.screen.add(boom)
self.destroy()
class Missile(games.Sprite):
"""A missile from the player's ship"""
image = games.load_image("missile.bmp")
SCORE = 0
def __init__(self, shipx, ship_top):
super(Missile, self).__init__(image = Missile.image, x = shipx,
y = ship_top - 25, dy = -2)
def update(self):
#if missile hits top of screen, destroys itself
if self.top < 0:
self.die()
#if missile overlaps, destroy missile and overlapping sprites
if self.overlapping_sprites:
for sprite in self.overlapping_sprites:
self.update_score()
sprite.die()
self.destroy()
def die(self):
self.destroy()
def update_score(self):
Ship.score.destroy()
Missile.SCORE += 30
self.score = games.Text(value = Missile.SCORE,
size = 30,
color = color.white,
top = 5,
right = games.screen.width - 10,
is_collideable = False)
games.screen.add(self.score)
The ship is instantiated and creates an initial scoreboard. Every time a missile kills an enemy, it calls the 'update_score' method. The method attempts to delete the original scoreboard, but does not work. How do I get it to delete the scoreboard from another class?