The way I have decided to do my tutorial pages is by taking a game idea (in this case PlanIt Fall{try to read it with a slightly deep,cheesy, echo effect}- a repton/boulderdash based game), break it into sections and describe how I went about it. please note I said how I did it - another programmer might go about it a different way (probably a better way for that matter) please forgive my orfull spellin but english is my first language.........doh
So first a quick description of what we need to do for this section
The game consists of a player controlled character moving round a scrolling screen collecting 'things' (gems) and avoiding other things (dying mainly).
THE MAP
I needed a way of holding the map data (in this case stuff like where the gems are,where the rocks are,etc)
Lets use an ARRAY - now arrays are simple, not like those new fangled TYPE things and OBJECTS ORIENTED THINGIES that we now have ("never had them in my day, mutter,mutter,mutter.......")
In my case it is (simplified)....
Dim map(5,8)and this means......
DIM - short for dimension and is a Blitz Basic
'command' - it sets aside some memory
MAP - the 'name' we have assigned (or given to) this memory
(5,8) - the size of the memory table or matrix (an excellent
film imho)
clear as mud ?
how about this then......
imagine you have set up a table of information called MAP with five columns and eight rows e.g.
now we these reference these 'slots of information' e.g.
| MAP | 1 | 2 | 3 | 4 | 5 |
| 8 | |||||
| 7 | |||||
| 6 | |||||
| 5 | |||||
| 4 | |||||
| 3 | |||||
| 2 | |||||
| 1 |
now we can refer to the table contents using an offset - e.g.
map(3,4)=rock
map(2.8)=empty
map(5,6)=gem
| MAP | 1 | 2 | 3 | 4 | 5 |
| 8 | empty | ||||
| 7 | |||||
| 6 | gem | ||||
| 5 | |||||
| 4 | rock | ||||
| 3 | |||||
| 2 | |||||
| 1 |
better ? If not give me a shout and I will try again......
Now the array we have set up is an integer array - it can only hold whole numbers
so we need the items (rock,gem,soil,etc) in a format that can be stored in this array
What I did was define some CONSTANTS - things that never change and make the program easier to read e.g.
Const iRock=3 ; set up a constant called iRock and set it to 3
Const iEmpty=4 ; set up a constant called iEmpty and set it to 4
Const iGem=2 ; set up a constant called iGem and set it to 2
so now I can say in 'pseudo code'
if map(across position,up position)=iRock then do something......
rather than
if map(across position,up position)=3 then do something......
as you can see - it reads easier
so the above becomes
map(3,4)=iRock
map(2,8)=iEmpty
map(5,6)=iGem
| MAP | 1 | 2 | 3 | 4 | 5 |
| 8 | iEmpty | ||||
| 7 | |||||
| 6 | iGem | ||||
| 5 | |||||
| 4 | iRock | ||||
| 3 | |||||
| 2 | |||||
| 1 |
OR
| MAP | 1 | 2 | 3 | 4 | 5 |
| 8 | 4 | ||||
| 7 | |||||
| 6 | 2 | ||||
| 5 | |||||
| 4 | 3 | ||||
| 3 | |||||
| 2 | |||||
| 1 |
getting there ?
In the next bit of this tutorial we can get on with how we can use arrays to set up the map and then display it........
cya soon
a quick note
when you dimension an array e.g. DIM map(3,4) it is actually a table of 4X5 not 3X4 - this is due to computers counting from 0 - so you could have map(0,0)
any comments would, constructive criticism, suggestions, etc to tuts@blitzen.co.uk
if you think my variable names are strange it is from an idea from Krylar over at the Christian Coders Network - go and have a look
tis a good idea.
Who says you cant teach an old dog new tricks ?