Qbasicnews.com

Full Version: pacman movement
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
does anyone know how to use inkey$ for the directional arrows?
the easiest way is to put this

Code:
up$ = CHR$(0) + CHR$(72)
down$ = CHR$(0) + CHR$(80)
lft$ = CHR$(0) + CHR$(75)
rght$ = CHR$(0) + CHR$(77)

at the top of your code (after declares etc.)

Then you just have to do

Code:
IF INKEY$ = up$ THEN 'do all the stuff you want it to do when the up arrow is pressed

The INKEY$ command isn't very good though so doing

Quote:key$ = INKEY$

in the loop of your code then doing

then do

Code:
IF key$ = up$ THEN 'do all the stuff you want it to do when the up arrow is pressed

NOTE: In the IF's change the up$ to down$ for down and so on.
TheDarkJay:
Very good!

For capturing the INKEY$ content, the following has always worked very well for me:

K$="":WHILE K$="":K$=INKEY$:WEND
Quote:K$="":WHILE K$="":K$=INKEY$:WEND
That loops until you press a key. That means you can't have the program do other stuff. (Like having ghosts move or have pacman continue moving)
WhiteTiger0990:
Yes, I see what you are telling me. And, yes, my use was limited to programs that required user input to continue, not games such as you imply, so, my method would not work there. Thank you for noticing this limitation.
Code:
K$="":WHILE K$="":K$=INKEY$:WEND
is best for a pause in the game, i find it useful to create a function and call it pause

Code:
FUNCTION pause
WHILE INKEY$ = "": WEND
END FUNCTION

As far as i am aware there is no difference (or i cannot spot one) when just having it run like that, it is only when you have other things inbetween it when
Code:
k$ = INKEY$
is neccesary. And then you have to use
Code:
WHILE k$ = 'some other button, "q", CHR$(27) (escape) or " " (space bar) are common ones
thank you i will try ur ideas
Good pause, but here's another way:

Code:
DO: LOOP UNTIL INKEY$ > ""

If any button is pressed, it continues. Otherwise, you could change the "" to a CHR$(##) to mak a specific, like

Code:
DO: LOOP UNTIL INKEY$ > CHR$(13)

Then, it only goes if the Enter Key is hit.
Don't you mean this?

Quote:DO: LOOP UNTIL INKEY$ = CHR$(13)
Or will greater than work as well?