hi,

i'm working on my snakegame and implemented the feature to go through walls.. (if you go left till you reach the left wall you appear at the right).. but there's a bug somewhere that appears irregularly. when i try to change the direction by 180? just at the moment when I'm touching the wall, the head very often is moved two fields down, example:

normal snake:
========?>

snake after the bug:


=====
=?>


ok, now i tried to comment out some code that could cause this bug and reached the code that checks for a crash with the level borders (not the wall borders, the level borders). after commenting the code out, that bug didn't appear, yet! but the code's so simple and (hopefully) doesn't affect any values or coordinates (of the snake):



;---------------------------------------
;now check if the snakehead touched the level borders
;---------------------------------------
.if levelerror==0
mov eax,sn1hcoor.y
mov ecx,49
mul ecx
add eax,sn1hcoor.x
.if leveldata[eax]==1
mov gameruns,0
mov gameoverf,1
invoke RtlZeroMemory,addr gameovermsg,50
invoke lstrcpy,addr gameovermsg,addr gameover00
mov eax,1
ret
.endif
.if playernr==2
mov eax,sn2hcoor.y
mov ecx,49
mul ecx
add eax,sn2hcoor.x
.if leveldata[eax]==1
mov gameruns,0
mov gameoverf,1
invoke RtlZeroMemory,addr gameovermsg,50
invoke lstrcpy,addr gameovermsg,addr gameover01
mov eax,1
ret
.endif
.endif
.endif



has anybody got an idea?

bye
Posted on 2003-01-22 09:37:46 by NOP-erator
perhaps this code can be optimized somehow? i dunno..
i did a lot of tests now, if this code is really the one that produces the bug.. but when commenting it out, it just didn'T appear anymore, no matter how often i tried..

:/

bye
Posted on 2003-01-22 10:22:13 by NOP-erator
ok.. i know what the problem was..
although the snake did NOT hit the level borders, it could happen that eax is 1 at the very end of the procedure. my program then jumps over some code that does calculation of the snake..the solution was to add "xor eax,eax" before the last "ret"..

thanks for reading :)

bye
Posted on 2003-01-22 10:37:46 by NOP-erator
Always nice to see issues resolve themself by the author before
anyone have had the chance to reply! :alright:
Posted on 2003-01-22 11:36:54 by natas