This is a screen shot of the game.
This is the map image. Each pixel represents the location of one of the 3d spheres.
Here is the code that reads the map image and converts it to 3d objects.
protected void LoadMap(String mapname)
{
// the map is just an image file with pixels of various colors
// red = barrier
// black = open space
// cyan = closed space
// green = starting point
Texture2D map1 = content.Load<Texture2D>(mapname);
mapwid = map1.Width;
maphei = map1.Height;
int numpix = mapwid*maphei;
if ((map == null) (map.Length < numpix))
{
map = new byte[numpix];
}
// want this map to fit over the circle, so calculate the size of each ball
// scale of the ball
mapballsz = (int)(maxballdist*2) / mapwid;
mapxstart = -(mapwid / 2-1) * mapballsz;
mapystart = -(maphei / 2-1) * mapballsz;
/*
* the sample I used to write this method
* ms-help://MS.VSCC.v90/MS.VSIPCC.v90/MS.XNAGS30.1033/XNA/GetData``1_B8CC1053 */
Rectangle sourceRectangle = new Rectangle(0, 0, mapwid, maphei);
Color[] retrievedColor = new Color[numpix];
map1.GetData<Color>(
0,
sourceRectangle,
retrievedColor,
0,
numpix);
goalcount = 0;
int i;
for (i = 0; i < numpix; i++)
{
if (retrievedColor[i] == Color.Cyan)
{
map[i] = MAP_CLOSED;
}
else if (retrievedColor[i] == Color.Red)
{
map[i] = MAP_BAR;
}
else if (retrievedColor[i] == Color.Blue)
{
map[i] = MAP_GOAL;
goalcount++;
}
else
{
map[i] = MAP_OPEN;
}
}
}
No comments:
Post a Comment