Various kinds of movements

BlitzMax Forums/BlitzMax Beginners Area/Various kinds of movements

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

To simply move right,left, up, or down, you just have to tell your sprite to add or subtract from the x and y coordinates of the sprite.
For example:
(this isn't as long as it seems;it's mostly comments to make sure you understand it all the way.
if you already know how to do this, skip down to the next post on how to jump)

'****set graphics*****

Graphics 600,800,16 'fullscreen

'****variables****

Global x:Float=0 'x-coordinate variable
Global y:Float=0 'y-coordinate variable

'****start loop****

While Not KeyDown(key_escape) 'as long as you don't push the escape button, it will continue to make the loop

DrawRect x,y,10,10 'sprite = 10x10 square

'***input keys***
If KeyDown(key_left) 'if you want to say while key_left not down, you just say "keydown(key_left)=false

x:-1 'subtract one from x is now =to x; try changing the value of what you subtract x with.
EndIf

If KeyDown(key_right)

x:+5 'add to x; going right 5 pixels; notice the speed of going right compared to left
EndIf

If KeyDown(key_up)

y:-1 'this is going up 1; not down because if you look at the screen, 0,0 starts at the top left and is positive going down and right
EndIf

If KeyDown(key_down)

y:+5 'this is going 5 down; faster than going up
EndIf

If KeyHit(key_space) 'if you tap space; holding it down doesn't matter

x=300 'go to center;resetting what x and y equal
y=400
EndIf

Flip 'this is just drawing the program onto the screen: the rectangle
'cls 'take out the first appostraphe in order to uncomment the cls(clear screen) to see what happens
'******End loop******
Wend

'*******Done!!!!***********

Try it out with the "cls" behind the apostraphe first. Try to spell your name with it. Then take out the apostraphe and see what happens.