×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
• Talk With Other Members
• Be Notified Of Responses
• Keyword Search
Favorite Forums
• Automated Signatures
• Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

#### Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

# I need help with character movement...

## I need help with character movement...

(OP)
I just started to program about 8 weeks ago.
I cant make my characters move with the keyboard.

I need help.

### RE: I need help with character movement...

What??

"The world shrinks more and more with every new user online."

### RE: I need help with character movement...

'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 " ";

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

' 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 "The End"

#### Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

#### Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Close Box

# Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

• Talk To Other Members
• Notification Of Responses To Questions
• Favorite Forums One Click Access
• Keyword Search Of All Posts, And More...

Register now while it's still free!