Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
pacman movement
#1
does anyone know how to use inkey$ for the directional arrows?
ife is Short Lets pick on it.
Reply
#2
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.
url=http://www.sloganizer.net/en/][Image: style4,TheDarkJay.png][/url]
Reply
#3
TheDarkJay:
Very good!

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

K$="":WHILE K$="":K$=INKEY$:WEND
Ralph, using QuickBASIC 4.5 and Windows XP Home Edition and Service Pack 2, with HP LaserJet 4L printer.
Reply
#4
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)
[Image: sig.php]
Back by popular demand!
I will byte and nibble you bit by bit until nothing remains but crumbs.
Reply
#5
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.
Ralph, using QuickBASIC 4.5 and Windows XP Home Edition and Service Pack 2, with HP LaserJet 4L printer.
Reply
#6
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
url=http://www.sloganizer.net/en/][Image: style4,TheDarkJay.png][/url]
Reply
#7
thank you i will try ur ideas
ife is Short Lets pick on it.
Reply
#8
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.
Reply
#9
Don't you mean this?

Quote:DO: LOOP UNTIL INKEY$ = CHR$(13)
Or will greater than work as well?
url=http://www.sloganizer.net/en/][Image: style4,TheDarkJay.png][/url]
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)