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

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



> Ok, I'm getting closer. I did this:
>
>                        if event.type == USEREVENT:
>                                keys = pygame.key.get_pressed()
>                                if keys[K_UP]:
>                                        self.player.move = 1
>                                elif keys[K_DOWN]:
>                                        self.player.move = 2
>                                elif keys[K_LEFT]:
>                                        self.player.move = 3
>                                elif keys[K_RIGHT]:
>                                        self.player.move = 4
>
> Here's how it works:
> player.move = 0-4 where 0 = stop, 1 = up, 2 = down, 3 = left, 4 = right
You need separate values for x and y. and don't use elifs, use a set
of ifs.  The way you're doing it disallows for diagonal movement and
creates some other issues.