hi,

as perhaps some of you know, i'm rewriting my snake game into directx. direct input and all the stuff works great. to slow down the snake, i use "Sleep" at the end of the snake moving procedure:



snakemainproc proc

invoke ClearScreen
invoke movesnake
invoke changedirection
.if foodflag==1
; invoke placefood
.endif
invoke DrawWindowFrame
invoke ReadKeyboard
.if keyboard_state[DIK_ESCAPE]
invoke DestroyWindow,hWnd
.elseif keyboard_state[DIK_UP]
mov snakeone[0].direction,1
.elseif keyboard_state[DIK_DOWN]
mov snakeone[0].direction,3
.elseif keyboard_state[DIK_LEFT]
mov snakeone[0].direction,4
.elseif keyboard_state[DIK_RIGHT]
mov snakeone[0].direction,2
.elseif keyboard_state[DIK_S]
.endif
invoke Sleep,50
invoke UpdateScreen

ret
snakemainproc endp




but it seems that i don't get every keypress....and this is very important! would it be better to read the keyboard in an extra thread that runs independent from the game? is this even possible? cause i think, that this is because of that "Sleep", it seems, that even directinput doesn't get input during that time. perhaps there is a better methode to slow down my snake, and i don't need any threads? but then it is important, that i can change the game speed during gameplay....
but if i have to use threads, how to create one? i don't know anything about that......

thanks.

nop
Posted on 2001-12-16 05:04:32 by NOP-erator
(this thread has been edited by me since my last visit)
Posted on 2001-12-16 09:43:47 by NOP-erator
hey,

come on, please help me, i can't continue without solving that....

the main reason why i used sleep is, to slow down the snake, otherwise it would move incredibly fast! i tested and tested, and i'm sure that this sleep doesn't allow me to read the keyboard. but how to do it else?

looking forward to get an answer....

thanks,

nop
Posted on 2001-12-16 14:46:40 by NOP-erator
hiiii
i never coded a game but i think you should use SetTimer on your proc

and get the pressed keys from your main window proc

hope this helps ,.

bye

eko:alright:
Posted on 2001-12-16 16:07:03 by eko
.data?
snakespeed dd ?
.code

snakemainproc proc
Local LastTick : dword

invoke GetTickCount
sub eax,LastTick
.if eax>snakespeed
add LastTick,eax
invoke ClearScreen
invoke movesnake
invoke changedirection
.if foodflag==1
; invoke placefood
.endif
invoke DrawWindowFrame
.endif
invoke ReadKeyboard
.if keyboard_state
invoke DestroyWindow,hWnd
.elseif keyboard_state
mov snakeone[0].direction,1
.elseif keyboard_state
mov snakeone[0].direction,3
.elseif keyboard_state
mov snakeone[0].direction,4
.elseif keyboard_state
mov snakeone[0].direction,2
.elseif keyboard_state
.endif
invoke Sleep,0
invoke UpdateScreen

ret
snakemainproc endp


Try this method (read keys continously but update snake only if some time elapsed since last update)
Posted on 2001-12-16 18:59:48 by kamilh
i'm not sure if i understood the source well, but i think that i got the point. shouldn't be lasttick a global variable? i mean, everytime the program lefts the procedure, lasttick is set to zero, isn't it? and then it wouldn't make sense to add eax to lasttick. but anyways, when always the difference between gettickcount and lasttick is added to lasttick, wouldn't the number be to big after some time?

but ok, after i checked this difference, i just test if this difference is bigger/smaller than snakespeed, and if yes/no i move/don't move the snake, but always read the keyboard, right?


thanks!

nop
Posted on 2001-12-17 05:52:37 by NOP-erator
sorry nop , i thought snakemainproc was your thread proc..
if not ; yes, lasttick should be global..

lasttick is not added to lasttick,
sub eax,lasttick
add lasttick,eax
samething with push eax,pop eax (lasttick is set to last value read from gettickcount)

anyway your conclusion is correct..
Posted on 2001-12-17 12:15:20 by kamilh
are you sure? i mean, there is lasstick substracted from eax (Gettickcount). so in lasttick there is the number 3000 for example. and after the subtraction there is 100 in eax. so if you add this 100 to 3000, and that in every loop, it can't work.....

shouldn't it be mov lasttick,eax?????

bye
Posted on 2001-12-17 13:11:38 by NOP-erator
anyways, i used mov now, and it works great! the loop is fast, i get all the keyboard input,......just great! thanks!

nop
Posted on 2001-12-17 14:21:41 by NOP-erator