Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Moving Objects
#1
Yeah, I'm sorta new at this I know some of the basic stuff and basic graphics. I am trying to make a programs that is like a game but has no point. Anyway, what I need is how do you make an object on the screen move, and suppose if it is like a fighting game type thing, how would you make it shoot and shoot enemies and effect them?

Any help would be appreciated. Thanks...



CKoo
Reply
#2
you can detect keypresses and move accordingly like
Code:
SCREEN 13
x = 100
y = 100
DO
PRESS$ = INKEY$
SELECT CASE PRESS$
CASE "w": y = y - 1 'go up
CASE "s": y = y + 1 'go down
CASE "a": x = x - 1 'go left
CASE "d": x = x + 1 'go right
END SELECT
PSET (x, y), 4
LOOP
yea...
about the enemies and all
youll need an array
i.e.
q = your guy
e = enemy
Code:
_|_|_|_|_|_|_|_|_|_|_
_|_|_|_|_|_|_|_|_|_|_
_|_|e|_|_|_|q|_|_|_|_
_|_|_|_|_|_|_|_|_|_|_
_|_|_|_|_|_|_|_|_|_|_
if your guy shoots an arror ( ^ ) you just check the position of it with the enemy
Code:
_|_|_|_|_|_|_|_|_|_|_
_|_|_|_|_|_|_|_|_|_|_
_|_|e|^|_|_|q|_|_|_|_
_|_|_|_|_|_|_|_|_|_|_
_|_|_|_|_|_|_|_|_|_|_
next movement you would check like
Code:
IF enemyx = arrowx THEN
IF enemyy = arrowy THEN
'...
END IF
END IF

btw: welcome to the forums =P :king: :king: :king:
edit2: here
Code:
SCREEN 13
x = 100
y = 100
DO
PRESS$ = INKEY$
SELECT CASE PRESS$
CASE "w": y = y - 1 'go up
CASE "s": y = y + 1 'go down
CASE "a": x = x - 1 'go left
CASE "d": x = x + 1 'go right
END SELECT
IF oldx <> x OR oldy <> y THEN PSET (oldx, oldy), 0: PSET (x, y), 4
oldx = x: oldy = y
LOOP
[Image: sig.php]
Back by popular demand!
I will byte and nibble you bit by bit until nothing remains but crumbs.
Reply
#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


Forum Jump:


Users browsing this thread: 1 Guest(s)