[phpBB Debug] PHP Warning: in file [ROOT]/phpbb/db/driver/mysqli.php on line 264: mysqli_fetch_assoc(): Couldn't fetch mysqli_result
[phpBB Debug] PHP Warning: in file [ROOT]/phpbb/db/driver/mysqli.php on line 326: mysqli_free_result(): Couldn't fetch mysqli_result
Pete's QBASIC Site Discuss QBasic, Freebasic, QB64 and more 2012-09-12T19:23:22-05:00 http://petesqbsite.com/phpBB3/app.php/feed/topic/3612 2012-09-12T19:23:22-05:00 2012-09-12T19:23:22-05:00 http://petesqbsite.com/phpBB3/viewtopic.php?p=22085#p22085 <![CDATA[Thanks]]> Statistics: Posted by Spivey38 — Wed Sep 12, 2012 7:23 pm


]]>
2012-09-12T08:17:17-05:00 2012-09-12T08:17:17-05:00 http://petesqbsite.com/phpBB3/viewtopic.php?p=22084#p22084 <![CDATA[Help structuring movement (RPG)]]> K$ = INKEY$

IF LEN(K$) THEN

'move enemy

'move sprite

END IF
LOOP

The sprite would move the key direction pressed. The enemy would move toward the current sprite position. If you want to be able to move diagonally use INP(96) scan codes:

http://qb64.net/wiki/index.php?title=Keyboard_scancodes

Code:

DECLARE SUB Delay (dlay!)DECLARE FUNCTION ScanKey% (code%)                   'NOT required in QB64CLSx = 40: px = xy = 20: py = yxx = 41: pxx = xxyy = 21: pyy = yyDO: Delay .05 ' program or game loop  COLOR 15  LOCATE 8, 14: PRINT "W A S D": LOCATE 8, 52: PRINT "ARROW PAD"  IF ScanKey%(17) THEN    LOCATE 2, 15: PRINT " UP "    IF y > 1 THEN y = y - 1  ELSE LOCATE 2, 15: PRINT "----" 'W key  END IF  IF ScanKey%(31) THEN    LOCATE 6, 15: PRINT "DOWN"    IF y < 25 THEN y = y + 1  ELSE LOCATE 6, 15: PRINT "----" 'S key  END IF  IF ScanKey%(30) THEN    LOCATE 4, 12: PRINT "LEFT"    IF x > 1 THEN x = x - 1  ELSE LOCATE 4, 12: PRINT "----" 'A key  END IF  IF ScanKey%(32) THEN    LOCATE 4, 18: PRINT "RIGHT"    IF x < 80 THEN x = x + 1  ELSE LOCATE 4, 18: PRINT "---- " 'D key  END IF  IF ScanKey%(72) THEN    LOCATE 2, 55: PRINT " UP "    IF yy > 1 THEN yy = yy - 1  ELSE LOCATE 2, 55: PRINT "----" 'arrow  END IF  IF ScanKey%(80) THEN    LOCATE 6, 55: PRINT "DOWN"    IF yy < 25 THEN yy = yy + 1  ELSE LOCATE 6, 55: PRINT "----" 'arrow  END IF  IF ScanKey%(75) THEN    LOCATE 4, 52: PRINT "LEFT"    IF xx > 1 THEN xx = xx - 1  ELSE LOCATE 4, 52: PRINT "----" 'arrow  END IF  IF ScanKey%(77) THEN    LOCATE 4, 58: PRINT "RIGHT"    IF xx < 80 THEN xx = xx + 1  ELSE LOCATE 4, 58: PRINT "---- " 'arrow  END IF  LOCATE py, px: PRINT SPACE$(1);  LOCATE pyy, pxx: PRINT SPACE$(1);  COLOR 10: LOCATE y, x: PRINT CHR$(1);  COLOR 12: LOCATE yy, xx: PRINT CHR$(2);  px = x: py = y: pxx = xx: pyy = yyLOOP UNTIL ScanKey%(1)zerocodes% = ScanKey%(0) 'reset all array values to zero for next part of programENDFUNCTION ScanKey% (scancode%)STATIC Ready%, keyflags%()IF NOT Ready% THEN REDIM keyflags%(0 TO 127): Ready% = -1i% = INP(&H60) 'read keyboard statesIF (i% AND 128) THEN keyflags%(i% XOR 128) = 0IF (i% AND 128) = 0 THEN keyflags%(i%) = -1K$ = INKEY$ 'clears key buffer to prevent beepsScanKey% = keyflags%(scancode%)IF scancode% = 0 THEN Ready% = 0 'allows program to reset all values to 0 with a REDIMEND FUNCTIONSUB Delay (dlay!)start! = TIMERDO WHILE start! + dlay! >= TIMER  IF start! > TIMER THEN start! = start! - 86400LOOPEND SUB

Statistics: Posted by burger2227 — Wed Sep 12, 2012 8:17 am


]]>
2012-09-11T17:20:32-05:00 2012-09-11T17:20:32-05:00 http://petesqbsite.com/phpBB3/viewtopic.php?p=22083#p22083 <![CDATA[Help structuring movement (RPG)]]>
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

Statistics: Posted by Spivey38 — Tue Sep 11, 2012 5:20 pm


]]>