Main Menu

The very basics: Vol 1

Started by Draco9898, July 06, 2005, 10:33:47 PM

Previous topic - Next topic

Draco9898

 
 This tutorial is here to get you up to speed on where to start on making your programs...

All Programs go what we'd like to call an indefinite (or definite, should you choose) loops...Inside these loops is all the code for the stuff you'd like to happen on the screen, such as updating the screen so you can actually see something happening on it (Sync) to the most complex algorithims for controlling your game world (but we're only doing simple stuff here so don't run away yet).

 Perhaps the simplist program you can make is something which just throws text onto the screen, that's it. Now I know your saying "I WANT TA Make PONG!", But first of all do you know what kind of math it wil take to move the ball around the screen? Do you know what types of data you'd like to use to store the ball's various information such as it's positions on the screen, how fast it's going, in what direction it's going? An absolute begginner is not quite ready for pong!

Here's a simple program that displays "Hello world" in the upper-left corner of the sceen, in the position of 10,10.

PlayBASIC Code: [Select]
Do
Text 10,10,"Hello world"
Sync
Loop



Let's run through what each command means:

*Do : This commands marks the beginning of a infinite loop

*Text 10,10,"Hello World" : This is the command putting the text on the screen obviously. This command demands you use the correct syntax (Order of information given to the command) for it to work properly, The syntax is X position (10), Y position (10), Then a string ("Hello World"). Strings are always chunks of text or characters and are always enclosed by hypens or the " symbols.

*Sync : This command refreshes the backbuffer and your screen, without it you will not notice ANYTHING changing o the screen and your program will lock up with a serious error.

*Loop: This is the end of our infinite loop, after the computer get's to this space in your program it goes back to the beggining of the loop to access commands.


Now why don't we do something interesting, we'll make a box appear in random places on the screen:

PlayBASIC Code: [Select]
Do
Cls 0
Box1=Rnd(600): Box2=Rnd(800)
Box Box1,Box2,Box1+10,Box2+10,1
Sync
Loop



Right now you might be saying: "Oh noes, Draco! My brain is going to explode, it looks way too hard!"
But let's break it down you you can understand,

*Cls 0: This command will clear the screen so everything doesn't get "stuck" on, try taking this command out and you'll see what I mean, the syntax for this commands requires a color number, we just use zero, which is pure black.

*Box1=Rnd(600): Box2=Rnd(800) : Now this looks confusing, but all we're doing here is using varibles to store some nu8mbers to make our job easier, these varibles are Box1, and Box2. Box1 is storing a random number (Rnd()) between 0 and 600, Box2 is storing a random number between 0 and 800.

*Rnd() : This command will generate a random number between 0 and the number you put into the brackets.

*Box : The syntax for Box is Xposition,Yposition,xPosition 2, Yposition 2, Style. Now why in the world do you have to put in four co-ordenents? Because it's the four sides of the box, that's why. We're plugging in our varibles from before into this command so we don't have to type the same number junk over and over again.
*Then we have our Sync and loop, that's it.

 So now you know how to do some pretty simple stuff, but you have to start somewhere. Now try some stuff on your own, how about a bunch of text?
A bunch of different boxes?

Remember there is also the help file in playbasic AND if you are wondering about a command you typed in you can put your mouse over a command and press F1 to see the correct syntax.


That's all for now.






DualCore Intel Core 2 processor @ 2.3 ghz, Geforce 8600 GT (latest forceware drivers), 2 gigs of ram, WIN XP home edition sp2, FireFox 2.

"You'll no doubt be horrified to discover that PlayBasic is a Programming Language." -Kevin