All pastes #936119 Raw Edit

Unnamed

public text v1 · immutable
·published 2008-03-10 03:28 UTC
rendered paste body
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<Tile> WorldTiles = new List<Tile>();

        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<Texture2D>( "tiles\\water" );
            Tiles[1] = C.Load<Texture2D>( "tiles\\grass" );
            Tiles[2] = C.Load<Texture2D>( "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 );
            }
        }
    }
}