Home | Register new account | Login | Search for a message | Currently Online
Poster
sha-kai
Subject: Buggy
(Posted on 05/21/05 - 06:10:21 AM)
Member

sha_kai@earthlink.net

Turn smilies off

Hi,

I've been thinking of working on a rpg, and so set to work deciding what features I wanted to have. One of the features I decided to include was mobile NPC's, so I set about creating a simple bit of code to facilitate this, however, I'm having some trouble clearing up an anoying little bug that stops the NPC sprite from moving. Please see the code sample posted below.

---------------------------Sample--------------------------------------

DIM SHARED eraser%(100)
DIM SHARED player%(100)
DIM SHARED enemy%(100)

playerx% = 15
playery% = 2
ploldx% = playerx%
ploldy% = playery%
enemyx% = 15
enemyy% = 17
enoldx% = enemyx%
enoldy% = enemyy%
enwait% = 10000

SCREEN 13

LINE (0, 0)-(10, 10), 0, BF
GET (0, 0)-(10, 10), eraser%

'Player pic
LINE (0, 0)-(10, 10), 15, BF
GET (0, 0)-(10, 10), player%

'NPC pic
LINE (0, 0)-(10, 10), 6, BF
GET (0, 0)-(10, 10), enemy%

CLS

PUT (playerx% * 10, playery% * 10), player%, PSET
PUT (enemyx% * 10, enemyy% * 10), enemy%, PSET

RANDOMIZE TIMER

'move the player

DO

SELECT CASE INKEY$
CASE CHR$(0) + CHR$(77)
playerx% = playerx% + 1 'right
ploldx% = playerx% - 1
ploldy% = playery%
GOSUB placeplayer
CASE CHR$(0) + CHR$(75)
playerx% = playerx% - 1 'left
ploldx% = playerx% + 1
ploldy% = playery%
GOSUB placeplayer
CASE CHR$(0) + CHR$(80)
playery% = playery% + 1 'up
ploldy% = playery% - 1
ploldx% = playerx%
GOSUB placeplayer
CASE CHR$(0) + CHR$(72) 'down
playery% = playery% - 1
ploldy% = playery% + 1
ploldx% = playerx%
GOSUB placeplayer
CASE CHR$(27)
quit = 1
END SELECT

'move enemy

enemystep% = enemystep% + 1

IF enemystep% >= enwait% THEN
enemystep% = 0
enemydir% = INT(RND * 4)

SELECT CASE enemydir%
CASE 0
enemyx% = enemyx% + 1
enoldx% = enemyx% - 1
enoldy% = enemyy%
GOSUB placeenemy
CASE 1
enemyx% = enemyx% - 1
enoldx% = enemyx% + 1
enoldy% = enemyy%
GOSUB placeenemy
CASE 2
enemyy% = enemyy% + 1
enoldy% = enemyy% - 1
enoldx% = enemyx%
GOSUB placeenemy
CASE 3
enemyy% = enemyy% - 1
enoldy% = enemyy% + 1
enoldx% = enemyx%
GOSUB placeenemy
END SELECT

END IF

LOOP UNTIL quit = 1

END

placeplayer:
IF playerx% < 1 THEN playerx% = 1
IF playerx% > 30 THEN playerx% = 30
IF playery% < 1 THEN playery% = 1
IF playery% > 18 THEN playery% = 18
PUT (ploldx% * 10, ploldy% * 10), eraser%, PSET
PUT (playerx% * 10, playery% * 10), player%, PSET
'LOCATE 1, 1: PRINT playerx%, playery%
'LOCATE 2, 1: PRINT ploldx%, ploldy%
RETURN

placeenemy:
IF enemyx% < 1 THEN enemyx% = 1
IF enemyx% > 30 THEN enemyx% = 30
IF enemyy% < 1 THEN enemyy% = 1
IF enemyy% > 18 THEN enemyy% = 18
PUT (enoldx% * 10, enoldy% * 10), eraser%, PSET
PUT (enemyx% * 10, enemyy% * 10), enemy%, PSET
'LOCATE 4, 1: PRINT enemydir%
'LOCATE 5, 1: PRINT enemyx%, enemyy%
'LOCATE 6, 1: PRINT enoldx%, enoldy%
RETURN
---------------------------End Sample---------------------------------

Things seem to work fine if enwait% is set to 500 or less, but over that threshold the NPC sprite stops moving until there is some sort of input (ie: a key is pressed), or text output (ie: enabling any of the 'PRINT' commands).

If anyone has any ideas as to what is causing this, and suggestions for how to fix it, I'd appreciate hearing them.

Thanks,

Shannon

See the happy moron,<BR>He doesn't give a damn,<BR>I wish I were a moron,<BR>My God! Perhaps I am.

Replies to this message:


Post a reply:
Nickname: You are not logged in. If you have a registered account you should login before posting.
Subject:
Message: