I can't figure this out
I am creating an ArrayList of Fish objects. I basically am building a flocking demo using XNA studio. I have a class called FishManager, and one called Fish. I want to add another class called FishGroup, but for now I have to figure out this problem. I am randomly creating the Fish's location and other properties including direction. I walk through the debugger and each fish has different values for everything except the ones I set. After I run the program when I go to draw the fish they all end up with the same values, it really doesn't make sense. I walk through a couple times with the debugger and each time more fish become alike. If someone can see what I'm doing wrong I would really appreciate it. I made sure that the array the constructor is only getting called once, but I am just lost to why I am having this problem.
[code]
namespace Flocking.Fish
{
classFishManager
{
privateTexture2D[] east_image =null;privateTexture2D currentTexture =null;privateArrayList group1 =null;staticbool FishLoaded =false;//This class should only be created oncepublic FishManager(GraphicsDevice device){
FishLoaded = LoadFish(device);
//Create Fishgroup1 =
newArrayList();Fish tempFish;for (int i = 0; i < 10; i++){
group1.Add(
newFish());}
}
privatebool LoadFish(GraphicsDevice device){
east_image =
newTexture2Deast_image[0]=
Texture2D.FromFile(device,"Sprites/ball fish e0000.bmp");east_image[1] =
Texture2D.FromFile(device,"Sprites/ball fish e0001.bmp");east_image[2] =
Texture2D.FromFile(device,"Sprites/ball fish e0002.bmp");east_image[3] =
Texture2D.FromFile(device,"Sprites/ball fish e0003.bmp");east_image[4] =
Texture2D.FromFile(device,"Sprites/ball fish e0004.bmp");east_image[5] =
Texture2D.FromFile(device,"Sprites/ball fish e0005.bmp");east_image
=
east_image[7] =
Texture2D.FromFile(device,"Sprites/ball fish e0007.bmp");returntrue;}
//This function draws the east images without rotationpublicvoid DrawFish(refSpriteBatch sprite){
foreach (Fish ain group1){
int index = a.getFrame();if(index <= 0 || index > 8)index = 1;
tempX += 35;
tempY += 35;
Vector2 tempPosition = a.getPosition();sprite.Draw(east_image[index], tempPosition,
newRectangle(0, 0, 64, 64),Color.TransparentWhite, a.getRotation(),newVector2 (32, 32), 0.75f,SpriteEffects.None, 1.0f);}
}
}
classFish{
privateVector2 direction;privatefloat speed;privatefloat MaxSpeed = 25;privatefloat DesiredSpeed = 10;privatefloat senseRange = 100;privatefloat seperationDistance = 20;privatefloat currentRotation = 0.0f;privateVector2 position;privateint currentFrame = 1;public Fish(){
Random rand =newRandom();int xValue = rand.Next(25);int yValue = rand.Next(25);direction =
newVector2(xValue, yValue);direction.Normalize();
determineRotation();
speed = rand.Next((
int)MaxSpeed);//Make sure fish spawn in the box from 200, 200 to 400, 400int startX = rand.Next(200);int startY = rand.Next(200);position =
newVector2(startX + 200, startY + 200);}
[/code]

