Hi,
So i'm coding a game and to load the tiles, the code will read the .map file where the map info is. But, it gives me this error.
the .map file looks like this:
That's only one line...
48:48:00:06 48:48:00:06 48:00:00:07 1F:00:00:07 22:00:00:07 22:00:00:07 20:00:00:06 22:00:00:06 22:00:00:07 1F:00:00:06 82:00:00:06 87:52:00:06 81:52:00:06 00:00:00:06 00:00:00:06 00:00:00:06 00:00:00:06 00:00:00:06 00:00:00:06 00:00:00:06 00:00:00:06 00:00:00:06 00:00:00:06 00:00:00:06 00:00:00:06 00:00:00:06 00:00:00:06 00:00:00:06 00:00:00:06 00:00:00:06 00:00:00:06 00:00:00:06 00:00:00:06 00:00:00:06 00:00:00:06 00:00:00:06 00:00:00:06 00:00:00:06
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Threading;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using System.IO;
namespace Core
{
public class Core
{
public struct XY
{
public int
X,
Y;
public XY(int x, int y)
{
X = x; Y = y;
}
}
public class Members
{
public static Panel VIEW = new Panel
{
Location = new Point(100, 0),
Size = new Size(570, 570),
Visible = true
};
public static Panel WORLD;
public static Engine ENGINE = new Engine();
public static Tile[,] TILE = new Tile[T_XCOUNT, T_YCOUNT];
public static Init INIT = new Init();
public static int
T_XCOUNT,
T_YCOUNT;
public static bool
FIRST_TIME_ENGINE_INIT = false,
PLAYER_RENDER = false;
}
public class Player
{
public static Bitmap TEXTURE;
public static Rectangle DIMENSION;
public static XY LOCATION;
public static char
PLAYER_LOOKING_AT = 'S';
public const int
DEFAULT_XLOC = 9,
DEFAULT_YLOC = 8,
DEFAULT_XSIZE = 30,
DEFAULT_YSIZE = 30;
public const string
DEFAULT_SPRITE = @"Sprites/Animated/Character/Gael/Gael-LSW.png";
public static bool LookingAt(char direction)
{
PLAYER_LOOKING_AT = direction;
if (PLAYER_LOOKING_AT == 'S')
{
TEXTURE = new Bitmap(DEFAULT_SPRITE);
}
else if (PLAYER_LOOKING_AT == 'E')
{
TEXTURE = new Bitmap(DEFAULT_SPRITE);
}
else if (PLAYER_LOOKING_AT == 'N')
{
TEXTURE = new Bitmap(DEFAULT_SPRITE);
}
else if (PLAYER_LOOKING_AT == 'W')
{
TEXTURE = new Bitmap(DEFAULT_SPRITE);
}
else
{
TEXTURE = new Bitmap(DEFAULT_SPRITE);
}
return true;
}
}
#region Const
public const int
#region Values
WINDOW_XSIZE = 770,
WINDOW_YSIZE = 570,
MAX_XTILE = 49,
MAX_YTILE = 49;
#endregion
public const string
#region Values
WINDOW_TITLE = "Game",
DEBUG_WINDOW_TITLE = "Debug",
SPRITE_FOLDER = "Sprites/",
DEFAULT_SPRITE_EXT = ".png";
#endregion
#endregion
public class Tile
{
public XY LOCATION;
public Rectangle DIMENSION;
public Bitmap FORE_TEXTURE;
public Bitmap BACK_TEXTURE;
public bool COLLSION = false;
public const int
XSIZE = 30,
YSIZE = 30;
public void SetLocation(int x, int y)
{
LOCATION = new XY(x, y);
DIMENSION = new Rectangle(LOCATION.X * 30, LOCATION.Y * 30, XSIZE, YSIZE);
}
}
public class Init
{
public void _Player()
{
Player.LOCATION = new XY(Player.DEFAULT_XLOC, Player.DEFAULT_YLOC);
Player.DIMENSION = new Rectangle(Player.LOCATION.X, Player.LOCATION.Y, Player.DEFAULT_XSIZE, Player.DEFAULT_YSIZE);
Player.TEXTURE = new Bitmap(Player.DEFAULT_SPRITE);
}
public void _Window(Form window)
{
window.Size = new Size(WINDOW_XSIZE, WINDOW_YSIZE);
window.Text = WINDOW_TITLE;
window.BackColor = Color.Black;
window.Controls.Add(Members.VIEW);
Members.VIEW.BringToFront();
}
public void _SetTiles(string mapFile)
{
int Y = 0, X = 0;
string[] Parameter = new string[4];
string[] TilesInfo = File.ReadAllLines(mapFile);
for (int y = 0; y < TilesInfo.Count(); y++)
{
string[] WordsInfo = TilesInfo[y].Split(' ');
Y = TilesInfo.Count();
for (int x = 0; x < WordsInfo.Count(); x++)
{
X = WordsInfo.Count();
Parameter = WordsInfo[x].Split(':');
}
}
Members.T_XCOUNT = X;
Members.T_YCOUNT = Y;
Members.WORLD = new Panel { Location = new Point(0, 0), Size = new Size(X * 30, Y * 30), Visible = true, BackColor = Color.Gray };
Members.VIEW.Controls.Add(Members.WORLD);
Members.WORLD.BringToFront();
for (int y = 0; y < Y; y++)
{
for (int x = 0; x < X; x++)
{
Members.TILE[x, y].FORE_TEXTURE = new Bitmap(SPRITE_FOLDER + Parameter[0] + DEFAULT_SPRITE_EXT);
Members.TILE[x, y].BACK_TEXTURE = new Bitmap(SPRITE_FOLDER + Parameter[1] + DEFAULT_SPRITE_EXT);
if (Parameter[3] == "06")
Members.TILE[x, y].COLLSION = true;
else
Members.TILE[x, y].COLLSION = false;
}
}
}
public void _StartEngine()
{
Members.WORLD.Paint += new PaintEventHandler(_OnRender);
}
public void _OnRender(object sender, PaintEventArgs e)
{
if (Members.FIRST_TIME_ENGINE_INIT == false)
{
Members.ENGINE.Init(e.Graphics);
Members.ENGINE.StartRender();
Members.FIRST_TIME_ENGINE_INIT = true;
}
else
{
if (Members.PLAYER_RENDER == true)
{
Members.ENGINE.RenderPlayer();
}
else
{
}
}
}
}
public static void Render(bool RenderPlayer)
{
if (RenderPlayer == true)
{
Members.WORLD.Paint += new PaintEventHandler(Render);
void Render(object sender, PaintEventArgs e)
{
}
}
else
{
Members.WORLD.Paint += new PaintEventHandler(Render);
void Render(object sender, PaintEventArgs e)
{
}
}
}
}
}
What I have tried:
I have tried to look if it was going above the index, but the exception shows up when
TILES[0,0] = new Bitmap(...)
is called...