Note that there are some explanatory texts on larger screens.

plurals
  1. POXNA how to store and draw a 2d map?
    text
    copied!<p>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.</p> <p>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.</p> <p>What I am thinking now is this. I will store the map in a text file like so:</p> <pre><code>//x, y, ground_type, object_type 0, 0, 1, 0 0, 1, 2, 1 </code></pre> <p>where 0=Grass, 1=River etcc for ground terrain, and 0=Nothing, 1=Wall for object types.</p> <p>Then I will have a Game Component Map class that can read that file or create a new one from scratch:</p> <pre><code>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..) } </code></pre> <p>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?</p> <p>Any hints are welcome. Thanks!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload