Post by Azan on Mar 16, 2005 16:38:56 GMT -5
Simple Graphics
In this tutorial you will learn how to ...
~ Set graphics
~ Add movement to graphics
Ok now we will be taking all of our past stuff we learned and actualy be turning it into graphics (graphics may seem intimidating at first but its actualy really easy). Ok for our first line in our program we will be setting up our global variables.
Global x=200
Global y=200
Global playerspeed=2
x and y are the coordinate in which our player will be placed (For bliz the upper left most part of the screen is 0,0 and it is added as it goes down and to the right, and playerspeed is the speed at which our player will move, now to actualy create the screen.
Graphics 640,480
this is basicaly setting up our window size, now we need to set buffers
SetBuffer BackBuffer()
(this is hard to explane so bear with me on this) Now to start our programs while loop.
While Not KeyHit(1)
and in the loop put this (flip flips the buffers from front to back and cls clears the previos buffers)
Flip
Cls
now we arent going to close the loop just yet, so lets start on our functions
Function updateplayer()
Rect x,y,15,15
End Function
is what this does is create a rectangle at the variables we assigned (in this case x and y) and 15,15 is the size of the rectangle, now to make the functions that acutaly move the player
Function up()
y=y-playerspeed
End Function
this is basicaly subtracting playerspeed from the current y coordinate (making it go up on the screen) and now the rest of them (there is no need to explane these)
Function down()
y=y+playerspeed
End Function
Function le()
x=x-playerspeed
End Function
Function ri()
x=x+playerspeed
End Function
now we have to go back to our while loop and add this below cls
updateplayer()
If KeyDown(200) up()
If KeyDown(208) down()
If KeyDown(203) le()
If KeyDown(205) ri()
Wend
is what this is doing is saying that as long as the key that is specified is held down it will loop that function (note you can use keyhit instead but then you would have to tap the keys) the numbers in the () are scan codes (each key on a keyboard has an id, this is it) a list of scan codes can be found by opening blitz and in the intro menu go to command reference then to scancodes so now our final program should look like this
Global x=200
Global y=200
Global playerspeed=2
Graphics 640,480
SetBuffer BackBuffer()
While Not KeyHit(1)
Flip
Cls
updateplayer()
If KeyDown(200) up()
If KeyDown(208) down()
If KeyDown(203) le()
If KeyDown(205) ri()
Wend
Function updateplayer()
Rect x,y,15,15
End Function
Function up()
y=y-playerspeed
End Function
Function down()
y=y+playerspeed
End Function
Function le()
x=x-playerspeed
End Function
Function ri()
x=x+playerspeed
End Function
now if you run it you should be able to control the box using the arrow keys (now to get a better idea of buffers remove the cls and run the program)
If you have any questions regarding what was discussed in this tutorial please post it in this thread.
Copyright: This document may not be posted anywhere else but ragnarokcom.proboards33.com with out the authors consent, by posting anywhere else with out the authors consent you are agreeing to give me your soul mwahahaha (but feel free to post links to this site/tutorial on other sites).