using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;
using tAC_Engine;
namespace Game.Astropolis.HackerHavoc
{
///
/// This class stores all the information needed to interact with and display a room
///
class Room
{
public const float ROOM_WIDTH = 10;
public const float ROOM_HEIGHT = 10;
private Vector2 mTileSize;
private Focus camera;
List> mTiles;
Viewport mDrawSpace;
Player mplayer;
public Room(String pIn, Viewport pDrawSpace)
{
//Calculates the size of a tile.
//mTileSize.Y = pDrawSpace.Height / ROOM_HEIGHT;
//mTileSize.X = pDrawSpace.Width / ROOM_WIDTH;
mTileSize.Y = 75;
mTileSize.X = 75;
mDrawSpace = pDrawSpace;
if (pIn.Equals("Default"))
{
mTiles = new List>();
List row = null;
List lastRow = null;
Tile t = null;
for (int a = 0; a < ROOM_HEIGHT; a++)
{
row = new List();
for (int b = 0; b < ROOM_WIDTH; b++)
{
if (t == null)
{
t = new Tile();
t.name = a + " , " + b;
t.PositionReferfence = Tile.PositionRef.Head;
t.Position = new Vector3(mTileSize.X/2.0f, mTileSize.Y/2.0f,0);// Vector3.Zero;
t.Width = mTileSize.X;
t.Height = mTileSize.Y;
row.Add(t);
}
else if (b == 0 && lastRow != null)
{
Tile temp = new Tile();
temp.name = a + " , " + b;
temp.PositionReferfence = Tile.PositionRef.Top;
temp.Attach = lastRow[0];
Vector3 pos = temp.Attach.Position;
//pos.X = pos.Position.X;
pos.Y = pos.Y + mTileSize.Y;
temp.Position = pos;
temp.Width = mTileSize.X;
temp.Height = mTileSize.Y;
row.Add(temp);
t = temp;
}
else
{
Tile temp = new Tile();
temp.name = a + " , " + b;
temp.PositionReferfence = Tile.PositionRef.Left;
temp.Attach = t;
Vector3 pos = temp.Attach.Position;
pos.X = pos.X + mTileSize.X;
//pos.Y = pos.Position.Y;
temp.Position = pos;
temp.Width = mTileSize.X;
temp.Height = mTileSize.Y;
row.Add(temp);
t = temp;
}
}
mTiles.Add(row);
lastRow = row;
}
}
mplayer = new Player(TextureManager.Load(@"Content\MiniGames\Cheetah"),Vector3.Zero,new Vector3(50,50,1));
camera = mplayer;
camera.CameraPosition = Vector3.Zero;
}
//This will update the players interaction in the room and all the interactives.
public void Update()
{
Vector3 pos = camera.CameraPosition;
if (InputState.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.Up))
{
pos.Y -= 1;
}
if (InputState.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.Down))
{
pos.Y += 1;
}
if (InputState.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.Left))
{
pos.X -= 1;
}
if (InputState.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.Right))
{
pos.X += 1;
}
camera.CameraPosition = pos;
}
//This draw method will draw all the tiles.
//The center of the viewport will be the tile that the focus is on.
public void Draw(SpriteBatch pBatch)
{
Viewport old = GenericBaseApplication.GameManager.GraphicsDevice.Viewport;
GenericBaseApplication.GameManager.GraphicsDevice.Viewport = mDrawSpace;
SpriteBatch s = new SpriteBatch(GenericBaseApplication.GameManager.GraphicsDevice);
Vector3 offset = camera.CameraPosition;
offset.X = mDrawSpace.Width / 2 - offset.X;
offset.Y = mDrawSpace.Height / 2 - offset.Y;
s.Begin();
for (int a = 0; a < ROOM_HEIGHT; a++)
{
for (int b = 0; b < ROOM_WIDTH; b++)
{
mTiles[a][b].Draw(s, offset);
}
}
//new Vector3(mDrawSpace.Width/2,mDrawSpace.Height/2,1)
mplayer.Draw(s,offset);
s.End();
GenericBaseApplication.GameManager.GraphicsDevice.Viewport = old;
}
}
}