Alright so Im making a Final-Fantasy tactics style game, and I have built the grid, using a multidimensional array, right now its 3x3, 32 pixels per 'cell' Im just having problems drawing it, I dont really know where to start. I guess I need to do a foreach loop, loop through my array and Draw the GrassTile with the same position as the cell.
heres my code, Any suggestions? (this is a first with OO language for me, so Im really just having problems communicating with the Game1 class' Draw method, with my Grid class's cell array.
Game1.cs
namespace Tactics
{
public class Game1 : Microsoft.Xna.Framework.Game
{
GraphicsDeviceManager graphics;
SpriteBatch spriteBatch;
Grid mapOne;
Texture2D grassTile;
public const int cellSize = 32; //The cell size, in pixels, used to multiply the offset.
public Game1()
{
graphics = new GraphicsDeviceManager(this);
Content.RootDirectory = "Content";
}
/// <summary>
/// Allows the game to perform any initialization it needs to before starting to run.
/// This is where it can query for any required services and load any non-graphic
/// related content. Calling base.Initialize will enumerate through any components
/// and initialize them as well.
/// </summary>
protected override void Initialize()
{
mapOne = new Grid();
graphics.PreferredBackBufferWidth = 96;
graphics.PreferredBackBufferHeight = 96;
graphics.ApplyChanges();
Window.Title = "Tactics";
base.Initialize();
}
/// <summary>
/// LoadContent will be called once per game and is the place to load
/// all of your content.
/// </summary>
protected override void LoadContent()
{
// Create a new SpriteBatch, which can be used to draw textures.
spriteBatch = new SpriteBatch(GraphicsDevice);
grassTile = Content.Load<Texture2D>("sprites/grass");
}
protected override void UnloadContent()
{
}
protected override void Update(GameTime gameTime)
{
// Allows the game to exit
if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
this.Exit();
base.Update(gameTime);
}
protected override void Draw(GameTime gameTime)
{
GraphicsDevice.Clear(Color.CornflowerBlue);
spriteBatch.Begin();
spriteBatch.End();
base.Draw(gameTime);
}
}
}
Cell.cs
namespace Tactics
{
public class Cell
{
Vector2 cellPos;
Vector2 cellLeft;
Vector2 cellRight;
Vector2 cellUp;
Vector2 cellDown;
Vector2 cellParent;
int cellType;
//cell types.
public const int cellTypeGrass = 1;
public Cell(Vector2 pos, int type)
{
//Initialize all the cell variables.
cellPos = pos;
cellType = type;
//Based on this cells position, find all the other cells locations.
cellLeft = cellPos; cellLeft.Y -= Game1.cellSize; //to find the cell to the left, you take the current cells position, then subtract 1 offset from Y
cellRight = cellPos; cellRight.Y += Game1.cellSize; // same as left, except +offset
cellUp = cellPos; cellUp.X -= Game1.cellSize; //same as others, except - X offset
cellDown = cellPos; cellDown.X += Game1.cellSize; //same.
cellParent = Vector2.Zero; //wont be using this till pathfinding.
}
}
}
Grid.cs
namespace Tactics
{
public class Grid
{
public const int gridSize = 3;
public Cell[,] cells = new Cell[gridSize, gridSize];
private Vector2 tempCellPos = Vector2.Zero;
public virtual Grid()
{
for (int x = 0; x < gridSize; x++)
{
for (int y = 0; y < gridSize; y++)
{
tempCellPos.X = (x * 32); tempCellPos.Y = (y * 32); //Making the grid with a multidimensional array
//Send the arguments to the constructor for each cell.
cells[x, y] = new Cell(tempCellPos, Cell.cellTypeGrass);
}
}
}
}
}
any help will be appreciated, those are my 3 classes.