I'm trying to make a game where there are a number of balls bouncing (for now only with 45 degree angle) on a rectangular area and where you can controll a cursor moving horizontally or vertically in the same rectangular area.
The problem seems to be very simple, but there are a lot of things to care attention in order to have the best result.
There are 2 main targets that I would like to reach:
1-smooth movement of balls
2-very quick response to keypress event
Unfortunately two targets are in conflic each other, because if you want a smooth movement you have to repaint practically every loop inside a while statement, but in this way you don't leave spaces for response key.
If you put a sleep (also a sleep(5) !!) the balls movements becomes very slow, but unfortunately you don't get any improvements for the "response key problem".
There is to note that every step I don't clean all the screen but only the previous point where there was the balls, and then I repaint only the balls in the next position.
I have tried also to use fillRect insted balls image with the same results...
Also using keyRepeated, the time from one cursor movement and the other (especially after the first button press) is too slow for my taget.
I have to try to use more than one thread?
Every advice, also the smallest, will be very appreciated!!!
Many thanks in advance!
Since you have a while lopp which is computationally deciding how to draw the balls why don't you have this while loop also process keys that have been placed in a queue from the keypressed. Basically the key press could simple set a value to a variable that is checked in the while loop to process a key movement or you can have a queue. Just a thought. I think a single variable would be fine since you will no optimize any faster with a queue unless of course you want to compute the series of keys in a queue to the final movement.
Thanks anyway, but i managed to solve my self the problem.
The problem was that my code wasn't optimized and, since the 3510i is really slow, the collision detection procedure slowed it all, although the game was really simple and i'd never thought i had this kind of trouble.