Blitz Basics - Everything You Need to Know to Create Games With Blitz
2 posters
Blitz Basics - Everything You Need to Know to Create Games With Blitz
This thread will teach you the basics that you need to know to make games with blitz. Under the exception that you won't be learning sound or networking. Sorry guys
Print statments:
Prints the contents of the quotation marks
Variables:
The Global can also be local. This changes if the variable is local or global. 'myVariable' should be your variables name. Notice the '%' symbol. This means that the variable is an interger. If you add a '#' instead it's a decimal number and if you add a '$' than it is a string. (a string of text like "Hello World") Next we define our variables value by using 'myVariable = myValue' where myValue is the value of the variable.
Input String
notice how we can use variables instead of our quotes inside of the print statement. Same goes for numbers in the print statement and this is useful for HP displays and whatnot. The main purpose of this code however is to display the input$ function. Inside the quotation marks is your prompt to the user. Leave this blank "" if you don't want this to have a prompt show up.
Random Numbers
Before we begin let's start off by saying that computers aren't really random. They follow a certain algorithum. If we change this though we use this syntax:
the thing is if we just kept our number at one there would still be no randomness. But no matter what there is always more miliseconds in the day than before right? So if we put 'MilliSecs' than it will put the amount of MilliSeconds that have passed. (sense the beginning of time?) So than we just do this:
Ok so now we know that.
If Statements
If statements test a value. They work like this:
If condition is true, than run this code:
code goes here
else if that's not true but this is true than:
code goes here
else if that's not true but this is true than:
code goes here
else (if none of the above if/else if statments are true than run this code)
code goes here
endif (marks end of if statment)
this isn't real code but it makes things easier to understand. Note you can have as much 'else ifs' as you want and only one if at the start. The else must always go on the bottom. You don't have to have an 'else if' or 'else' but you must have an if. Let's look at a real if statement:
Please note that Blitz is case sensitive. If the user typed 'no' than it would not be equal to 'No'.
For loops
for loops let you repeat a lot of code without writing tons of code. Let's just look at this:
this program will print the numbers 1 through 10. To start you type 'For' than you type 'yourVariable%', name it what you want but it must be a number. than you make your 'to numberValue'. The numberValue is what value you want your variable to be. Once the variable reaches this value the for loop stops and the program continues. the 'step' shows how much the number increases each time the for loop code runs. if you don't add the 'step' the step will be set to '1' by default.
While loops
these loops continue until the variable is not equal to the condition given. It's a lot like plain english so here's some code:
notice that we can't create our variable when we create the loop. Also notice the 'Wend' or 'While End' closes the while loop. also notice I used a less than symbol. Here's a list of all the symbols you can use:
GUIs!
This function creates our GUI:
the color deft should be something like 8, 16, or 32. width and height are whatever you want. the mode is either 0, 1, 2, 3. Here's something I got from the blitz website that might be helpful regarding the 'mode'
0 : auto - windowed in debug, fullscreen in non-debug (this is the default)
1 : fullscreen mode (how most professional games are made, covering the ENTIRE screen)
2 : windowed mode (this part you can't resize it!)
3 : scaled window mode (this one you can resize it!)
here's something else useful:
you know how if you run notepad, up in the window bar it says 'Untitled - Notepad'. Well you want that for your game right? Well than just put a string variable inside that apptitle function and that's how it works!
Labels
labels are, well, sort of like bookmarks in your code. Say I used a label somewhere. well I can easily get back to that label with another function. This is really helpful and I always use labels for frames. Here is an example:
neat huh?
How to end fullscreen programs:
There's not X in the top right for fullscreen so use the 'End' command in one of your code and it ends the program nicely.
Graphics and Images
ok so here's how you do this. First you load the image:
than you have to draw the image:
Now your almost ready to make games... but here's another thing you should know:
SetBuffer BackBuffer()
and
SetBuffer FrontBuffer()
change your buffers for double buffering.
Flip
changes your buffers
Cls
clears the screen. Super helpful.
Scancodes and KeyInput
KeyInput works like this:
Scancodes are little numbers that you can use. Each scancode represents a key on the keyboard. '1' is the 'ESCKey'. There is a list of all scancodes on the blitz website and the blitz command reference that is inside your blitz IDE. (nifty right?) The demo version (most recent) has a scancode picker that lets you click and key and it gives you the scancode. (even niftier!)
Functions
the Graphics() function is a function that comes with Blitz. It takes 4 parameters, or variables that change what the function does. You can create your own functions. do this by this syntax:
you can make your functions anywhere, and you can call them anywhere too. Just don't call them inside themselves or else you get an infinate loop when you run the function! Here's how you add parameters:
So now you know the syntax. here's the logic.
This should work... if you know what the keys are which I don't lol.
Anyways that's all (thank god) sorry about my spelling if there was lot's of errors which I'm sure there was.
Print statments:
- Code:
Print "Your Text Goes Here"
Prints the contents of the quotation marks
Variables:
- Code:
Global myVariable%
myVariable = myValue
The Global can also be local. This changes if the variable is local or global. 'myVariable' should be your variables name. Notice the '%' symbol. This means that the variable is an interger. If you add a '#' instead it's a decimal number and if you add a '$' than it is a string. (a string of text like "Hello World") Next we define our variables value by using 'myVariable = myValue' where myValue is the value of the variable.
Input String
- Code:
Local string$
string = Input$("Prompt to the user goes here")
Print string
notice how we can use variables instead of our quotes inside of the print statement. Same goes for numbers in the print statement and this is useful for HP displays and whatnot. The main purpose of this code however is to display the input$ function. Inside the quotation marks is your prompt to the user. Leave this blank "" if you don't want this to have a prompt show up.
Random Numbers
Before we begin let's start off by saying that computers aren't really random. They follow a certain algorithum. If we change this though we use this syntax:
- Code:
SeedRnd(NumberOfSeed)
the thing is if we just kept our number at one there would still be no randomness. But no matter what there is always more miliseconds in the day than before right? So if we put 'MilliSecs' than it will put the amount of MilliSeconds that have passed. (sense the beginning of time?) So than we just do this:
- Code:
SeedRnd(MilliSecs)
;Now our numbers are truely random!
;Notice that adding a semicolon creates a comment which is a personal note ignored by the compiler
Global myInt% = Random() ;Either that or it's 'Rand()'
Ok so now we know that.
If Statements
If statements test a value. They work like this:
If condition is true, than run this code:
code goes here
else if that's not true but this is true than:
code goes here
else if that's not true but this is true than:
code goes here
else (if none of the above if/else if statments are true than run this code)
code goes here
endif (marks end of if statment)
this isn't real code but it makes things easier to understand. Note you can have as much 'else ifs' as you want and only one if at the start. The else must always go on the bottom. You don't have to have an 'else if' or 'else' but you must have an if. Let's look at a real if statement:
- Code:
Local Answer$ = Input$("Yes or no!")
If Answer = "Yes"
Print "YAY!!!!!!!!"
Else If Answer = "No"
Print "BOOOOO!!!"
Else
Print "Why didn't you say yes or no?"
EndIf
Please note that Blitz is case sensitive. If the user typed 'no' than it would not be equal to 'No'.
For loops
for loops let you repeat a lot of code without writing tons of code. Let's just look at this:
- Code:
For yourVariable% = 1 To 10 Step 1
Print yourVariable
Next ;the 'next means you are done with the for loop code and are continueing with your program
this program will print the numbers 1 through 10. To start you type 'For' than you type 'yourVariable%', name it what you want but it must be a number. than you make your 'to numberValue'. The numberValue is what value you want your variable to be. Once the variable reaches this value the for loop stops and the program continues. the 'step' shows how much the number increases each time the for loop code runs. if you don't add the 'step' the step will be set to '1' by default.
While loops
these loops continue until the variable is not equal to the condition given. It's a lot like plain english so here's some code:
- Code:
i% = 1
While i < 5
i = i + 1
Print i
Wend
notice that we can't create our variable when we create the loop. Also notice the 'Wend' or 'While End' closes the while loop. also notice I used a less than symbol. Here's a list of all the symbols you can use:
- Code:
= - Equal
< - Less Than
> - Greater than
<= - Less Than or Equal To
>= - Greater Than or Equal To
GUIs!
This function creates our GUI:
- Code:
Graphics(width, height, color deft, (optional)mode)
the color deft should be something like 8, 16, or 32. width and height are whatever you want. the mode is either 0, 1, 2, 3. Here's something I got from the blitz website that might be helpful regarding the 'mode'
0 : auto - windowed in debug, fullscreen in non-debug (this is the default)
1 : fullscreen mode (how most professional games are made, covering the ENTIRE screen)
2 : windowed mode (this part you can't resize it!)
3 : scaled window mode (this one you can resize it!)
here's something else useful:
- Code:
AppTitle("Untitled - Notepad")
you know how if you run notepad, up in the window bar it says 'Untitled - Notepad'. Well you want that for your game right? Well than just put a string variable inside that apptitle function and that's how it works!
Labels
labels are, well, sort of like bookmarks in your code. Say I used a label somewhere. well I can easily get back to that label with another function. This is really helpful and I always use labels for frames. Here is an example:
- Code:
.myLabelName
code
code
code
code
Goto myLabelName
neat huh?
How to end fullscreen programs:
There's not X in the top right for fullscreen so use the 'End' command in one of your code and it ends the program nicely.
Graphics and Images
ok so here's how you do this. First you load the image:
- Code:
Global myImage = LoadImage("C:\MyImageLocation\MyImage.bmp") ;use bitmaps!!!
than you have to draw the image:
- Code:
DrawImage(myImage, xvalue, yvalue)
Now your almost ready to make games... but here's another thing you should know:
SetBuffer BackBuffer()
and
SetBuffer FrontBuffer()
change your buffers for double buffering.
Flip
changes your buffers
Cls
clears the screen. Super helpful.
Scancodes and KeyInput
KeyInput works like this:
- Code:
If KeyDown(Scancode)
Code for moving player...
EndIf
Scancodes are little numbers that you can use. Each scancode represents a key on the keyboard. '1' is the 'ESCKey'. There is a list of all scancodes on the blitz website and the blitz command reference that is inside your blitz IDE. (nifty right?) The demo version (most recent) has a scancode picker that lets you click and key and it gives you the scancode. (even niftier!)
Functions
the Graphics() function is a function that comes with Blitz. It takes 4 parameters, or variables that change what the function does. You can create your own functions. do this by this syntax:
- Code:
Function myFunctionName()
Print "This is a function!"
End Function
myFunctionName() ;This line calls the function
you can make your functions anywhere, and you can call them anywhere too. Just don't call them inside themselves or else you get an infinate loop when you run the function! Here's how you add parameters:
- Code:
Function myFunc(parameter1%, parameter2#, parameter3$)
Print parameter1
Print parameter2
Print parameter3
End Function
myFunc(3, 3.5, "lolololol :D") ;notice we seperate parameters with commas!
So now you know the syntax. here's the logic.
- Code:
Graphics(800, 600, 16, 2)
AppTitle("Example Game")
Global x% = 25
Global y% = 25
Global LeftKey% = 45 ;fake scancodes I don't remember what they really are....
Global RightKey% = 56
Global ship$ = "<-*->"
;we will use the 'text' function. It's like the print function but it allows you to print with different X/Y values
.gameloop
Text(x, y, ship) ;we use ship string as the value
Flip ;good for making game smoother
Cls ;refresh the screen
TestInput() ;calling on a function
Goto gameloop
Function TestInput()
If KeyDown(LeftKey) ;notice we use the variables instead of numbers....
x = x - 3
EndIf
If KeyDown(RightKey)
x = x + 3
EndIf
End Function
This should work... if you know what the keys are which I don't lol.
Anyways that's all (thank god) sorry about my spelling if there was lot's of errors which I'm sure there was.
Nighthawk0973- Moderator
- Posts : 307
Join date : 2011-07-20
Age : 25
Location : In Front of My Computer
Re: Blitz Basics - Everything You Need to Know to Create Games With Blitz
Why not?Nighthawk0973 wrote:...you won't be learning sound or networking. Sorry guys
_________
Nice tutorial!
Re: Blitz Basics - Everything You Need to Know to Create Games With Blitz
Just because I didn't plan to put these concepts in the tutorial.
Nighthawk0973- Moderator
- Posts : 307
Join date : 2011-07-20
Age : 25
Location : In Front of My Computer
Re: Blitz Basics - Everything You Need to Know to Create Games With Blitz
Will you later?Nighthawk0973 wrote:Just because I didn't plan to put these concepts in the tutorial.
Similar topics
» Snowfire Games Hireing Artists
» An In Deft Guide to creating custom GUIs for your games
» What is Blitz?
» Blitz/Blitz3D
» Let's Collaborate - Blitz MMORPG
» An In Deft Guide to creating custom GUIs for your games
» What is Blitz?
» Blitz/Blitz3D
» Let's Collaborate - Blitz MMORPG
Permissions in this forum:
You cannot reply to topics in this forum
|
|