so i thought i'd ask here if some one knew how to go about doing it? Just to be clear, i'm not asking you to tell me what to do, i'm asking how to go about doing it.
public void update()
{
Point currentCell = new Point(0, 0);
// phase one checks each square on the current frame layer, if within the rules then it flags that square on the update array
// rows
for (int x = 0; x < 10; x++)
{
// columbs
for (int y = 0; y < 10; y++)
{
// tallys up neighbers (and sets the count to zero)
int celltally1 = 0;
int celltally2 = 0;
currentCell.X = x;
currentCell.Y = y;
// checks all neighbering cells
// left
if (currentCell.X > 0)
{
if (pGrid[currentCell.X - 1, currentCell.Y] >= 1)
{
celltally1++;
}
if (pGrid[currentCell.X - 1, currentCell.Y] >= 2)
{
celltally2++;
}
}
// up
if (currentCell.Y > 0)
{
if (pGrid[currentCell.X, currentCell.Y - 1] >= 1)
{
celltally1++;
}
if (pGrid[currentCell.X, currentCell.Y - 1] >= 2)
{
celltally2++;
}
}
// right
if (currentCell.X < 100)
{
if (pGrid[currentCell.X + 1, currentCell.Y] >= 1)
{
celltally1++;
}
if (pGrid[currentCell.X + 1, currentCell.Y] >= 2)
{
celltally2++;
}
}
// down
if (currentCell.Y < 100)
{
if (pGrid[currentCell.X, currentCell.Y + 1] >= 1)
{
celltally1++;
}
if (pGrid[currentCell.X, currentCell.Y + 1] >= 2)
{
celltally2++;
}
}
// up right
if (currentCell.Y > 0 && currentCell.X < 100)
{
if (pGrid[currentCell.X + 1, currentCell.Y - 1] >= 1)
{
celltally1++;
}
if (pGrid[currentCell.X + 1, currentCell.Y - 1] >= 2)
{
celltally2++;
}
}
// up left
if (currentCell.Y > 0 && currentCell.X > 0)
{
if (pGrid[currentCell.X - 1, currentCell.Y - 1] >= 1)
{
celltally1++;
}
if (pGrid[currentCell.X - 1, currentCell.Y - 1] >= 2)
{
celltally2++;
}
}
//down right
if (currentCell.Y < 100 && currentCell.X < 100)
{
if (pGrid[currentCell.X + 1, currentCell.Y + 1] >= 1)
{
celltally1++;
}
if (pGrid[currentCell.X + 1, currentCell.Y + 1] >= 2)
{
celltally2++;
}
}
// down left
if (currentCell.Y < 100 && currentCell.X > 0)
{
if (pGrid[currentCell.X - 1, currentCell.Y + 1] >= 1)
{
celltally1++;
}
if (pGrid[currentCell.X - 1, currentCell.Y + 1] >= 2)
{
celltally2++;
}
}
// rules fo alive cells
if (pGrid[currentCell.X, currentCell.Y] != 0)
{
// rule = less then 2 A neighbers then kill cell
if (celltally1 < 2)
{
pGridU[currentCell.X, currentCell.Y] = 0;
}
// rule = Greater then 3 A neigbers then kill cell
if (celltally1 > 3)
{
pGridU[currentCell.X, currentCell.Y] = 0;
}
// rule = less then 2 B neighbers then kill cell
if (celltally2 < 2)
{
pGridU[currentCell.X, currentCell.Y] = 0;
}
// rule = Greater then 3 B neighbers then kill cell
if (celltally2 > 3)
{
pGridU[currentCell.X, currentCell.Y] = 0;
}
// rule = if more B cells then A, convert cell to B
if (celltally2 > celltally1)
{
pGridU[currentCell.X, currentCell.Y] = 2;
}
// rule = if more A cells then B convert cell to A
if (celltally2 < celltally1)
{
pGridU[currentCell.X, currentCell.Y] = 1;
}
//// rule = if enough A cells then keep as A
//if (celltally1 > 1 && celltally1 < 4)
//{
// pGridU[currentCell.X, currentCell.Y] = 1;
//}
// //rule = if enough B cells then keep as B
//if (celltally2 > 1 && celltally2 < 4)
//{
// pGridU[currentCell.X, currentCell.Y] = 2;
//}
}
else
{
// rules for dead cells
// rule = if 3 A neighbers then make cell alive as A
if (celltally1 == 3)
{
pGridU[currentCell.X, currentCell.Y] = 1;
}
//rule = if 3 B neighbers then make cell alive as B
if (celltally2 == 3)
{
pGridU[currentCell.X, currentCell.Y] = 2;
}
}
}
}
// phase two moves the update array to the current frame array
for (int y = 0; y < 10; y++)
{
for (int x = 0; x < 10; x++)
{
pGrid[x, y] = pGridU[x, y];
}
}
// Phase three clears the update layer, as in reset
Clear();
}
right, i got the displaythingy to work so now i have a grid with cells that can be switched on and off (display wise, no logic)
so which would be better, a single two layer array where i flag each block to be changed on the second layer and then change acourdingly or two single layer arrays and check the first array's data and modify the second acourdingly.
A) this is c#
There is nothing stopping you from using pointers in C# BTW. You just need to enable unsafe code in your project. It will even work on the 360.
EDIT: wow, i intended to start working on it more, but that was 2 hours ago :P.
right, well that's it, times up i won't be uploading it since i kind of didn't get it working adaquatly, i might come back to it in the furture if i do ill post it then, thanks for the help. Still, i learnt alot about XNA and game implimentation so it served it's perpose, i think the main reason i failed wasn't becuase of bad code (well yeah but that's not it) but sloppy coding style (which in turn cuased the bad code, see wasn't just bad code), in the future i won't be so sloppy so problems that occur will be easier to deal with.
I wonder what the next game we have to make will be?