Hi Bob,
There are a lot of ways to do it..
In the past, I've used something like this for teaching basic movement:
- Store time since previous frame
- Poll for events
- Update held keys
- If movement key held,
- set movement/direction flag for player sprite
- Update sprite ai based on time since previous frame
- if movement/direction flag on
- generate a rect for the proposed new location
- see if the new location only includes non-blocked tiles
(background collision)
- If it doesn't, this is our sprite's new rect
- If it does, either
- do nothing (very basic) or
- move to the edge of the original position
This should work fine for objects that won't move fast enough to cover more
than a tile per frame..
Is that what you were looking for? Or something even more abstracted like..
while True:
tts = fpcClock.tick( FPS )
held_keys = update_keys()
draw_background()
update_sprites( tts, held_keys )
draw_sprites()
pygame.display.update()
Thank you,
Noel
On Tue, Oct 6, 2015 at 4:12 PM, Bob Irving <[email protected]> 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
>
>