sorry, it's me again :tongue:
i've another problem with my direct input stuff. i attached a part of the source and the exe. the problem is:

when i press a lot of keys one after the other in a short time for snake number1 (first), snake number 2 doesn't react on its keys correctly (when snake nr. 1 started to do that). but if snake number 2 does the stuff first, snake number 1 has no problems with input, but after about 2 seconds, snake 2 doesn't react correctly anymore. it's like, that snake nr.1 is "stronger" than snake nr. 2. i can't explain that to me. it should work as well!

to start the game, doubleclick it, wait about 4 seconds, then press "S". the game starts with two snakes. perhaps there is someone who can help you to test :tongue:

here is the readkeyboard loop:

snakemainproc proc uses ebx edi esi

invoke GetTickCount
mov ebx,eax
mov ecx,lasttick
sub eax,ecx
.if eax>=snakespeed
mov lasttick,ebx
invoke ClearScreen
invoke movesnake
invoke changedirection
.if foodflag==1
invoke placefood
invoke foodcrash
invoke snakecrash
.if eax==1
jmp @F
invoke wallcrash
.if eax==1
jmp @F
invoke DrawBitmap,foodx,foody,offset surface_food,offset bmp_food_info
mcall [dds_back],IDirectDrawSurface7_GetDC,addr backdc
invoke SelectObject, backdc, fonthandle
mov oldfont,eax
invoke SetTextColor,backdc,0FFFFFFh
invoke SetBkMode,backdc,TRANSPARENT
.if point1flag==1
invoke wsprintf,addr strbuffer,addr szformat,p1pointsint
invoke wsprintf,addr p1points,addr p1pointsformat,addr strbuffer
mov point1flag,0
invoke DrawMyText,addr p1points,addr pointsrectstruct
invoke SelectObject,backdc,oldfont

mcall [dds_back],IDirectDrawSurface7_ReleaseDC,backdc

invoke DrawWindowFrame
invoke UpdateScreen

invoke ReadKeyboard

.if keyboard_state[DIK_ESCAPE]

invoke DestroyWindow,hWnd

.elseif keyboard_state[DIK_UP]
.if snakeone[0].direction!=3
mov snakeone[0].direction,1

.elseif keyboard_state[DIK_DOWN]
.if snakeone[0].direction!=1
mov snakeone[0].direction,3

.elseif keyboard_state[DIK_LEFT]
.if snakeone[0].direction!=2
mov snakeone[0].direction,4

.elseif keyboard_state[DIK_RIGHT]
.if snakeone[0].direction!=4
mov snakeone[0].direction,2
.elseif keyboard_state[DIK_W]
.if snaketwo[0].direction!=3
mov snaketwo[0].direction,1

.elseif keyboard_state[DIK_S]
.if snaketwo[0].direction!=1
mov snaketwo[0].direction,3

.elseif keyboard_state[DIK_A]
.if snaketwo[0].direction!=2
mov snaketwo[0].direction,4

.elseif keyboard_state[DIK_D]
.if snaketwo[0].direction!=4
mov snaketwo[0].direction,2

.elseif keyboard_state[DIK_S]



snakemainproc endp

the keys of snake one are the arrow keys, and snake two has the other (W,A,S,D).

Posted on 2001-12-18 15:01:58 by NOP-erator
I presume you are getting all keys pressed reported, and so you can press 2 or more keys at once (this would make sense).

However you seem to only deal with one at a time in your loop.

You really need to do something like this:

.if escape
; Do escape
; All other cases are overridden by quitting!

; Now we must deal with player1
.if p1_up_key
; p1_direction = up
.elseif p1_down_key
; p1_direction = down
.elseif p1_left_key
; p1_direction = left
.elseif p1_right_key
; p1_direction = right
; No more checks for p1!

; But we must also check for player 2 as well.
.if p2_up_key
; p2_direction = up
.elseif p2_down_key
; p2_direction = down
.elseif p2_left_key
; p2_direction = left
.elseif p2_right_key
; p2_direction = right

At the moment, you will skip the rest of the "elseif" statements on finding the first key that is pressed, so player 2 cannot change course unless player1 allows them to....

Posted on 2001-12-18 18:46:35 by Mirno
thanks, you made it very clear for me. i'll test it in about 6 hours, i'm at school at the moment. but it was a logical fault again....


Posted on 2001-12-19 02:35:59 by NOP-erator

thank you, thank you, thank you, everything's cool!!! i'm so happy!! :alright:

Thanks Mirno :grin:

Posted on 2001-12-19 13:33:33 by NOP-erator