Sunday, September 26, 2010

Space Invaders Tutorial: Part 1 Setup

Welcome to the start of a great tutorial series on the great classic game Space Invaders. This part will be the setting up part of the tutorial. Please read this carefully as we will create a folder for the game with certain subdirectories.

Creating the main folder for this project we will need to create a new folder on the desktop.




Rename the folder to Space Invaders Tutorial.



Once you  have done that open the folder and add 1 subdirectory named Resources like so
Now we have to add 2 subdirectories for the resources folder. One named Graphics and the other named sounds.

Well done. Now we have the folder framework for our game. Now we have to add some code as this tutorial is for a game called space invaders. We need to have a framework so that the code can be read easier if you need help if there is something wrong and the other reason is so that you know what you are doing. Open up Basic4GL and type in the following to the program.

Well done now save it in the Space Invaders Tutorial folder that we created on the desktop and name it Space Invaders Tutorial.


Well done. You have successfuly completed the first part of the Space Invaders Tutorial on the Everything Basic4GL blog. I hope you have enjoyed this part of tutorial and you look forward to the next parts of the tutorial.
Please note: This tutorial series will be done by screenshots and text like this part was. The code will always be in the screen shot and sometimes will be under the image if it is hard to read or is longer than the screen. This will be done with text like this and will be coloured with the respected colour in the basic4GL IDE.

Saturday, September 25, 2010

Space Invaders Tutorial: Introduction

Welcome to the Everything Basic4GL blog. This tutorial is to use the four parts of the tutorial series on this blog called the Basic4GL Basics Tutorial. Space Invaders a very well known classic arcade game. There has been many clones, references to the game designed and created by Tomohiro Nishikado.

This tutorial series goal is to create a complete clone of the Space Invaders game. The concepts we will use for this game is Text for the scores and lives, images for the spaceship and enemies and sound for extra effects.

The images you will need will be at the top of the tutorial part that it will be used in. The sound will also be in the post that it will be used in.

The tutorial series will not go into depth of the Basics as you should of leared them in the tutorial series The Basic4GL Basics tutorial. Links to the parts are here.

I hope you enjoy the space invaders tutorial series.

Tuesday, September 21, 2010

Basic4GL Basics Tutorial 4 - Playing a .wav sound

Ok so basically it has been a while. I haven't really done much lately on programming especially with basic4GL, but I'm back with a new tutorial that will get you on your way with programming more applications. This tutorial will go into detail about loading and playing a .wav file. This part will conclude with the basic4GL basics tutorial.

This is a very simple program as the sound we will be using for this example will be the gong.wav file. It is found inside the C:\Program Files\Basic4GL\Programs\Sounds directory. So if you run save this program in the default programs directory you will be able to play the sound. So lets get to the code of this program.

dim sound

sound = LoadSound("sounds/gong.wav"
PlaySound(sound)

lets explain the code. we have to dim the variable which will store the sound file in this program. We then use the LoadSound function which was made for the use of games or other media applications to make it easier for people to have audio in their programs. Part of the LoadSound function we have to include a path to file. Then we use the PlaySound functions which we use the variable that holds our sound. save your program in the programs directory that was installed with the basic4gl installer. on my system it is C:\Program Files\Basic4GL\Programs\. Play the program and you should hear the sound of a gong.

I hope this tutorial helps you in the future.

Thursday, May 27, 2010

Basic4GL Basics Tutorial 3 - Load a Image to the Screen

This tutorial teaches you how to load a image to the screen. Make sure you have gone here and here before learning how to load a image and place it on the screen.

Ok so loading a image in Basic4GL is actually a lot easier than most of other programming languages. This so because of the way the sprite library is made to make sprite games. Also did you know you can create complete games using the sprite library and without knowing a single peice of OpenGL code. So lets continue with this tutorial by saving a image from below.




Now save it as a .png as thats the file format I like personally. Make sure Basic4GL is open and place the following code into it. Preferably typing it in and not copying and pasting it.

dim block

block = NewSprite(LoadTex("block.png"))
SprSetPos(200, 200)
BindSprite(block)

ok so lets explain this code for you.
firstly you declared a variable and told Basic4GL you wanted it to make a NewSprite. Then you toald it load a image called block using the LoadTex function. You then selected the point in the screen where you wanted to place the loaded image. BindSprite doesn't need to be called but if you wanted multiple images on the screen at once it has to be used. So it's just good practise.
Now if you save this program to the desktop in a folder called test. Pleae place the block image in here and save your basic4GL file with whatever name you like. If you followed the tutorial correctly your program should look like below.


So now this part of the tutorial is finnished. You can now place your images you make onto the screen. There is quite a lot of image formats that Basic4GL can load such as .png, .jpg, .bmp, .gif and several others that I have forgotten about.

Basic4GL Basics Tutorial 2 - Variables and Constants

This is the secobd part to the Basic4GL Basics Tutorial set. If you want to learn how to display text to the screen then go here.

Variables are not just very useful but they are essentially needed in every program. Basic4GL's variables have to be declared with dim no matter what type of variable you are using. The different variables types are as such:
  • integer e.g dim x = 1
  • float e.g dim x# = 1.01
  • string e.g dim string$ = "Hello World
ok so those are the three variable types used in Basic4GL. Constants are the same as variables except is just declared like so const x = 10. constants cannot be altered later on in the program where as the other three variable types can.

So lets use some variables and print them to the screen.

dim a = 1
dim b# = 1.014
dim c$ = "Hello Mate"

printr a
printr b#
printr c$

ok so thats the basic part of using variables. lest use maths with variables aye. This is a bit of fun.

dim a = 1+7
dim b = 9
dim c = a + b

print c


Well thats the addition used. You can experiment on what you have learned in this tutorial as you have completed it.

Tell me what other tutorials for Basic4GL you would like me to make for you by emailing me at wayne_312@live.com

Basic4GL Basics Tutorial 1 - Displaying Text to the Screen

This tutorial assumes you have downloaded Basic4GL from here and installed it.

Basic4GL is a easy to learn easy to use programming language. It isn't designed to be the best programming language in fact it was a hobby project by a guy named Tom Mulgrew. However he has just recently had a child and well all his spare time is taken with work and his family.

This tutorial is one of a few that teaches you the basics of Basic4GL programming. Also note there are the guides that tells you about Basic4GL. However this tutorial set only covers key aspects of Basic4GL so you may have to read the guides to help you learn other aspects of Basic4GL. If you have problems learning parts of Basic4GL email me your problems at wayne_312@live.com or go and ask for help at the Basic4GL forum located here.

Ok open up the Basic4GL IDE which looks like the image below



Well done. Ok now we should learn how to display text on the screen. There are two main ways in Basic4GL. There is the printr function which returns the cursor to the next line. The print function leaves the cursor after the last character of the string. Now lets have a go.

printr "Hello World!"

did you see the go button located in the middle of the top bar. Click on it I dare you to. Also if you like use the shortcut which is F9.

Now lets go complex.

print "Health "
printr "= 100"
print "Score"
printr "= 0"

Run that and you will see some text in the screen.

Well this concludes the first tutorial on displaying text to the screen. The next tutorial should be out soon.