Quick debugging question [Python, pygame] -
it's still incomplete program, reason value of textbox doesn't increase when should... why this?? when pizza sprite overlaps pan sprite, score in textbox supposed increase in value 10. why not occur?
thanks!
''' created on jul 1, 2011 @author: ******* louis ''' #watch me do. livewires import games, color import random games.init (screen_width = 640, screen_height = 480, fps = 50) #pizza class class pizza (games.sprite): pizzaimage = games.load_image ("pizza.bmp", transparent = true) def __init__(self, x = random.randrange(640), y = 90, dy = 4): super (pizza, self).__init__(x = x, y = y, image = pizza.pizzaimage, dy = dy) def handle_caught (self): self.destroy() class pan (games.sprite): panimage = games.load_image ("pan.bmp", transparent = true) def __init__ (self, x = games.mouse.x, y = games.mouse.y): super (pan, self).__init__(x = x, y = y, image = pan.panimage) self.score = 0 self.textbox = games.text (value = str(self.score), size = 20, color = color.black, x = 550, y = 50) games.screen.add(self.textbox) def update (self): #wwwwow there *update* method self.x = games.mouse.x self.y = games.mouse.y if self.left < 0: self.left = 0 if self.right >640: self.right = 640 if self.top < 0: self.top = 0 if self.bottom > 480: self.bottom = 480 self.check_collision() def check_collision (self): pizza in self.overlapping_sprites: self.score = self.score + 10 pizza.handle_caught() #main def main(): wallbackground = games.load_image ("wall.jpg", transparent = false) games.screen.background = wallbackground games.screen.add(pizza()) games.screen.add(pan()) games.mouse.is_visible = false games.screen.event_grab = true games.screen.mainloop() main()
the textbox takes value string. when create textbox, create string current value of score, , set text string. no lasting connection between score , textbox made.
the textbox has method available update text; call method value str(self.score)
after increment score.
Comments
Post a Comment