Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • 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.

Students Click Here

I need help with character movement...

I need help with character movement...

I need help with character movement...

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...


"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
    ' get a keystroke without waiting
    a$ = INKEY$
    ' Update the character's position based on
    ' the arrow key pressed.
        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

    '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
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.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

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:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close