My head hurts. Please help!
Here is my problem.
I have writen a game that works the same way as pac man (yet another clone)!
As the main character moves along , I store the last key press and use it again if no key is pressed. This avoids the player tapping keys all the time.
The trouble is that in most pac man clones (good ones atleast) the player can press a key in advance of where they want to move - so the player goes in along a wall and presses a key that will move him in to a new path as soon as a break in the wall is found.
Here is an example of my code (simple text gfx)
CLS
'FIRST OFF, SET UP FOUR WALLS
PRINT "#######################################################################"
PRINT "# #"
FOR COUNT = 1 TO 20
PRINT "# # # #"
NEXT COUNT
PRINT "#######################################################################"
'SOMETHING TO BUMP INTO
LOCATE 13, 26: PRINT "##########"
LOCATE 14, 26: PRINT "##########"
Y = 2: X = 2 'SET PLAYER START LOCATION
LOCATE Y, X: PRINT "@";
DO
KEYB$ = INKEY$ 'GET A KEY PRESS
IF KEYB$ = "" THEN KEYB$ = OLD.KEY$ 'IF NO KEY PRESS USE OLD KEY PRESS
IF KEYB$ = CHR$(0) + "H" THEN GOSUB UP
IF KEYB$ = CHR$(0) + "P" THEN GOSUB DOWN
IF KEYB$ = CHR$(0) + "K" THEN GOSUB LEFT
IF KEYB$ = CHR$(0) + "M" THEN GOSUB RIGHT
IF KEYB$ = CHR$(27) THEN END ' EXIT
OLD.KEY$ = KEYB$ ' STORE OLD KEY
FOR DELAY! = 0 TO 10000: NEXT DELAY! ' SLOW THINGS DOWN!
LOOP
UP:
IF SCREEN(Y - 1, X) <> 32 THEN RETURN ' LOOK UP - IF ITS A WALL DONT MOVE
LOCATE Y, X: PRINT " "; ' CLEAR OLD LOCATION
Y = Y - 1: LOCATE Y, X: PRINT "@"; ' SET NEW LOCATION
RETURN
DOWN:
IF SCREEN(Y + 1, X) <> 32 THEN RETURN
LOCATE Y, X: PRINT " ";
Y = Y + 1: LOCATE Y, X: PRINT "@";
RETURN
LEFT:
IF SCREEN(Y, X - 1) <> 32 THEN RETURN
LOCATE Y, X: PRINT " ";
X = X - 1: LOCATE Y, X: PRINT "@";
RETURN
RIGHT:
IF SCREEN(Y, X + 1) <> 32 THEN RETURN
LOCATE Y, X: PRINT " ";
X = X + 1: LOCATE Y, X: PRINT "@";
RETURN
Can someone add to this code to perform the advance key presses and moves?
Thanx for any help!
Curly
Here is my problem.
I have writen a game that works the same way as pac man (yet another clone)!
As the main character moves along , I store the last key press and use it again if no key is pressed. This avoids the player tapping keys all the time.
The trouble is that in most pac man clones (good ones atleast) the player can press a key in advance of where they want to move - so the player goes in along a wall and presses a key that will move him in to a new path as soon as a break in the wall is found.
Here is an example of my code (simple text gfx)
CLS
'FIRST OFF, SET UP FOUR WALLS
PRINT "#######################################################################"
PRINT "# #"
FOR COUNT = 1 TO 20
PRINT "# # # #"
NEXT COUNT
PRINT "#######################################################################"
'SOMETHING TO BUMP INTO
LOCATE 13, 26: PRINT "##########"
LOCATE 14, 26: PRINT "##########"
Y = 2: X = 2 'SET PLAYER START LOCATION
LOCATE Y, X: PRINT "@";
DO
KEYB$ = INKEY$ 'GET A KEY PRESS
IF KEYB$ = "" THEN KEYB$ = OLD.KEY$ 'IF NO KEY PRESS USE OLD KEY PRESS
IF KEYB$ = CHR$(0) + "H" THEN GOSUB UP
IF KEYB$ = CHR$(0) + "P" THEN GOSUB DOWN
IF KEYB$ = CHR$(0) + "K" THEN GOSUB LEFT
IF KEYB$ = CHR$(0) + "M" THEN GOSUB RIGHT
IF KEYB$ = CHR$(27) THEN END ' EXIT
OLD.KEY$ = KEYB$ ' STORE OLD KEY
FOR DELAY! = 0 TO 10000: NEXT DELAY! ' SLOW THINGS DOWN!
LOOP
UP:
IF SCREEN(Y - 1, X) <> 32 THEN RETURN ' LOOK UP - IF ITS A WALL DONT MOVE
LOCATE Y, X: PRINT " "; ' CLEAR OLD LOCATION
Y = Y - 1: LOCATE Y, X: PRINT "@"; ' SET NEW LOCATION
RETURN
DOWN:
IF SCREEN(Y + 1, X) <> 32 THEN RETURN
LOCATE Y, X: PRINT " ";
Y = Y + 1: LOCATE Y, X: PRINT "@";
RETURN
LEFT:
IF SCREEN(Y, X - 1) <> 32 THEN RETURN
LOCATE Y, X: PRINT " ";
X = X - 1: LOCATE Y, X: PRINT "@";
RETURN
RIGHT:
IF SCREEN(Y, X + 1) <> 32 THEN RETURN
LOCATE Y, X: PRINT " ";
X = X + 1: LOCATE Y, X: PRINT "@";
RETURN
Can someone add to this code to perform the advance key presses and moves?
Thanx for any help!
Curly