I would most certainly use a mysql database over a flatfile any day (besides perhaps static content). Considering you probably want attributes at the tile level, such as terrain type, whether the area is passable, or perhaps other features, it is best you normalize your structure into a maps table (you probably want multiple maps), a tiles table (each tile for a particular map), and a terrain type table (meta data based on the particular tile). Perhaps a schema (sample data included) along the lines of
Code: Select all
--
-- Table structure for table `gamemap_maps`
--
CREATE TABLE IF NOT EXISTS `gamemap_maps` (
`id` int(10) NOT NULL auto_increment,
`name` varchar(255) collate latin1_general_ci NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci AUTO_INCREMENT=2 ;
--
-- Dumping data for table `gamemap_maps`
--
INSERT INTO `gamemap_maps` (`id`, `name`) VALUES
(1, 'My First Map');
-- --------------------------------------------------------
--
-- Table structure for table `gamemap_terrain`
--
CREATE TABLE IF NOT EXISTS `gamemap_terrain` (
`id` int(10) NOT NULL auto_increment,
`type` enum('grass','water','mountain','plain') collate latin1_general_ci NOT NULL default 'grass',
`passable` tinyint(1) NOT NULL default '0',
PRIMARY KEY (`id`),
KEY `type` (`type`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci AUTO_INCREMENT=5 ;
--
-- Dumping data for table `gamemap_terrain`
--
INSERT INTO `gamemap_terrain` (`id`, `type`, `passable`) VALUES
(1, 'grass', 1),
(2, 'water', 0),
(3, 'mountain', 0),
(4, 'plain', 1);
-- --------------------------------------------------------
--
-- Table structure for table `gamemap_tiles`
--
CREATE TABLE IF NOT EXISTS `gamemap_tiles` (
`id` int(10) NOT NULL auto_increment,
`map_id` int(10) NOT NULL,
`terrain_id` int(5) NOT NULL,
`xpos` int(5) NOT NULL,
`ypos` int(5) NOT NULL,
PRIMARY KEY (`id`),
KEY `map_id` (`map_id`,`terrain_id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci AUTO_INCREMENT=17 ;
--
-- Dumping data for table `gamemap_tiles`
--
INSERT INTO `gamemap_tiles` (`id`, `map_id`, `terrain_id`, `xpos`, `ypos`) VALUES
(1, 1, 1, 1, 1),
(2, 1, 1, 2, 1),
(3, 1, 1, 3, 1),
(4, 1, 1, 4, 1),
(5, 1, 1, 1, 2),
(6, 1, 1, 2, 2),
(7, 1, 1, 3, 2),
(8, 1, 1, 4, 2),
(9, 1, 1, 1, 3),
(10, 1, 1, 2, 3),
(11, 1, 1, 3, 3),
(12, 1, 1, 4, 3),
(13, 1, 1, 1, 4),
(14, 1, 1, 2, 4),
(15, 1, 2, 3, 4),
(16, 1, 3, 4, 4);
Now that we have a normalized map database with coordinates, we can easily construct the map with indivudal tiles metadata. I.e.,
Code: Select all
SELECT *
FROM gamemap_maps AS map
INNER JOIN gamemap_tiles AS tile ON map.id = tile.map_id
INNER JOIN gamemap_terrain AS terrain ON tile.terrain_id = terrain.id
WHERE map.id = 1
ORDER BY map.xpos ASC, map.ypos ASC
Which would generate a map along the lines of
[text]_____________________________________________
| x = 1 | x = 2 | x = 2 | x = 4 |
| y = 1 | y = 1 | y = 1 | y = 1 |
| grass | grass | grass | grass |
| passable | passable | passable | passable |
|__________|__________|__________|__________|
| x = 1 | x = 2 | x = 3 | x = 4 |
| y = 2 | y = 2 | y = 2 | y = 2 |
| grass | grass | grass | grass |
| passable | passable | passable | passable |
|__________|__________|__________|__________|
| x = 1 | x = 2 | x = 3 | x = 4 |
| y = 3 | y = 3 | y = 3 | y = 3 |
| grass | grass | grass | grass |
| passable | passable | passable | passable |
|__________|__________|__________|__________|
| x = 1 | x = 2 | x = 3 | x = 4 |
| y = 4 | y = 4 | y = 4 | y = 4 |
| grass | grass | water | mountain |
| passable | passable | non- | non- |
|__________|__________|_passable_|_passable_|[/text]
Let me know if you need some more explanation.