[pygame] PyGame Windows Key Behaviour
Hi there! I've written a small demo pong game. There are 2 players, one is cpu controlled. To sync there movement i use clock = pygame.time.Clock() and in the while loop: milli = clock.tick() seconds = milli/1000. on checking the events it's: if event.type == KEYDOWN: if event.key == K_DOWN: b_y += seconds * playerspeed cpu changes his position with an equal function, until it reaches the height of the ball under winXP cpu and player can move with an equal speed under win7 the player is significant slower than the cpu. it seems that a player only can move 2/3 the distance than the cpu player is able to Do you have any hint's what can be done to fix this? with kind regards Thomas
Re: [pygame] PyGame Windows Key Behaviour
What is this equal function that the AI uses, exactly? Does it use the same playerspeed variable? It might also be possible that you have a rounding problem, especially if you aren't limiting the frame rate (which seems to be the case). This might, for example, make you move faster in one direction than the other. To avoid these issues, you can store an absolute decimal position, and then each step find an integer pixel position from that each step which can be used for calculations, drawing, etc in the game. Alternatively, you can abandon the approach you're using and just go at a constant frame rate, say 60 FPS, and then define pixels per frame speeds instead of pixels per second. From: Thomas pummer.tho...@gmail.com To: pygame-users@seul.org Sent: Mon, January 31, 2011 6:22:46 AM Subject: [pygame] PyGame Windows Key Behaviour Hi there! I've written a small demo pong game. There are 2 players, one is cpu controlled. To sync there movement i use clock = pygame.time.Clock() and in the while loop: milli = clock.tick() seconds = milli/1000. on checking the events it's: if event.type == KEYDOWN: if event.key == K_DOWN: b_y += seconds * playerspeed cpu changes his position with an equal function, until it reaches the height of the ball under winXP cpu and player can move with an equal speed under win7 the player is significant slower than the cpu. it seems that a player only can move 2/3 the distance than the cpu player is able to Do you have any hint's what can be done to fix this? with kind regards Thomas
Re: [pygame] PyGame Windows Key Behaviour
On Mon, Jan 31, 2011 at 4:22 AM, Thomas pummer.tho...@gmail.com wrote: cpu changes his position with an equal function, until it reaches the height of the ball under winXP cpu and player can move with an equal speed under win7 the player is significant slower than the cpu. it seems that a player only can move 2/3 the distance than the cpu player is able to If they're both using a similar function, but they're going at a different speed, then the problem lies there. My guess is that the key events are not being fired each frame. What you want is to use pygame.key.get_pressed(). Ian
Re: [pygame] PyGame Windows Key Behaviour
Hi Thomas, can you just post all the code? in particular what's missing is seeing how the player ball and cpu are moved and how those things relate together. There are definitely people on the list who could easily identify the cause of your problem in an instant with that information. Also, there a number of techniques that could be used that would prevent the problem you are describing from ever occuring, and it would be easier to communicate how such techniques work if we could see where you are coming from now. thanks On Mon, Jan 31, 2011 at 3:22 AM, Thomas pummer.tho...@gmail.com wrote: Hi there! I've written a small demo pong game. There are 2 players, one is cpu controlled. To sync there movement i use clock = pygame.time.Clock() and in the while loop: milli = clock.tick() seconds = milli/1000. on checking the events it's: if event.type == KEYDOWN: if event.key == K_DOWN: b_y += seconds * playerspeed cpu changes his position with an equal function, until it reaches the height of the ball under winXP cpu and player can move with an equal speed under win7 the player is significant slower than the cpu. it seems that a player only can move 2/3 the distance than the cpu player is able to Do you have any hint's what can be done to fix this? with kind regards Thomas