Tile Matrix
What we need is a tile matrix function where an image can hold the appropriate tile frames and they can be quickly rendered by passing a matrix or array to a TileMap() (or whatever you want to call it) function
Ex:
[0,0,0,0,1,1,1,1,1,0,0,0
0,0,0,0,1,0,0,0,1,0,0,0
0,0,0,0,1,0,0,0,1,0,0,0
0,0,0,0,1,1,1,1,1,0,0,0]
you get the idea.
Use a simple matrix (PPL has a very powerful matrix engine and very nice matrix functions):
- Code:
map$ = [
[0,0,0,0,1,1,1,0],
[1,0,0,0,0,0,0,1],
[1,0,1,1,1,0,0,0]
]
// For each row in map$
for (y$, 0, mcount(map$)-1)
// For each columns in row y$
for (x$, 0, mcount(@map$[y$])-1)
if (@map$[y$][x$] != 0)
// Create a new sprite
s$ = NewSprite(NULL);
// Move it to a new location, 32 x 32 pixels map.
MoveSprite(s$, x$ * 32, y$ * 32);
// Use a surface loaded prior with LoadSurface.
SetSpriteSurface(s$, surfaces$[map$[y$][x$]], 0, 0);
end;
end;
end;
It's that easy.
Sponge is working on a game that does exactly that. Maybe he would like to share his source or concept with you?
does this take a lot of fps to render constantly with so many sprites? Also with this would you be able to have certain tiles cause collision?
Nope, with 16x16 sprites, it took no time to render a full screen, and moved around at over 100FPS on my A620.
Yes you can do certain tiles causing collision too.
Your game Sponge is the perfect example. When it is more advanced, are you considering making it open-source for the community?
why do you have to put the @ in front of the map$. Also, is there reason you make a surface because you can draw to a surface, but cannot draw to a sprite? I am a little confused.
The @ converts an address into actual data in a variable.
Dim(d$, 10);
d$[0] = "THIS IS A STRING";
In PPL a lot of the string data is stored as an address value.
ShowMessage(d$[0]);
Will not print "THIS IS A STRING" but it's address value.
ShowMessage(@d$[0]);
Will convert the address value into it's actual content and print "THIS IS A STRING".
In the case of a matrix:
a$ = [10, 10];
a$ points to a memory location that holds the matrix elements 10, 10.
ShowMessage(a$);
Will print the address.
a$ = [[10,10]];
a$ still points to a memory location. But the first element of the matrix also point to another matrix (called a sub-matrix) that holds elements 10,10.
ShowMessage(a$[0]);
Will print the address pointed by element 0 of the matrix a$.
In order to get the actual data and process it, you need to transfer from an address to data.
ShowMessage(@a$[0][1]);
Converts a$[0] to data and then print matrix element of sub-matrix, which is 10.
The matrix is stored like this:
a$ = [10, 20, [30, 40]];
a$ : 10, 20, [address-1]
address-1 : 30, 40
-----------------------------------------------------
A sprite is just a set of values (including a surface pointer) for the engine to use. A sprite is not a surface in itself.
tune in next week when we discuss chapter 14 of the latest release from Microsoft Press, "PPL, the early years"
Thanks for the explaination. I understood everything up to the part where a$=[[10,10]]. here is where you lost me. Is a matrix like an array? I don't understand the double brackets
So does a$[0][1,1]="wew" work?
Matrix can contain sub-matrix.
[10, 10, [20, 30], 40, 50]
The [20, 30] are considered a sub-matrix of a matrix.
A matrix is almost like an array of values except they are stored just a bit differently internally.
To access sub-matrix you cannot use matrix$[10, 10], this would simply not work.
You have to tell PPL that the first offset is pointing to a sub-matrix and then get a value inside that sub-matrix with the second offset value.
- Code:
matrix$[10][10]
matrix$[10] <- points to sub-matrix in position 10.
[10] <- get element value at position 10.
An Array is stored differently, there are no sub-arrays possible.
- Code:
Dim(a$, 3, 3);
0, 1, 2
0, 1, 2
0, 1, 2
a$[1,1] is correct for an array,
however a$[1][1] is not. Unless you have an array value pointing to an address:
- Code:
a$[1,1] = "THIS IS A STRING";
ShowMessage(@a$[1,1]); // "THIS IS A STRING"
ShowMessage(a$[1][1]); // Character value of 'H'
Because a$[1] points to an address, then the [1] offset points to the H letter in "THIS IS A STRING".[/code]
Ok, this whole time I have been confusing arrays with matrices.
Let's see if I understand right.
I create the following matrix:
a$ = [0,1,2,"You ",4,"Rock! ",["Big ","Time"]];
Now, if I would access these these are the values I would get:
a$[1] equals the number 1,
@a$[3] equals the string "You ",
a$[4] equals the number 4,
@a$[7][1] equals the string "Time ".
Is this correct?
Correct, except:
@a$[7][1] equals the string "Time ".
should be:
@a$[6][1] equals the string "Time ".
mmttb: If you want to see my world drawing code, I can send it over. I'm intending on a commercial game, so when it's done I'll probably release a large part of the engine open sourced.
sponge, I would like that. you can PM me. Thanks
kornalius, if this is the case, it seems that an array would serve better for a map because it can have, but more importantly be called be dimension
ex:
Sprite located at a$[1,1] = 3
Is there an advantage for making map grids that a matrix would have over this?
An array would have done the job probably even better for access speed. But the reason we use matrices is for hard coding the level by hand in the code.
- Code:
SDIM(Map$, TBYTE, 100, 100);
This would be faster to access and better on the memory usage.
how I have done maps in the past is:
dim(fakemap$,6);
dim(map$,6,6);
fakemap$[0] = "0,0,0,1,1,1";
fakemap$[1] = "0,0,0,1,0,1";
fakemap$[2] = "0,0,0,1,0,1";
fakemap$[3] = "0,0,0,1,0,1";
fakemap$[4] = "0,0,0,1,1,1";
fakemap$[5] = "0,0,0,0,0,0";
Then I use a split function to seperate the strings delimited by a comma and fill up the real map$ elements by processing with 2 FOR loops. This has worked fantastic for me in the past.
Not a very efficient way but it definitely work. You could do the same thing in PPL no problem.
I am in the thinking process of writing a really nice level editor that will support tile and isometric maps. So maybe this will easy your job by a lot in the end.
Hi Kornalius,
any news about the level editor yet?
Also, here are two tilemaps(80x56 tiles), one is single row, the other is double row. Could please show me how to access them using the tilematrix code from above?
And how to use the matrix when there are more than 16 Tiles (0-9,A-F)?
Thanks!
Floodguy: Take a look at Mappy Win.
sponge: Does Mappy Win support isometric display too?
Yes it does. It also supports hexagonal maps, if you want to add support for that too

Here's the link:
http://www.tilemap.co.uk/
Nah, I already have enough in the GameAPI for now!

Sponge: Thanks for the tip. Did actually knowed about Mappy Win. Used it to check the integration and overview of my tiles/map, but don't know how to access such a tilemap, especially from PPL.
Kornalius: the isotile demo shows the tiles on the full screen, how do I get the map to beshowed in a user defined area, like a window on and user interface bitmap (i.e. RPG GUI)?
Floodguy:
You could use a new surface ( NewSurface(), the SetSurface() ) or use the g_setclipping() function to clip the screen drawing.