[Tutor] Why Won't My Pizza Fall?

Ricardo Aráoz ricaraoz at gmail.com
Mon Jan 14 03:37:26 CET 2008


Alan Gauld wrote:

> However, I do agree that an init method is probably the wrong
> place to have a dx/dy pair since we should, I would ex[pect,
> be positioning the object initially before trying to move it.
> Thus I'd expect a move metjod someplasce that took the
> dx and dy. Something like:
> 
>   class Pizza(games.Sprite):
>     """A falling pizza."""
>     def __init__(self, screen, x, y, image):
>         """Initialize pizza object."""
>         self.init_sprite(screen = screen, x = x, y = y, image = image)
>         self.x = x
>         self.y = y
> 
>     def fall(self, dx=0,dy=0):
>         self.x += dx
>         self.y += dy
>         self.delete_sprite()    # clear the old
>         self.init_sprite(self.x, self.y) # draw the new
> 
> However since in re-reading the description I think this Pizza
> is supposed to fall automatically the default drop could be
> passed in to the init, but we should try to arrange for the fall
> to be called periodically(by mainloop?)
> 
> But in either case the calculation of the new x and y values
> should be done by the object itself. If it isn't supposed to
> know where it is then what does?
> 
> Alan G.
> 

Anyway Alan, what do you think about Pizza as a class? It has two
properties, (x, y) that express it's position, but with respect to what?
Pizza cannot exist by itself, it has a strong dependency on another
object that will give context to Pizza.x and Pizza.y and in giving
context then it would modify Pizza's behavior (for instance, what
happens and where is the floor). So Pizza is tightly coupled with
another object. Isn't that questionable? I don't have an answer. What do
you think?



More information about the Tutor mailing list