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

Re: [pygame] Function for keyboard movement



Again, thanks to all who replied. We are hacking our way through the Pygame jungle...

PygameZero is intriguing. However, we are still not comfortable with making classes (Sprite or Actor). I realize it's "easier", but it's easier for me, not for an average 9th grade student. We will continue hacking away because we believe that BlitzBasic, even though it delivers a very good intro to text coding, is no longer supported and so doesn't offer a good path forward.

I do appreciate the many offers of assistance, code samples, suggestions.... Perhaps after the end of our marking period, I'll post a couple code samples from our students, and that will give everyone an idea of where we are and where we're headed....

Thanks again,
Bob Irving
Porter-Gaud School
Charleston, SC

On Thu, Oct 8, 2015 at 5:48 AM, Sam Bull <sam.hacking@xxxxxxxx> wrote:
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).




--
Twitter: @birv2
www.bob-irving.com
http://www.scoop.it/t/on-the-digital-frontier