Introduction
The concept of the map is designed to make it run with minimal resources, including database. This also includes time spend building the map.
In my map images, I have chosen non-tiled images to indicate each map co-ordinates a specific location, but this does not mean one cannot use tiled map. The reason for my approach is to have bold detailed graphics and reduce travel steps from one location to the next. So, the player can travel one or two steps to move from a forest to a town etc.
By default my map view matrix is 5 x 5. Player is in cell x6/y5
| 3/4 | 3/5 | 3/6 | 3/7 | 3/8 |
| 4/4 | 4/5 | N | 4/7 | 4/8 |
| 5/4 | W | P | E | 5/8 |
| 6/4 | 6/5 | S | 6/7 | 6/8 |
| 7/4 | 7/5 | 7/6 | 7/7 | 7/8 |
By default all x/y co-ordinates are filled with default grassland values. This is static array in code.
Then data is fetched from the database requesting values within player's co-ordinates. eg.
where (x between (6-2) and (6+2)) and (y between (5-2) and (5+2)).
If the returned records include any rows, then the matching x/y cells are replaced. eg. if we had one record that had x=7 and y=6, then cell data 7/6 is replaced.
The cell's included data has all the information to display image & description. So, before the page is drawn and sent back to the user's browser, all cell data is updated.
The type of the cell also determines what the player can do on the cell. A type value of zero means the player cannot move to that cell. This makes adding waterhole, oceans or any unmovable area possible by adding records in the database (the default cell value is type=1, Grassland).
As one can see, only 1 record of data is fetched from the database for 25 cell matrix, reducing database access & process time and bandwidth (if mysql is not on the same local machine).
Map's other fields are used by the engine to process if any monsters, players, coins are found on the current cell or not etc.
Depending on cell type, a NPC is selected that is located in the cell and shown. ie. A blacksmith is shown to player on a cell where the type is 4. This NPC will have its items listed for the player to purchase from or to sell to. The NPC can only sell the items sold to by other players.
I will update and add more information as it comes to mind.
Input from you is welcomed.
Details
The structure of table.MAP.
- id int(11) NOT NULL auto_increment, //unique primary key ID
- x int(11) NOT NULL, //X co-ordinates
- y int(11) NOT NULL, //Y co-ordinates
- type int(11) NOT NULL, //type of cell, determines what the player can do while on this cell. A type 0 means the player cannot move to this cell.
- image varchar(16) NOT NULL, //partial url of the image eg. images/map/01.jpg
- name varchar(32) NOT NULL, //name of the cell, eg. Grassland
- desc varchar(256) NOT NULL, //description of cell, eg. City of Vatchestan
- monster int(11) NOT NULL default '0', //if any monsters are found (1 or 0)
- player int(11) NOT NULL default '0', //if other players are visible (1 or 0)
- item int(11) NOT NULL default '0', //if items are found and random multiplier
- coin int(11) NOT NULL default '0', //if coins are found and random multiplier
Note: this structure might change.
TYPES:
- 0 - Player cannot move to this cell
- 1 - Grassland
- 2 - Forest
- 3 - Arena
- 4 - Shop
- 5 - Market
- 6 - Bank
- 7 - Tavern
- 8 - Temple
- 9 - Workshop
- 10 - Clan Castle
- 11 - Major City