I've started a new XNA project and am having some issues communicating between classes. Essentially, I'm laying down framework for a tile-based platformer and have two very simple classes at the moment.
One class, Tile(Tile.cs) contains and enum, named TileCollision and a struct named Tile.
The other, Level(Level.cs). Any time I try to reference TileCollision or try to create a Tile, it says it doesn't exist in the current context.
Is there anything else I need to do to get these two classes to talk? They're in the same namespace and don't need references added since they're not compiled DLL's or anything. Not sure what I've missed.
Here's the code for Tile.cs:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
namespace PoriPlatformer
{
class Tile
{
// Controls the collision detection and response behavior of a tile.
enum TileCollision
{
// A passable tile is one which does not hinder player motion at all, Example: Air
Passable = 0,
// An impassible tile is one which does not allow the player to move through it at all
// It is completely solid.
Impassable = 1,
// A platform tile is one which behaves like a passable tile except when the player
// is above it. A player can jump up through the platform as well as move past it
// to the left and right, but can not fall through the top of it.
Platform = 2,
}
struct Tile
{
public Texture2D Texture;
public TileCollision Collision;
public const int Width = 40;
public const int Height = 32;
public static readonly Vector2 Size = new Vector2(Width, Height);
// Constructs a new tile
public Tile(Texture2D texture, TileCollision collision)
{
Texture = texture;
Collision = collision;
}
}
}
}
Here's the offending code in Level.cs:
// Loads an individual tile's appearance and behavior.
private Tile LoadTile(char tileType, int x, int y)
{
switch (tileType)
{
// Blank space
case '.':
return new Tile(null, TileCollision.Passable);
// Passable platform
case '~':
return LoadTile("platform", TileCollision.Platform);
// Impassable block
case '#':
return LoadTile("block", TileCollision.Impassable);
case '_':
return LoadTile("ground", TileCollision.Impassable);
default:
throw new NotSupportedException(String.Format("Unsupported tile type character '{0}' at position {1}, {2}.", tileType, x, y));
}
}
underlined portions in Level.cs would be TileCollision