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

Re: [pygame] my rpg game (so far)



For my method, just drop this into your main event-handling loop (with
changes as needed):
    if event.type == USEREVENT
        keys = pygame.key.get_pressed()
        speed = constants.SCROLL_SPEED / graphics.constants.FPS

        if keys[K_LEFT]:
            pos[1] -= speed
        if keys[K_RIGHT]:
            pos[1] += speed
        if keys[K_UP]:
            pos[0] -= speed
        if keys[K_DOWN]:
            pos[0] += speed

You'll also want to do this in the setup:
FPS = 30
pygame.timer.set_timer(USEREVENT, 1000. / FPS)

Adjust FPS up to make it smoother, down to use less CPU.  30 FPS seems
to be a good setting for me.

-FM

On Fri, Oct 31, 2008 at 2:21 PM, Michael Fiano <michael.fiano@xxxxxxxxx> wrote:
> On Fri, 31 Oct 2008 06:13:15 -0400
> Michael Fiano <michael.fiano@xxxxxxxxx> wrote:
>
>> Right now if you are holding a directional key to move, and you press
>> a different directional key at the same time, the player will stop,
>> instead of changing directions. If anyone could give me some pointers
>> on how to do this I'd be very happy, because I want it to be
>> gamepad-friendly too.
>
> Correction: The player doesn't stop when a 2nd simultaneous direction
> is pressed. It does stop moving the player under the following
> conditions though, and I would like to somehow prevent it:
>
> If you hold down any cursor key then change directions by holding
> down another cursor key and then lift your finger off the second to
> resume the direction of the first, the avatar will actually stop
> instead. I want to resume moving in the first pressed (and
> still pressed) direction instead of stopping abruptly. I have tried the
> sugestions here to no avail. Are there any games with this type of
> movement functionality, or any sample code anywhere?
>