Pong Help

I have gotten a pong program to work but i need help on making it run faster. when the screen refreshes the bottom line blinks because of the slight time it takes to refresh, can that be easily fixed? Problem most likely is ineffiecent loops, but i don't know how to fix.

Comments

: I have gotten a pong program to work but i need help on making it run faster. when the screen refreshes the bottom line blinks because of the slight time it takes to refresh, can that be easily fixed? Problem most likely is ineffiecent loops, but i don't know how to fix.: Do not refresh the whole screen, but only the paddles and the ball. This is a lot faster than a whole-screen refresh.

[b][red]This message was edited by zibadian at 2006-10-15 10:56:26[/red][/b][hr]: : : Do not refresh the whole screen, but only the paddles and the ball. This is a lot faster than a whole-screen refresh.: : : how do i do that?: That greatly depends on the text/graphics. Nearly always it is done by removing the old position and painting it in the new one. Here is a simple example of a 0 moving along a line:[code] for i := 1 to 60 do begin if i = 1 then GotoXY(60, 2); write(' '); { remove old location } else GotoXY(i-1, 2); write(' '); { remove old location } GotoXY(i, 2); write('0'); { write the new location } end;[/code]More advanced methods store the old location along with the new one, and update that with each step.

i shall try. that just adds a few more vars...one more question, code only works right now so that the entire screen refreshes at once, ei the ball doesn't move unless the paddles move or any other random key is pressed. how can this be fixed? something like adding a timed statement to the major loop? if so, how.

: i shall try. that just adds a few more vars...one more question, code only works right now so that the entire screen refreshes at once, ei the ball doesn't move unless the paddles move or any other random key is pressed. how can this be fixed? something like adding a timed statement to the major loop? if so, how.: Use the Keypressed() function to detect if there is a keypress. Then you can use ReadKey() to get the key-value.

[b][red]This message was edited by acidicburn at 2006-10-15 12:3:38[/red][/b][hr]: Use the Keypressed() function to detect if there is a keypress. Then you can use ReadKey() to get the key-value.:thx this should help a lot. So keypressed() detects if a key was pressed. so how would i use it in a program. if keypressed then? also, i don't know any assembly, i just started using pascal about a month ago.

: [b][red]This message was edited by acidicburn at 2006-10-15 12:3:38[/red][/b][hr]: : Use the Keypressed() function to detect if there is a keypress. Then you can use ReadKey() to get the key-value.: :thx this should help a lot. So keypressed() detects if a key was pressed. so how would i use it in a program. if keypressed then? also, i don't know any assembly, i just started using pascal about a month ago. : : : : Here's an example, which stops if you press enter:[code]var i: integer;begin i := 0; repeat GotoXY(1, 1); write(i); i := (i+1) mod 999; if Keypressed then begin if Readkey = #13 then Break; end; until i = 1000;end;[/code]