### Author Topic: Blitz 2D Beginners Tutorials.  (Read 1350 times)

0 Members and 1 Guest are viewing this topic.

#### Shockwave

• good/evil
• Founder Member
• Posts: 17297
• Karma: 489
• evil/good
##### Blitz 2D Beginners Tutorials.
« on: October 29, 2006 »

I will be making some tutorials so that people can learn to code and posting them here, here is the first, it's very basic stuff (no pun intended) but I know that it can be hard for some people to get into programming so hopefully these will help.

All spam and one word replies will be deleted from this topic, please only post questions pertaining to the code or your own attempts. Thanks.

This tutorial will assume that you have a basic knowledge of a few things (not many, don't worry!)

It will assume that you know how to open a graphics screen.
It will assume that you understand how a program is executed (Ie. line by line) and it will assume that
you know about While Wend loops.

Some of the methods in my tutorials are not the best way of doing things, I am usually aware of this but there are usually good reasons for my ways...

[/color]

First thing's first, we are going to learn about integer variables.. Variables are really important no matter what language you choose to use, you'll need them.
Try and imagine a variable as an envelope, inside this invelope is a bit of paper which something can be written on.
So if you had 100 apples and you wanted to remember how many apples you had, you could write the number 100 on the bit of paper, and then put it into the envelope.
You might write something like "Apples" on the front of the envelope so instead of having to count your apples each time you wanted to know how many you had, you could just look inside the envelope.

What's the point you might ask?

Well, the key is that variables are nearly always just that.!! Ie. Variable. You can change what's stored inside that envelope.

This time we are looking at integers, integers are basically whole numbers with no decimal point.

1.203 Would not be an integer, that is a floating point number.

1 Would be an integer because it has no decimal point.

It is not possible to store a floating point number inside an integer variable. For the time being though, we know that integers store whole numbers.

Let's try a listing.

Remember that anything after a semi-colon ( ; ) in Blitz is treated as a comment and is ignored by the computer.
You should use as many comments as possible when you are programming, it will help you understand what's going on.

Code: [Select]
`;=============================; Simple Integer Variable demo; By Shockwave................;=============================;==================================; Open Screen;; X size, Y size , Bit depth , mode;==================================Graphics 640,480,32,2;==================================================================; Create a variable called "apples" and store the number 100 in it.;==================================================================APPLES = 100;==================================================================; Print the contents of variable name "apples" to the screen;==================================================================Print APPLES;==================================================================; Wait for Keypress.;==================================================================While Not KeyDown(1)Wend`
Seemingly, all this listing does is to print the number 100 in a screen and wait for a key to be pressed.
Let's say that you gave 10 of your apples away.. Hopefully this should be pretty easy for you to follow...

Code: [Select]
`;=============================; Simple Integer Variable demo; By Shockwave................;=============================;==================================; Open Screen;; X size, Y size , Bit depth , mode;==================================Graphics 640,480,32,2;==================================================================; Create a variable called "apples" and store the number 100 in it.;==================================================================APPLES = 100GIVEN_AWAY = 10;==================================================================; Print the contents of variable name "apples" to the screen;==================================================================Print "YOU HAD " + APPLES;==================================================================; Print the contents of variable name "GIVEN_AWAY" to the screen;==================================================================Print "BUT YOU GAVE AWAY " + GIVEN_AWAY;==================================================================; Subtract Given_Away from Apples;==================================================================APPLES=APPLES - GIVEN_AWAY;==================================================================; Print the contents of variable name "apples" to the screen;==================================================================Print "SO YOU HAVE NOW GOT " + APPLES;==================================================================; Wait for Keypress.;==================================================================While Not KeyDown(1)Wend`
So as you can see, you can change the contents of those envelopes.
You should be able to move t hings around the screen quite easily now, so let's have a go.
This assumes that you know these commands;

Text
Vwait
Cls

Code: [Select]
`;=============================; Simple Integer Variable demo; By Shockwave................;=============================;==================================; Open Screen;; X size, Y size , Bit depth , mode;==================================Graphics 640,480,32,2;==================================================================; Create a variable called XPOS To store the x position of the text;==================================================================XPOS = 0;==================================================================; Main Loop;;==================================================================While Not KeyDown(1)Text XPOS,100,"HELLO!"XPOS=XPOS+1VWaitClsWend`
As you can see, we are changing the contents of XPOS and using XPOS as our location to draw the text.
Eventually it goes off the screen which is a shame. If we use a command called "IF" we can do something about it.

Usually we'd say IF (SOMETHING OR OTHER) THEN DO SOMETHING

We'll have a moivement variable called speed this time, you should be able to work this out no problem...

Code: [Select]
`;=============================; Simple Integer Variable demo; By Shockwave................;=============================;==================================; Open Screen;; X size, Y size , Bit depth , mode;==================================Graphics 640,480,32,2;==================================================================; Create a variable called XPOS To store the x position of the text;==================================================================XPOS = 0;==================================================================; Create a variable called SPEED To store the Speed of the text.;==================================================================SPEED = 2;==================================================================; Main Loop.;==================================================================While Not KeyDown(1)Text XPOS,100,"HELLO!";==================================================================; Add the contents of Speed to xpos;==================================================================XPOS=XPOS+SPEED;==================================================================; Check the contents of Xpos to see if screen edge reached, if so reverse speed.;==================================================================If XPOS>640 Then SPEED = -2If XPOS<  0 Then SPEED =  2VWaitClsWend`
Notice that when you add a negative number to a positive one then you actually get a subtraction.
You now have a good understanding of basic integers. Next time we'll do strings.
Shockwave ^ Codigos
Challenge Trophies Won:

#### lilw4t3rdr0p

• Guest
##### Re: Blitz 2D Beginners Tutorials.
« Reply #1 on: November 17, 2006 »
Shock: I know you are busy, but when you have time could you please add another tutorial?

#### Shockwave

• good/evil
• Founder Member
• Posts: 17297
• Karma: 489
• evil/good
##### Re: Blitz 2D Beginners Tutorials.
« Reply #2 on: November 18, 2006 »
Yeah, I'll do one soon.
Shockwave ^ Codigos
Challenge Trophies Won:

#### lilw4t3rdr0p

• Guest
##### Re: Blitz 2D Beginners Tutorials.
« Reply #3 on: November 18, 2006 »
Thank you!

#### lilw4t3rdr0p

• Guest
##### Re: Blitz 2D Beginners Tutorials.
« Reply #4 on: December 20, 2006 »
I know how to draw a square, circle, oval, line, and point, but what about a triangle?

I tried to type it in

Tria 300, 300, 50, 50 but it doesn't do anything.

Is the command wrong? Is there an extra parameter? LOL, is it even possible and if it is, can you make an inverted triaganle?

Oh and what about diamond shapes, or rect turned at a 45 degree angle?

Fhew!
« Last Edit: December 20, 2006 by lilw4t3rdr0p »

#### Jim

• Founder Member
• Posts: 5257
• Karma: 394
##### Re: Blitz 2D Beginners Tutorials.
« Reply #5 on: December 20, 2006 »
In blitz you need to draw the outline of the triangle using 3 lines.  If you need to fill it then it's a bit more complicated (perhaps a bit beyond you just now, but we'll get there in '07 :-).

Jim
Challenge Trophies Won:

#### lilw4t3rdr0p

• Guest
##### Re: Blitz 2D Beginners Tutorials.
« Reply #6 on: December 20, 2006 »
Thanks Jim.