Hello, I have a problem and I am not sure how to approach the solution. I need to create a 2D map editor for my XNA app., with a certain number of tiles. Say a map will be 50x100 tiles.
I am not sure what data structure to use for the map, tiles and how to store it on the hard-drive for later loading.
What I am thinking now is this. I will store the map in a text file like so:
//x, y, ground_type, object_type
0, 0, 1, 0
0, 1, 2, 1
where 0=Grass, 1=River etcc for ground terrain, and 0=Nothing, 1=Wall for object types.
Then I will have a Game Component Map class that can read that file or create a new one from scratch:
class Map : DrawableGameComponent {
//These are things like grass, whater, sand...
Tile ground_tiles[,];
//These are things like walls that can be destroyed
Tile object_tiles[,];
public Map(Game game, String filepath){
for line in open(filepath){
//Set the x,y tile to a new tile
ground_tiles[line[0], line[1]] = new Tile(line[3])
object_tiles[line[0], line[1]] = new Tile(line[4])
}
}
public Map(Game game, int width, int heigth){
//constructor
init_map()
}
private void init_map(){
//initialize all the ground_tiles
//to "grass"
for i,j width, heigth{
ground_tiles[i,j] = new Tile(TILE.GRASS)
}
public override Draw(game_time){
for tile in tiles:
sprite_batch.draw(tile.texture, tile.x, tile.y etc..)
}
My Tile class will probably NOT be a game component. I am still not quite sure how to handle collision detection for example between a bullet originating from the player with the map object. Should that be handled by the Map class or some kind of super Manager class?
Any hints are welcome. Thanks!