I was trying to make a Game-Engine when i got an error in my level class (class for level creation)
Level.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace _2dgame
{
class Level
{
public const int LEVEL_WIDTH = 12;
public const int LEVEL_HEIGHT = 8;
private static TextureID[,] blocks = new TextureID[LEVEL_WIDTH, LEVEL_HEIGHT];
public static TextureID[,] Blocks
{
get { return blocks; }
set { blocks = value; }
}
public static void initLevel()
{
for (int x = 0; x < LEVEL_WIDTH; x++)
{
for(int y = 0; x < LEVEL_HEIGHT; y++)
{
if (y >= 12)
{
blocks[x, y] = TextureID.dirt; //ERROR
}
else
{
blocks[x, y] = TextureID.air;
}
}
}
}
}
}
Error:
An unhandled exception of type 'System.IndexOutOfRangeException' occurred in 2dgame.exe