Help structuring movement (RPG)
Posted: Tue Sep 11, 2012 5:20 pm
Hello! I am an beginner level coder using Qbasic. I am currently attemping to make a RPG for my young son so when he is old enough to read I should have something playable hehe. It is a very simple RPG using PUT/GET tiles, characters etc. The problem i have is animating the enemies on the screen. My code is set up like this...
Program looks for a keyboard action
If none, it moves the enemy a tile in a direction
Repeat
You can probably see the problem i am having. It scans the keyboard for input and moves the enemy about a thousand times per second! I can put a delay in (for d=1 to 1000000:next d). It will slow everything down, but it wont always catch a keyboard input if it is pressed during the delay part.
The code for keyboard commands (move/inventory/gear etc) i got from another Qbasic site and reads...
DO
press$=INKEY$
IF press$="I" then inventory '(subroutine)
IF press$="s" then savegame '(subroutine)
<ENEMY>
LOOP UNTIL press=CHR$(27) 'loops forever until i press escape
I have the enemy movement code sandwiched in the loop which makes it go way to fast. If i put that chunk of code outside the loop, the enemy never moves because every action is contained in the loop. Not sure what to do here. If you need an example of what i want, think the original Legend of Zelda =)
Thanks alot!
-Bryan
Program looks for a keyboard action
If none, it moves the enemy a tile in a direction
Repeat
You can probably see the problem i am having. It scans the keyboard for input and moves the enemy about a thousand times per second! I can put a delay in (for d=1 to 1000000:next d). It will slow everything down, but it wont always catch a keyboard input if it is pressed during the delay part.
The code for keyboard commands (move/inventory/gear etc) i got from another Qbasic site and reads...
DO
press$=INKEY$
IF press$="I" then inventory '(subroutine)
IF press$="s" then savegame '(subroutine)
<ENEMY>
LOOP UNTIL press=CHR$(27) 'loops forever until i press escape
I have the enemy movement code sandwiched in the loop which makes it go way to fast. If i put that chunk of code outside the loop, the enemy never moves because every action is contained in the loop. Not sure what to do here. If you need an example of what i want, think the original Legend of Zelda =)
Thanks alot!
-Bryan