Hi guys ive been reading a beginners book on python and the author created a simple game with the liewires package. I understand the explaination but there is just 1 part that i don't quite get. I'm not great at maths but this isn't complex at all. i don't know if i should post the whole code, cos' its only 1 line i don't get, so ill post only relevant code and my comments inbetwen these lines "-----" <- so skim to those lines which are relevant. 1st here is the line of code i don't get.
# sets buffer to approx 30% of pizza height, regardless of pizza speed self.time_til_drop = int(new_pizza.height * 1.3 / Pizza.speed) + 1 so the game is about a chef who drops pizzas from the top of a building. Both chef and pizza are objects from a chef and pizza class. ----- the pizza falls at a speed of 1. ------- class Pizza(games.Sprite): ---speed = 1-------- image = games.load_image("pizza.bmp") def __init__(self, x, y = 90): """ Initialize a Pizza object. """ super(Pizza, self).__init__(image = Pizza.image, x = x, y = y, ------dy = Pizza.speed------ #dy is the verticle movement of the falling pizzas ----------the pizza object is initilized in the chef class---------- ------self.tme_till_drop is the property i need help with--------- class Chef(games.Sprite): def __init__(self, y = 55, speed = 2, odds_change = 200): """ Initialize the Chef object. """ super(Chef, self).__init__(image = Chef.image, x = games.screen.width / 2, y = y, dx = speed) self.odds_change = odds_change ----self.time_til_drop = 0-------- self.check_drop() #this is the function that determines timing of pizza drops def check_drop(self): """ Decrease countdown or drop pizza and reset countdown. """ if self.time_til_drop > 0: self.time_til_drop -= 1 else: new_pizza = Pizza(x = self.x) #positions the pizza's x(horizontal positon) to match that of the chef's games.screen.add(new_pizza) # set buffer to approx 30% of pizza height, regardless of pizza speed self.time_til_drop = int(new_pizza.height * 1.3 / Pizza.speed) + 1 i understand the code until the comment set buffer. No where in the code does it say the pizza's height. Im guessing the height is the actual pizza image's height in pixels. "pizza.bmp" heres the code: self.time_til_drop = int(new_pizza.height * 1.3 / Pizza.speed) + 1 so if, let's say the pizza height is 60(pixels). multiplying it by 1.3 gives me 78. dividing it by Pizza.speed seems pointless as Pizza.speed is 1, and i will get 78 again. then adding one makes it 79. i don't see how 79 is 30% of 60. 60 being the pizza's height. I know im looking at it all wrong. Can anyone please help explain to me that line of code and the authors calculation:( _______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor