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

Re: [pygame] Function for keyboard movement



Hi guys,

Thanks for all the ideas..... I apologize if I wasn't clear enough in my OP.

Since we found that collisions and rects are a stretch for beginning programmers, my colleague came up with the following code:

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;


So that allows us to replicate what we used last year in Blitz Basic, which was

ifImagesCollide(pic1,pic1x,pic1y, pic2, pic2x, pic2y)

One line of code! We (the other teacher and I understand rects but feel that the time spent explaining them was not commensurate with the value the students get at this level.

As for keyboard movement, in BlitzBasic it's

if keydown(right) then....

One line again! So no need to introduce the for event loop, etc.

We are making the switch to Python/Pygame because no one has ever heard of Blitz Basic, and we thought it was perhaps time to update, since most of the world is moving to Python for introducing text-based coding.

However, some of these things make us go hmmm....

Thanks in advance,
Bob Irving
Porter-Gaud School
Charleston, SC



On Wed, Oct 7, 2015 at 1:37 PM, <rockachu2@xxxxxxxxx> wrote:
Could you give us an example of what you have in basic?




On Oct 6, 2015, at 13:12, Bob Irving <bobirv@xxxxxxxxx> wrote:

Hi folks,

We're introducing Python for 9th grade this year and moving from Blitz Basic for game programming. Just wondering if anyone has come up with a way to hide the complexity for keyboard movement..... it's one of those things that makes sense to more advanced programmers but not to beginners. We've experimented with making a few functions to detect collisions, mouse clicks....

TIA,
Bob Irving
Porter-Gaud School
Charleston, SC



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