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

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



On Fri, 31 Oct 2008 14:31:54 -0500
"Charlie Nolan" <funnyman3595@xxxxxxxxx> wrote:

> 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.

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

Here's what happens:
It works as expected if the first key is left or right, and the 2nd key
held is up or down. It does not work with up or down as the first key
pressed (it just keeps moving rather than stopping this time). Does
anyone see of hand why this is? It's not making much sense to me.