root/src/ZuneDemo/Renderer/DrawableWorld.cs

User picture

Author: conkerjo

Revision: 30 («Previous)


File Size: 1.77 KB

(November 01, 2009 14:48 UTC) Over 2 years ago

Added Zune HD support and simple sample

 
Show/hide line numbers
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Brains.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework;

namespace ZuneDemo.Renderer
{
    public class DrawableWorld : World
    {
        public static Texture2D pointTexture;
        public DrawableWorld(ContentManager content)
        {
            pointTexture = content.Load<Texture2D>("Textures/point");
        }
        public void Render(SpriteBatch batch)
        {
            for (int x = 0; x < this.Map.ClusterGrid.Cols; x++)
            {
                for (int y = 0; y < this.Map.ClusterGrid.Rows; y++)
                {
                    this.DrawGrid(batch, this.Map.ClusterGrid.Grids[this.Map.ClusterGrid.GetGridIndex(x, y)]);
                }
            }

            foreach (var item in this.Actors)
            {
                ((DrawableAgent)item).Render(batch);
            }
        }

        private void DrawGrid(SpriteBatch batch, Brains.Framework.Map.Grid grid)
        {
            for (int x = 0; x < grid.Cols; x++)
            {
                Rectangle rect = new Rectangle(0, 0, 1, 1);
                rect.Height= grid.Height;
                rect.X = x * grid.CellSize;
                rect.Y = 0;
                batch.Draw(pointTexture, rect, Color.White);
                
                for (int y = 0; y < grid.Rows; y++)
                {
                    rect = new Rectangle(0, 0, 1, 1);
                    rect.Width = grid.Width;
                    rect.X = 0;
                    rect.Y = y * grid.CellSize;
                    batch.Draw(pointTexture, rect, Color.White);
                }
            }
        }
    }
}