Map in the game

xiaoxiao2021-03-06  17

About Map: The size of the "Tiles" map (TILE) is 32x16 (in pixel). The actual size of each tile is 32x15 (in pixels), which is seamless by splicing just a top. The map size is 128x128 (in the block). The arrangement is as follows: 0 2 4 6 8 ... // 0 line 1 3 5 7 9 ... 0 2 4 6 8 ... // Chain 1 3 5 7 9 ... The advantage of this way is very It is easy to determine those tiles in the screen visible range, and only the visible parts are drawn each time. The map is divided into two layers under the underlying and the surface. Each piece attribute accounts for 4 bytes (2 bytes of the underlying and the surface layer). So the size of the entire map is: 128x128x4 = 64k bytes. (Too clever, isn't it? One paragraph in DOS is so big) The property format of each tile is as follows:

TypeDef struct {unsigned no: 8; // Table number Unsigned Height: 4; // Tissue height Unsigned Add: 1; // Tile serial number Unsigned block: 1; // obstacle sign (here you can't walk, for example Wall root) Unsigned actor: 1; // Character logo (Someone stands here NPC) unsigned switch: 1; // Map switching flag (character walks here to switch to another scene)} TCell;

Note: 1, set groundno = 4, if Groundd = 1, then actual GroundNo = 256, ",", ", 512 different pieces of 512), 512 different pieces of (8 1) each map spell. Approximately 300 pieces of pieces are used in the practical application. 3, the character is approximately three pieces high, so the 4 Height is enough to deal with the occlusion of people and scenes. About the character: The character is between the bottom and the surface, and the masking relationship between the character and the scene is treated by the height of the tile. But there is also a front-rear relationship between the characters. How to deal with it? My method is to build a character chain list and use the painter algorithm. The relationship between characters is easy to calculate: first compare Y, then compare X, small pictures. However, there may be such a situation (there may be more complicated in the actual game, just a brief exemplary): The magician stands on the bodies, is released the round lightning magic, and the enemy released around the fire hit. Therefore, on the same tile, there are several elves: 骷髅, lightning, magician, lightning, fire. The solution is that each elf has a property field: byte level; indicates that it is located. The layer can be defined as follows: (just an example, not really doing this)

Const // sprite levelsldeadbody = 1, // body layer slspellunder = 2, // Next layer release magic layer slsprite = 3, // Elf layer slspellabove = 4, // SLSPLE SLSPELLHIT = 5, // Attack magic layer SLFree = 6, // Free layer (the sky is flying birds, butterflies, etc.) ...

转载请注明原文地址:https://www.9cbs.com/read-51557.html

New Post(0)