I’ve had a request to show how to use functions in blitzbasic from TheLividePianoist, I’ve been slow to answer, so here we go:
simple maths function:
purpose of function is to return double the number you send it:
x = 2
y = double(x)
The function header: function double(z) just means that the function is called double (you can call functions what ever you like, as long as there’s not already a function called that), and the (z) tells it to expect a variable called z. z could be anything, in this case it’s a number.
when a function exits, it can either just end using the “end function” line, or it can return a value to the part of the program that called it in this case it’s “y=double(x)”, x gets passed to the function, which get’s written in z, which the function doubles and returns to that part of code assigning the return value to y.
Here’s another quick example:
Say you always centre your text, using text x,y,”hello”,1,1
Instead of having to write ,1,1 on the end everytime, why not write a function called ctext that automatically centres your text?
ctext 400,300,”This is the centre of the screen!”
The function declaration: function ctext(x,y,mytext$) tells the function to expect to be given an x number, a y number and a string of text (hence the $ after mytext):
Then instead of returning a value, we simple call the text function with these values and put ,1,1 on the end to centre the text over the x and y coords chosen.
Hopefully this has cleared things up a bit for you, if you’re still unsure, please let me know.
I’ve begun producing a series of tutorials on how to write a 2D sidescrolling platform game using Blitz Basic. These should work fine in either BlitzPlus or Blitz3D (or Blitz Basic 2d if you want).
So far we’ve got a basic tile map editor and a character who can run left and right and jump.
I’ve got some ideas for what features to add, this has mainly been by looking at major platform games that have come out over the last 20 years and picking out the common features. So we’ll be trying to add the following:
slopes, lift, floating platforms, doors, animated tiles, treasure chests, enemies to be jumped on, breakable tiles, flying sections, powerups and what ever else I can think of.
I’ve already had a number of mails showing interest in this series, so I’ll try to make it a good one. I’ll try to get a general level structure working first, then each tutorial after that will look at adding in more features.
Aside from that, there’s the level editor tutorials. These will have to tie in with the platform game videos. So for instance, I’ll produce a level editor video which adds doors onto the level, the type of doors you get in mario which basically transport you from one area of the level to another. So obviously we then have to add the code to the game engine to handle these doors. The ordering of the videos will be a new level editor video, followed by a game video when adding new features in. Sometimes you’ll see a new game video without a level editor one for when I’m updating the game engine but not affecting the level structure. Level editor’s are very closely tied in with the game engine, but not totally.
The ultimate goal with these videos really is to build a generic platform game engine, that can be used for any type of platformer. So whether you want to write a mario style game, a megaman or a sonic game, you’ll be able to use this code.
The next step will be to use this code as a base for an overhead RPG tutorial series, but that’s a long way off yet, and will involve much more complex functionality such as conversation code for speaking to characters, quests surrounding a storyline and a complex inventory system.
Anyway, here’s the link, go enjoy yourself: Click Here!