<< Chapter < Page Chapter >> Page >

When all of the prey fish have been eaten, the final time that is displayed is the time that was required for the predator to eat all of the fish in thepopulation and the final kill count that is displayed is the same of the original number of prey fish in the population. (Also note that the player must click the Stop button before starting a new game. Fixing this inconvenience will be a good exercise for the student.)

When the escape attempt is successful...

When the escape attempt is successful, a clone of the prey fish in its new location is stored in the preyObjects container and a normalized versionof the fish's direction vector is stored in the displayVectors container as shown in Listing 22 .

Listing 22 . Restore the prey fish to the population.
}else{ //The escape attempt was successful. Restore// a clone of the prey object in its new // location along with its direction vector// to the population. preyObjects.set(cnt,tempPrey.clone());//Save a normalized version of the direction // vector for drawing later. It will// overwrite the previously saved vector and // if you watch closely it will show the// prey object running away from the // predator.displayVectors.set( cnt,tempVectorA.normalize().scale(15.0));}//end else }//end if distance<50 }//end for loop on population

Listing 22 also signals the end of the for loop that began in Listing 19 .

Keep the prey fish in the playing field

I have one more section of code to explain that deals with the behavior of the prey fish during each iteration of the animation loop. The code in Listing 23 causes prey fish that stray outside the playing field to return to the playing field.

Listing 23 . Keep the prey fish in the playing field.
for(int cnt = 0;cnt<preyObjects.size();cnt++){ tempPrey = preyObjects.get(cnt);if(tempPrey.getDisplacementVector(origin).getLength()>0.5*osiHeight){ tempVectorA =tempPrey.getDisplacementVector(origin); tempPrey = tempPrey.addVectorToPoint(tempVectorA.scale(0.1)); preyObjects.set(cnt,tempPrey.clone());}//end if prey object is out of bounds }//end for loop to process each prey object

The playing field is the interior of a sphere

The playing field is defined to be the interior of a sphere that is centered on the origin with a radius that is one-half the height of the off-screen image.The for loop in Listing 23 iterates once for each prey fish remaining in the population. The if statement in Listing 23 tests to determine if a prey fish is outside of the sphere.

If the prey fish is outside the sphere, the code in Listing 23 gives that prey fish a nudge back toward the origin and saves a clone of the prey fish inits new location.

Erase the off-screen image and draw the large circle

Listing 24 erases the off-screen image and draws the large circle that defines the playing field shown in Figure 1 .

Listing 24 . Erase the off-screen image and draw the large circle.
//Erase the screen g2D.setColor(Color.WHITE);GM01.fillRect(g2D,-osiWidth/2,osiHeight/2, osiWidth,osiHeight);//Draw a broken-line circle that represents the // intersection of the spherical boundary with the// x-y plane. Although the prey objects and the // predator can stray outside this sphere, they// prefer to be inside the sphere. GM01.Point3D tempPointA = new GM01.Point3D(new GM01.ColMatrix3D(osiHeight/2,0,0)); GM01.Point3D tempPointB;//The circle is defined by 39 points around the // circumference.g2D.setColor(Color.BLACK); for(int cnt = 0;cnt<39;cnt++){ tempPointB =new GM01.Point3D(new GM01.ColMatrix3D( osiHeight/2*Math.cos((cnt*360/39)*Math.PI/180),osiHeight/2*Math.sin((cnt*360/39)*Math.PI/180), 0));//Connect every third pair of points with a lineif(cnt%3 == 0){ new GM01.Line3D(tempPointA,tempPointB).draw(g2D); }//end if//Save the old point. tempPointA = tempPointB;}//end for loop//Draw the final line required to close the circle new GM01.Line3D(tempPointA,new GM01.Point3D(new GM01.ColMatrix3D( osiHeight/2,0,0))).draw(g2D);

Questions & Answers

what is microbiology
Agebe Reply
What is a cell
Odelana Reply
what is cell
Mohammed
how does Neisseria cause meningitis
Nyibol Reply
what is microbiologist
Muhammad Reply
what is errata
Muhammad
is the branch of biology that deals with the study of microorganisms.
Ntefuni Reply
What is microbiology
Mercy Reply
studies of microbes
Louisiaste
when we takee the specimen which lumbar,spin,
Ziyad Reply
How bacteria create energy to survive?
Muhamad Reply
Bacteria doesn't produce energy they are dependent upon their substrate in case of lack of nutrients they are able to make spores which helps them to sustain in harsh environments
_Adnan
But not all bacteria make spores, l mean Eukaryotic cells have Mitochondria which acts as powerhouse for them, since bacteria don't have it, what is the substitution for it?
Muhamad
they make spores
Louisiaste
what is sporadic nd endemic, epidemic
Aminu Reply
the significance of food webs for disease transmission
Abreham
food webs brings about an infection as an individual depends on number of diseased foods or carriers dully.
Mark
explain assimilatory nitrate reduction
Esinniobiwa Reply
Assimilatory nitrate reduction is a process that occurs in some microorganisms, such as bacteria and archaea, in which nitrate (NO3-) is reduced to nitrite (NO2-), and then further reduced to ammonia (NH3).
Elkana
This process is called assimilatory nitrate reduction because the nitrogen that is produced is incorporated in the cells of microorganisms where it can be used in the synthesis of amino acids and other nitrogen products
Elkana
Examples of thermophilic organisms
Shu Reply
Give Examples of thermophilic organisms
Shu
advantages of normal Flora to the host
Micheal Reply
Prevent foreign microbes to the host
Abubakar
they provide healthier benefits to their hosts
ayesha
They are friends to host only when Host immune system is strong and become enemies when the host immune system is weakened . very bad relationship!
Mark
what is cell
faisal Reply
cell is the smallest unit of life
Fauziya
cell is the smallest unit of life
Akanni
ok
Innocent
cell is the structural and functional unit of life
Hasan
is the fundamental units of Life
Musa
what are emergency diseases
Micheal Reply
There are nothing like emergency disease but there are some common medical emergency which can occur simultaneously like Bleeding,heart attack,Breathing difficulties,severe pain heart stock.Hope you will get my point .Have a nice day ❣️
_Adnan
define infection ,prevention and control
Innocent
I think infection prevention and control is the avoidance of all things we do that gives out break of infections and promotion of health practices that promote life
Lubega
Heyy Lubega hussein where are u from?
_Adnan
en français
Adama
which site have a normal flora
ESTHER Reply
Many sites of the body have it Skin Nasal cavity Oral cavity Gastro intestinal tract
Safaa
skin
Asiina
skin,Oral,Nasal,GIt
Sadik
How can Commensal can Bacteria change into pathogen?
Sadik
How can Commensal Bacteria change into pathogen?
Sadik
all
Tesfaye
by fussion
Asiina
what are the advantages of normal Flora to the host
Micheal
what are the ways of control and prevention of nosocomial infection in the hospital
Micheal
Got questions? Join the online conversation and get instant answers!
Jobilize.com Reply

Get Jobilize Job Search Mobile App in your pocket Now!

Get it on Google Play Download on the App Store Now




Source:  OpenStax, Game 2302 - mathematical applications for game development. OpenStax CNX. Jan 09, 2016 Download for free at https://legacy.cnx.org/content/col11450/1.33
Google Play and the Google Play logo are trademarks of Google Inc.

Notification Switch

Would you like to follow the 'Game 2302 - mathematical applications for game development' conversation and receive update notifications?

Ask