Tile based map.
by Vladimir
Vasilyev
Part2.
Introduction.
The basic idea used at
construction of a map is next :
We admit (allow), that the map is already correctly
constructed so it is necessary only to replace in the chosen
cell of a map one type of a surface with another.
Actually, on this place the
second part of the paper can be completed, since further it is
necessary only accurately to consider all special cases of
such replacement. As an example, we shall consider one of
variants.
Drawing by
the HI type on the LOW. (Hi
to Low)
For the
beginning we shall consider a case, when a new and old type of
a surface belong to one set and the new type of a surface is the
HI type. In a considered example an old type of a surface
- GROUND new - a GRASS and both types belong to the same TILESET2:
GROUND - GRASS and GRASS is the HI type in
relation to GROUND. (according to accepted in the first part
of clause to designations and names).
Fig.
1 |
Fig.
2 |
Fig.
3 |
|
For such type of the
replacement, for the tile, selected on fig1
- we shall name it further as central
- it is required in addition to replace only eight its nearest
neighbors. The distant neighbors do not changed in this case.
The process of calculation of
new bit representations for the nearest neighbors consists of
two stages and is realized in the editor in procedure
DoMain1x1.
At the first stage the bit
representation for everyone tile sets to nil and then known
(in the sense that for these bits is precisely known its
meaning ) bits are set to the necessary value. For new
central tile bit representation is 1111111.
As the nearest neighbors on borders should be coordinated with
central tile that we shall receive the following
known meanings of bits.
Number of
the neighbour
|
Bit masks
|
Fig.
4
|
Hi bit - top
7654
|
Low bit - party
3210
|
0
|
0110
|
0100
|
|
1
|
1100
|
1000
|
2
|
1001
|
0001
|
3
|
0011
|
0010
|
4
|
0100
|
0000
|
5
|
1000
|
0000
|
6
|
0001
|
0000
|
7
|
0010
|
0000
|
The values of bit masks
are stored in MaskArr1.
|
FTileMap
[ny, nx] .SetN: = AMapBrush; //
i.e. = cSetN;
TileBits: = 0; // is cleared
all bits
TileBits: = TileBits or MaskArr1 [i]; //
drawing by Bit=1 |
It is possible to tell, that
in this case (Hi to Low) we " draw by bit 1
".
At the second stage it is
necessary to receive missing meanings of bits. For this
purpose we pass on the just calculated nearest neighbors again
and for each of them we spend procedure of the coordination
(in the editor it is procedure CheckNeighbours (nx,
ny)) sides and tops for current tile with already its nearest neighbors.
Fig.
5
If we draw by a LOW type on
the HI from one TILESET, it is necessary, accordingly,
" to draw by zero ":
|
if
AMapBrush-SetN =-1 then
begin
TileBits:=FTileMap[ny,nx].TileBits;//get
the value
// combine it with the
mask - drawing by Bit=0
TileBits: = TileBits and MaskArr0 [i];
end; |
If a new and old type of a
surface belong to different sets, we reduce (increase) number
of a brush and draw the central cell and nearest neighbors by
intermediate terrain types. (in the editor it is procedure
Do1x1 (cnx, cny: Longint; const AMapBrush: byte)
The procedure corrects a
MapBrush and recursive calls itself while we shall not receive
the case described in the beginning of the clause, then the
execution passes to procedure DoMain1x1
(cnx, cny, AMapBrush);
I have increased amount of
the comments in a code of the editor and I hope, that you can
understand all ideas. If it is not - write to me and I
shall tell about difficult places, from your point of view, in
more detail.
Copyright ©
2001 Vladimir Vasilyev.
Any part of
given clause, including illustrations, in any purposes can not
be reproduced in any form and any means without the written
permission of the author.
|