Arrays and z88dk

12-9-2017

So the game will not have a map using the map software included in the engine, rather I’m going to generate a map using arrays, so I want to explore this in software.

If we know that the playing area is 15 tiles wide and 10 tiles high, we will need to create a 2d array.

The first dimension of the array will be the x position, with data going from 1 to 15
The second dimension of the array will be the y position, with data going from 1 to 10.

Now we can forget the actual data that I want to place in the slot, 1 to 15 and 1 to 10, so that should mean a third dimension.

So the layout I am imagining
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
1
2
3
4
5
6
7
8
9
10

So, the horizontal bit will have in it’s slot a number between 1 and 15 to denote the area on screen where the actual tile will be placed in X
The vertical bit will have the same but in Y.
A third dimension (not shown) will have the tile number we are going to place.
Of course, this array is probably too large for our needs, as this assumes that every tile on the screen will be filled by something. But, for right now I’m going with it.
The idea for now is
1) a 3d array for the level data
2) first dimension is width
3) second dimension is height
4) third dimension is tile data
note: the array is large enough to fill the entire screen in actuality that is too large as you would have a screen completely filled.

Time to experiment, but with a small array.
I need to declare an array and initialize it.

char test[2][3][4] =
{
{
{0, 1, 2, 3},
{4, 5, 6, 7},
{8, 9, 10, 11}
},
{
{12, 13, 14, 15},
{16, 17, 18, 19},
{20, 21, 22, 13}
}
};

Time to compile.

And error

sccz80:”main.c” L:34 Warning:#17:Expected ‘;’
sccz80:”main.c” L:34 Error:#26:Illegal Function or Declaration
sccz80:”main.c” L:35 Error:#26:Illegal Function or Declaration
sccz80:”main.c” L:36 Error:#26:Illegal Function or Declaration
sccz80:”main.c” L:37 Error:#26:Illegal Function or Declaration
sccz80:”main.c” L:38 Error:#26:Illegal Function or Declaration
sccz80:”main.c” L:39 Error:#26:Illegal Function or Declaration
sccz80:”main.c” L:40 Error:#26:Illegal Function or Declaration
sccz80:”main.c” L:41 Error:#26:Illegal Function or Declaration
sccz80:”main.c” L:42 Error:#26:Illegal Function or Declaration
sccz80:”main.c” L:43 Error:#26:Illegal Function or Declaration

Maximum (10) number of errors reached, aborting!
Compilation aborted

Time to check the code again. It looks OK. I run CPPCheck on the code. No errors shown with the code. What the hell.

Well, let’s go to z88DK web site and do some reading.

Apparently, multidimensional arrays are NOT supported in Z88DK. I’m sure there are a number of different ways then to approach this problem. Just need to think them through.

How about having 10 1d arrays with a length of 15.
Each of the 1d arrays will be 1 line in the horizontal

such as this:
array01 = 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
array02 = 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
array03 = 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
array04 = 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
array05 = 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
array06 = 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
array07 = 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
array08 = 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
array09 = 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
array10 = 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15

Each of those slots in that array can hold the tile info for that horizontal line

For example using tile 0 (empty) and tile 9 (something)

array 01 = 9 0 0 0 0 0 9 9 0 0 9 9 9 0 9

Would mean tiles 1,7,8,11,12,13,15 have a tile 9 in them whereas the remainder would have tile 0 in them.

Here are the arrays, initialized.
char horizonalLevelLine0 [15] = {00,00,00,00,00,00,00,00,00,00,00,00,00,00,00};
char horizonalLevelLine1 [15] = {00,00,00,00,00,00,00,00,00,00,00,00,00,00,00};
char horizonalLevelLine2 [15] = {00,00,00,00,00,00,00,00,00,00,00,00,00,00,00};
char horizonalLevelLine3 [15] = {00,00,00,00,00,00,00,00,00,00,00,00,00,00,00};
char horizonalLevelLine4 [15] = {00,00,00,00,00,00,00,00,00,00,00,00,00,00,00};
char horizonalLevelLine5 [15] = {00,00,00,00,00,00,00,00,00,00,00,00,00,00,00};
char horizonalLevelLine6 [15] = {00,00,00,00,00,00,00,00,00,00,00,00,00,00,00};
char horizonalLevelLine7 [15] = {00,00,00,00,00,00,00,00,00,00,00,00,00,00,00};
char horizonalLevelLine8 [15] = {00,00,00,00,00,00,00,00,00,00,00,00,00,00,00};
char horizonalLevelLine9 [15] = {00,00,00,00,00,00,00,00,00,00,00,00,00,00,00};

Actually, I think I like this better anyway since you can actually see what the screen will look like.

horizonalLevelLine0 = {15,15,15,15,15,15,15,15,15,15,15,15,15,15,15};
horizonalLevelLine1 = {15,00,00,00,00,00,00,00,00,00,00,00,00,00,15};
horizonalLevelLine2 = {15,00,00,00,00,00,00,00,00,00,00,00,00,00,15};
horizonalLevelLine3 = {15,00,00,00,00,00,00,00,00,00,00,00,00,00,15};
horizonalLevelLine4 = {15,00,00,00,00,00,00,00,00,00,00,00,00,00,15};
horizonalLevelLine5 = {15,00,00,00,00,00,00,00,00,00,00,00,00,00,15};
horizonalLevelLine6 = {15,00,00,00,00,00,00,00,00,00,00,00,00,00,15};
horizonalLevelLine7 = {15,00,00,00,00,00,00,00,00,00,00,00,00,00,15};
horizonalLevelLine8 = {15,00,00,00,00,00,00,00,00,00,00,00,00,00,15};
horizonalLevelLine9 = {15,15,15,15,15,15,15,15,15,15,15,15,15,15,15};

Except it does not work that nicely.

Seems that you cannot assign arrays that neatly in C.

However, the concept is there.  We assign an array, place the game data inside the array, we will then loop through the arrays and place that data on the screen.

 

 

Advertisements

Author: andydansby

I'm a hobbyist coder working with the ZX Spectrum. Living in New York state near the Syracuse area. I grew up in Virgina. The first computer my parents bought for me was a Timex Sinclair 2068.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s