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