[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [pygame] Function for keyboard movement



I think there are a lot of ideas getting thrown at you. If you are still
a little unsure of how to proceed, it might be a good idea to give a
little example program you might expect one of your students to write
(or a previous example from Blitz Basic) so we can get a better idea of
what kind of interface you are looking for.

I suspect using Sprites would give you a good interface for the
collision and adding them into a group would give an easy interface for
the blitting and updating for you. Note, also, that you can subclass the
Sprite class and define an update method for each object independently.

I'm unsure of whether you are looking to hide the entire game loop, or
just simplify the keyboard handling within it, so an example of what you
expect would be useful.


On Wed, 2015-10-07 at 14:41 -0400, Bob Irving wrote:
> def imagesCollide(pic1,p1x,p1y,pic2,p2x,p2y):
>     aRect = pic1.get_rect(center=[p1x,p1y])
>     bRect = pic2.get_rect(center=[p2x,p2y]) 
>    
>     if aRect.colliderect(bRect):
>         return True;
>     else:
>         return False;

Minor niggle on style, but last 4 lines should be simply:

        return aRect.colliderect(bRect)

And, don't use semi-colons at end of lines, they are for putting
multiple statements on one line (and that should be avoided 99.99% of
the time).

Attachment: signature.asc
Description: This is a digitally signed message part