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

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



+ 1 for Charlie's way.

@Michael:

Depending on if you do the directional keypressed check more than once
It may be better to.

<code>
DIRECTIONAL_KEYS = (K_UP, K_DOWN, K_LEFT, K_RIGHT): # put this up by your other constants

elif event.key in DIRECTIONAL_KEYS:
  do_stuff()
</code>

That way you only have to change your one constant and then reference it whenever you want. It helps to have all your constants in one spot too so they are easy to find. Just a thought.

Cheers,
James Hancock

On Fri, Oct 31, 2008 at 1:20 PM, Charlie Nolan <funnyman3595@xxxxxxxxx> wrote:
set_repeat isn't exactly ideal because it produces jerky movement.  I
just ignore the events altogether and use pygame.key.get_pressed once
a tick.

-FM

On Fri, Oct 31, 2008 at 11:47 AM, Paul Pigg <masterpigg@xxxxxxxxx> wrote:
> Have you tried using the pygame.key.set_repeat() function?  Otherwise, I
> would use the KEYDOWN event to set the speed in either x or y direction (I
> like diagonal movement ;)) and the KEYUP event to reset the directional
> speed to zero.  With that method, you'd need logic to deal with abrupt
> changes such as the user holding the up arrow, then pressing the down arrow
> before releasing the up arrow (which may again be taken care of by
> set_repeat).
>
> --p
>
> On Fri, Oct 31, 2008 at 3:13 AM, Michael Fiano <michael.fiano@xxxxxxxxx>
> wrote:
>>
>> On Fri, 31 Oct 2008 18:39:31 +1000
>> Nicholas Dudfield <ndudfield@xxxxxxxxx> wrote:
>>
>> > I am pretty sure you don't need to run event.pump() for every event.
>> >
>> > It doesn't seem like `keyinput` is being used at all so it's probably
>> > not needed.
>>
>> You're right. I don't need it anymore. keyinput was being used before
>> to make it so that more than one key could be pressed to move the
>> character. I gave up due to minor bugs in my code and forgot to remove
>> that little bit. What I would like to do:
>>
>> 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.
>>
>> > <code>
>> > elif event.key == K_UP or event.key == K_DOWN or event.key == K_LEFT
>> > or event.key == K_RIGHT:
>> >     do_stuff()
>> > </code
>> >
>> > The python idiom for this is
>> >
>> > <code>
>> > elif event.key in (K_UP, K_DOWN, K_LEFT, K_RIGHT):
>> >     do_stuff()
>> > </code>
>>
>> Aha, nice. Thanks!
>
>