Advertisement

timed movement

Started by April 22, 2002 08:41 AM
6 comments, last by edwinnie 22 years, 4 months ago
i am in midst of making the tetris cloney. i am trying to make the block move 1 sec a time> but the block seemed to move very much faster, why?
  
void Move_Crystal(void)
{
    int count=0;

	do{
	   count = 0;
	   crystal.y += 30;
	} while(++count > 1000);
}  
but if i use>
Sleep(1000);

the block does move a second a time, but keyboard movement responds very slowly.
Advertisement
You could put a timer start on your blocks. This could hold the last time your blocked moved. Check it each time around the loop and if it is over 1000ms (1 second) then move the block. Sleep pauses the loop, so the keyboard is only checked each time the block is moved.
Don''t forget to update the ''last_move'' time holding variable though.. hehe.

I'm not the brightest something or other in a group or similar.~ me ~
dont use sleep();!
it halts your entire game loop for n milliseconds thus
decreasing the framerate dramatically .
check out a high performance counter.

-eldee
;another space monkey;
[ Forced Evolution Studios ]

::evolve::

-eldee;another space monkey;[ Forced Evolution Studios ]
alright, i have just changed to this>

  DWORD Move_Crystal(void){    DWORD start_count = GetTickCount();    	crystal.y += 30;	while(GetTickCount() - start_count < 1000);	return(GetTickCount());}  


keyboard still responded very slowly.
Try something like this:

  void Move_Crystal {    static DWORD count = 0;    count += GetTickCount();    while (count > 1000) {        count -= 1000;        crystal.y += 30;    }}  


-Neophyte

-----BEGIN GEEK CODE BLOCK-----
Version: 3.1
GED d- s:+ a- C++$ UL++ P++ L++ E W+ N+ o K? w !O M--(+) V-- PS+
PE Y+ PGP t-- 5++ X+ R(+) rv+(++) b+++ DI+ D(+) G e+>++ h r--> y+
----- END GEEK CODE BLOCK-----
geekcode.com
Advertisement
I meant check it''s time each game loop.. don''t throw it into a while until it''s move time is up.. that is similar to sleeping..


int game_main()
{
// blah
//...

if( (GetCurTime() - crystal.last_move_time) >= 1000 ){
move_crystal(); // this is only for vertical movement.. k
crystal.last_move_time = GetCurTime();
}

// continue with normal
// ex: get input, move crystal horizontally, rotate, exit to menu

return 0
}

Your code may not look like that (let''s hope not.. ;D) but there is the idea, each time you go through the game loop (for all things) check it''s time, then update when the crystal''s pause time is up..

This is what I meant.. I don''t know if it is the best way, but I like it. :D

~ me ~
I'm not the brightest something or other in a group or similar.~ me ~
thx! okie.

This topic is closed to new replies.

Advertisement