Hello Bob,

So it seems that Blitz Basic has a different way to handle collisions. You’re 
saying to the ifImagesCollide function, “Here, I’m going to give you a long 
list of these attributes, and you figure it all out.” 

The Pygame way is different because you just give the equivalent collision 
function merely two Pygame sprites, and it tells you if you’ve collided:

from pygame import *
...
did_we_collide = collide_rect( sprite_a, sprite_b )       # /(Collision 
documentation)/[1]


But to get to this point, you need to create two sprite objects, which have 
class member functions to update and draw themselves. /(Sprite 
documentation)/[2] 


In Pygame Zero, which I mentioned in my previous post, sprite creation and 
keyboard checking is simplified. 

For the keyboard, you have an optional update() function, and if you use it, 
then you would code your keyboard polling like this:

*def* update():
    *if* keyboard.left:
        alien.x -= 1
    *elif* keyboard.right:
        alien.x += 1



keyboard[keys.A]      /# True if the 'A' key is pressed/
keyboard[keys.SPACE]  /# True if the space bar is pressed/
In each case, the check is just one line. (Documentation[3])
Sprites are wrapped up and called Actors, and it’s easier to understand how to 
use them than to explain Python inheritance and method member functions. 
In Pygame Zero, it’s:
alien = Actor('alien', (50, 50))
And then there are a small number of well-defined functions where you can put 
your code, such as having one draw function and one update function.
*def* draw():
    screen.clear()
    alien.draw()
This is all Python and Pygame under the hood, but it cleans up the path so it’s 
easier for newcomers to understand.
Hope this gives you a different perspective.
~ Michael 



> 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, <rockac...@gmail.com> wrote:
> 
> > Could you give us an example of what you have in basic?
> >
> >
> >
> >
> > On Oct 6, 2015, at 13:12, Bob Irving <bob...@gmail.com> 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
> >
> >
> 
> 
> 

--------
[1] http://pygame.org/docs/ref/sprite.html#pygame.sprite.collide_rect
[2] http://pygame.org/docs/ref/sprite.html#pygame.sprite.Sprite
[3] https://pygame-zero.readthedocs.org/en/latest/builtins.html#the-keyboard

Reply via email to