Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Moving Objects
#3
Code:
'okay! you will learn how to move a "sprite", realy a pixle

SCREEN 13  'generates the screen mode, you know this

x = 50  'sets locations of the pixle sprite
y = 50  'same

DO      'begin loop
press$ = INKEY$  'INKEY$ gets  info from the keyboard and puts it into the
                 'varriablr press$. press$ is not a speical variable,
                 'it can be changed to any leagal varriable name.
PSET (x, y), 15  'this sets a pixle at x,y with the color 15, white

IF press$ = "a" THEN x = x - 1: PSET (x + 1, y), 0
IF press$ = "d" THEN x = x + 1: PSET (x - 1, y), 0  'scroll to the bottum i'll explain it there
IF press$ = "w" THEN y = y - 1: PSET (x, y + 1), 0
IF press$ = "s" THEN y = y + 1: PSET (x, y - 1), 0
LOOP UNTIL press$ = CHR$(27) ' loops until the character 27 is pressed, the Esc key

'so if you press the "a" key the vaule of x,50, will be subtarcated by 1.
'then the new value of x is used to put the pixle in a new location. this
'is done when it loops back to the pset(x,y),15. before the new pixle is set
'a black pixle is placed at the location (x+1,y). this ereases the old pixle.
'lest'do some math. if press$=a then x=x-1, 49=50-1, then pset(x+1,y),0, which is
'49+1, is = 50, your old location, so a pixle is set at the old x,y value and
'when it loops back to the pset, a new pixle is placed. this works for going right
'the signs are just changed to make the locations the old one.
'
'now for y. y is weird beacuse you use y=y-1 to go up and y=y+1 to go down
'this is the way it is because the screen is set up like so
'
'(1,1)(2,1)...    so if you were at (2,2) and wanted to go down
'(1,2)(2,2)...    y=y+1, 3=2+1, up, y=y-1, 1=2-1
'(1,3)(2,3)...    get it?
'the ereasing is the same as x as it is for y
'so that's a really basic way of moving things
'the pixle will move off the screen because the are no boundries.
'to use the arrow keys you need to  know what their character numbers are.
'i'll try to find them.
Reply


Messages In This Thread
Moving Objects - by ckoo121 - 03-02-2004, 07:10 AM
Moving Objects - by whitetiger0990 - 03-02-2004, 07:21 AM
Moving Objects - by Diroga - 03-02-2004, 10:28 AM

Forum Jump:


Users browsing this thread: 1 Guest(s)