Here's an example of what I did to keep a player on the screen:

if key[pygame.K_DOWN]:
            player.direction = 'down'
            if player.rect.bottom < SCREEN_SIZE[1]:
                player.move(0, 5)
            else:
                pass
        elif key[pygame.K_UP]:
            player.direction = 'up'
            if player.rect.top > 30:
                player.move(0, -5)
            else:
                pass
        elif key[pygame.K_RIGHT]:
            player.direction = 'right'
            if player.rect.right < SCREEN_SIZE[0]:
                player.move(5, 0)
            else:
                pass
        elif key[pygame.K_LEFT]:
            player.direction = 'left'
            if player.rect.left > 0:
                player.move(-5, 0)
            else:
                pass

I would think using a similar method would work to limit movement to a certain 
point.

Dan


On Apr 28, 2010, at 4:48 PM, Alkatron wrote:

> Maybe it's a stupid question.......
> But i can't find how to move a sprite and stop it at (x,y) without 
> collisions.....in an empty space.
> I don't need step by step instruction....
> Pointing me to a running example is enough...
> 
> Thanks to all
> 
> Alkatron
> 

Reply via email to