using System; using System.Collections.Generic; using System.Text; using System.IO; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Audio; using Microsoft.Xna.Framework.Content; using Microsoft.Xna.Framework.GamerServices; using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Input; using Microsoft.Xna.Framework.Net; using Microsoft.Xna.Framework.Storage; namespace TopDown { class Level { private SpriteBatch S; private ContentManager C; private Texture2D[] Tiles = new Texture2D[50]; private struct Tile{ public int x; //X Location public int y; //Y Location public int t; //Texture public Tile( int xx, int yy, int tt ) { x = xx; y = yy; t = tt; } } private List WorldTiles = new List(); private string[] level; public Level( string x, SpriteBatch sb, ContentManager cm ) { level = File.ReadAllLines( "Content\\levels\\" + x ); S = sb; C = cm; Create(); } public void Init() { Tiles[0] = C.Load( "tiles\\water" ); Tiles[1] = C.Load( "tiles\\grass" ); Tiles[2] = C.Load( "tiles\\extra" ); } public void Create() { foreach ( string s in level ) { string[] splits = s.Split( ' ' ); for ( int i = 0; i < splits.Length; i++ ) { for ( int n = 0; n < level.Length; n++ ) { int t = 0; switch ( Int32.Parse( splits[i].Replace( " ", "" ) ) ) { case 0: t = 0; //water break; case 1: t = 1; //grass break; default: t = 2; //extra break; } WorldTiles.Add( new Tile( ( i * 16 ), ( n * 16 ), t ) ); } } } } public void Draw() { foreach ( Tile t in WorldTiles ) { S.Draw( Tiles[t.t], new Vector2( t.x, t.y ), Color.White ); } } } }