Desperate help on programming simulation :(
in
Programming Questions
•
1 year ago
Hey guys I was trying so hard to avoid this because I have asked so much questions in these fourms already =p but I am a poor programmer and got stuck being the lead programmer for my team in school since they all dont know a lick about programming.
Basically we are creating a simulation where animals breed and each time they breed it would produce a offspring with peices from each parent. I have it set up for testing purposes u control the giraffe and when you intersect with the bear it will choose from a array between a bear head/giraffe head and bear body/giraffe body producing a offspring which is completely random.
Now the idea was once the offspring is produced I would need him to be able to move randomly at will, however I cant figure out to make him move. I am calling these heads/bodies from an array and they are being drawn but I have no idea how to make them move since they are being implemented through a class.
so here is the code broken down
in draw I say
- if (giraffetigersex == true)
{
giraffetigeroffspring.display();
giraffetigeroffspring.move();
} - if ( intersect(giraffe.x, giraffe.y, giraffe.diameter,
bear.x, bear.y, bear.diameter))
{
giraffetigersex = true;
}
so when they intersect and the boolean is true it calls on display and here is my offspring class
- class GiraffeTigerOffSpring
{
float x, y;
float speedX;
float speedY;
float diameter; -
GiraffeTigerOffSpring()
{
x = random(width);
y = random(height);
speedX = random(-2,2);
speedY = random(-2,2);
diameter = 30;
}
void move()
{
x += speedX;
y += speedY; - if ( x < 0 || x > width ) speedX *= -1;
if ( y < 0 || y > height ) speedY *= -1;
}
void display()
{
ellipseMode(CENTER);
heads[randIndexGiraffeTigerHead].draw();
bodies[randIndexGiraffeTigerBody].draw();
}
}
Now display is called through my array which I have set up like this once again code broken down
- interface Head
{
void draw(); - }
- class BearHead implements Head
{
void draw()
{
image(imageHeads[1],25,25,35,35);
}
} and its the same exact thing for body and the others except for body its interface Body and class BearBody implements Body and all the other animal parts have the same class
-
The problem I am having is when I call the sex to be true it just displays it and thats it, it just draws it. I have no idea how I can some how combine these parts ex:Body and head* and have them move randomly together, so when my two animals intersect and produce the offspring, the offspring being drawn will be grouped together and move together randomly
-
ughh I am sorry this is long and I dont know if its complex, I am pretty desperate at this point and my team is completely clueless, if anyone could please help me I would be so thankfull:)
-
sorry and thankkk you in advance!!
1