Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

I need help with character movement...

Status
Not open for further replies.
Jun 6, 2001
1
US
I just started to program about 8 weeks ago.
I cant make my characters move with the keyboard.

I need help.
 
What?? "The world shrinks more and more with every new user online."
 
'CHARMOVE.BAS by Toshi Horie
'public domain, use as you wish.

moveleft$ = CHR$(0) + CHR$(&H4B)
moveright$ = CHR$(0) + CHR$(&H4D)
moveup$ = CHR$(0) + CHR$(&H48)
movedown$ = CHR$(0) + CHR$(&H50)
escape$ = CHR$(27)

x = 40: y = 10: oldx = x: oldy = y
SCREEN 0: WIDTH 80, 25: CLS
DO
' get a keystroke without waiting
a$ = INKEY$
' Update the character's position based on
' the arrow key pressed.
SELECT CASE a$
CASE moveleft$, "4"
x = x - 1
CASE moveright$, "6"
x = x + 1
CASE moveup$, "8"
y = y - 1
CASE movedown$, "2"
y = y + 1
CASE escape$
EXIT DO
CASE ELSE
' do nothing
END SELECT

'limit the character to move inside the screen
IF x < 1 THEN
x = 1
ELSEIF x > 80 THEN
x = 80
END IF
IF y < 1 THEN
y = 1
ELSEIF y > 25 THEN
y = 25
END IF

' erase the character from the old position
' instead of erasing, you can store the background,
' and restore it later for better graphics
LOCATE oldy, oldx: PRINT &quot; &quot;;

' draw it at the new position (color 30 is blinking yellow)
COLOR 30: LOCATE y, x: PRINT &quot;x&quot;;

' if you're in graphics mode (like SCREEN 13)
' then use PSET or PUT to draw the character

' remember the old position
oldy = y: oldx = x
LOOP
LOCATE 1, 1: PRINT &quot;The End&quot;

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top