tetris - jerky and unresponsive
I've been kindof busy, but I got the basic tetris program I had last week working pretty good, added preview, score ect., could do alot more but its all working pretty good except one more basic problem. It's jerky. I made a better display function, so it doesn't flicker, but it has a tendency to be unresponsive. Most of the program is spent in a loop that checks for a keypress, then checks the time to see if it's ready to move down yet, then loops back again.
Code:
while (end - start < timeitvl) //pause between blocks falling
{
if (kbhit())
{
int kp=getkeypress();
if (kp !=-1 && canmove(board,block,blockx,blocky,kp))
{
if (kp==1){blocky++;}
else if(kp==2){blockx--;}
else if(kp==3){blockx++;}
else if (kp==4){rotate_array(block);}
insertblock(board,block);
display(board,0);
}
}
end=double(clock())/1000;
}
I suspect thats what causes the problem, but I don't know how else to do it. The block always moves down on que, it just doesn't always move left/right immediately when pushing a button. So..., yea please take a look and give me any ideas.