<< Chapter < Page Chapter >> Page >

The graphical user interface

In addition to some other controls, the GUI provides an Attack button and an elapsed-time/kill-count indicator, shown in the bottom right in Figure 5 . At any point in time, this indicator displays the elapsed time in milliseconds when the most recent prey fish was eaten along with the totalnumber of prey fish that have been eaten. The two values are separated by a "/" character.

When all of the prey fish have been eaten by the predator, the elapsed time indicator shows the time in millisecondsrequired for the predator to catch and eat all of the prey fish. It also shows the number of prey fish that were eaten,which should match the value that the player entered into the upper-right text field before starting the game. (This field contains 500 in Figure 1 and 200 in Figure 5 ) .

Not initially in attack mode

When the player clicks the Start button and the game begins, the predator is not in attack mode. Rather, the predator swims around the school ofprey fish encouraging them to bunch up into a smaller and tighter cluster as shown in Figure 5 . The purpose of this behavior is to increase the number of fish that will be eaten when an attack is made.

The attack will be more or less successful

This circling behavior on the part of the predator continues until the player clicks the Attack button, at which time the predator enters the attack mode and makes an attack on the cluster as shown in Figure 1 . If the player clicks the Attack button too early, or doesn't wait long enough between attacks, the prey fish will be in a loose cluster and the predator will eat veryfew fish during the attack.

The predator always has an impact

Even when the predator is not in attack mode, its presence has a significant effect on the behavior of the school of prey fish. As the predator swims aroundthe prey fish, they tend to bunch up into a smaller and tighter cluster, but when the predator swims too close, the prey fish tend to panic and scatter,breaking up the tight cluster as shown in Figure 6 .

Therefore, if the player waits too long to click the Attack button or waits too long between attacks, the predator will have spiraled in so close tothe prey fish that they will break formation and begin to scatter, making it difficult for the predator to eat a large number of fish during the next attack.This is the other disadvantage of waiting too long to attack that I mentioned earlier .

Formation starting to break up due to closeness of the predator

Figure 6 shows the formation starting to break up because the predator has strayed too close to the cluster of prey fish. (The fish in the upper right of the formation have pulled out of the cluster and have started to flee thepredator.)

Figure 6 Formation starting to break up due to closeness of the predator.

Missing image.

An effective defense mechanism

The prey fish have a fairly effective defense mechanism and can do a reasonably good job of escaping the predator. The predator can increase the oddsof catching the prey fish by attacking very fast. (You can modify the code that controls the speed of the attack.) If the predator goes into the formation slowly, the prey fish will simply run away as is starting to be thecase in Figure 6 .

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