[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

R: [pygame] key pressed problem



Ok  tnx a lot...

-----Messaggio originale-----
Da: owner-pygame-users@seul.org [mailto:owner-pygame-users@seul.org] Per
conto di Sami Hangaslammi
Inviato: venerd́ 25 ottobre 2002 12.49
A: pygame-users@seul.org
Oggetto: Re: [pygame] key pressed problem


Remove the "if e.type == KEYDOWN" and call "chiave" on every iteration.

Then change the function to:

def chiave(hero,key):
         hero.direction = -1
         if key[K_DOWN]:
             hero.set_directions(0,0,1)
         elif key[K_UP]:
             hero.set_directions(1,0,-1)
         elif key[K_LEFT]:
             hero.set_directions(2,-1,0)
         elif key[K_RIGHT]:
             hero.set_directions(3,1,0)
         if key[K_RETURN]:
             if not hero.battle:
                 hero.battle = 1

This way, if no direction key is pressed, the direction is set to -1.

On Fri, 25 Oct 2002, Gabriele Farina wrote:

> I got this script to handle my events:
>
> Def chiave(hero,key):
>         if key[K_DOWN]:
>             hero.set_directions(0,0,1)
>         elif key[K_UP]:
>             hero.set_directions(1,0,-1)
>         elif key[K_LEFT]:
>             hero.set_directions(2,-1,0)
>         elif key[K_RIGHT]:
>             hero.set_directions(3,1,0)
>         elif key[K_RETURN]:
>             if not hero.battle:
>                 hero.battle = 1
> ....
> while 1:
>         #time.sleep(0.05)
>         for e in pygame.event.get():
>             if e.type == QUIT:
>                 break
>             elif e.type == KEYDOWN:
>                 k = pygame.key.get_pressed()
>                 chiave(hero,k)
>             else:
>                 hero.direction = -1
>
> ....
>
> when I run this script and I press one key, there are no problems;
when
> I press a second key while I'm pressing the first one, the hero moves
in
> the right direction. But when I release one of the two keys the hero
> stops...
>
> why?


--
Sami Hangaslammi

____________________________________
pygame mailing list
pygame-users@seul.org
http://pygame.seul.org

____________________________________
pygame mailing list
pygame-users@seul.org
http://pygame.seul.org