void Move_Crystal(void)
{
int count=0;
do{
count = 0;
crystal.y += 30;
} while(++count > 1000);
}
timed movement
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?
but if i use>
Sleep(1000);
the block does move a second a time, but keyboard movement responds very slowly.
Sleep(1000);
the block does move a second a time, but keyboard movement responds very slowly.
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.
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 ]
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 ]
-eldee;another space monkey;[ Forced Evolution Studios ]
alright, i have just changed to this>
keyboard still responded very slowly.
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:
-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
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
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 ~
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 ~
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement