Table of contents
- Preface
- Preview
- General background information
- Discussion and sample code
- Run the program
- Summary
- Conclusion
- Miscellaneous
- Complete program listing
Preface
This module is one in a collection of modules designed to teach you about the anatomy of a game engine.
Although the modules in this collection will concentrate on the Java game library named Slick2D, theconcepts involved and the knowledge that you will gain is applicable to different game engines written in different programming languages as well.
The purpose of this module is to teach you how to write a program that simulates the spread of a fatal communicable disease within a population (a pandemic) .
Viewing tip
I recommend that you open another copy of this module in a separate browser window and use the following links to easily find and view the imagesand listings while you are reading about them.
Figures
- Figure 1 . The disease has gained a foothold.
- Figure 2 . The disease has spread into the population.
- Figure 3 . The disease has receded after killing many in the population.
Listings
- Listing 1 . Beginning of the class named Slick0220.
- Listing 2 . Beginning of the init method.
- Listing 3 . Remainder of the init method.
- Listing 4 . Beginning of the update method.
- Listing 5 . Process collisions.
- Listing 6 . Make a cleanup pass.
- Listing 7 . The render method.
- Listing 8 . Source code for Slick0220.
- Listing 9 . Source code for Sprite01.
Preview
In an earlier module titled Slick0210: Collision detection and sound , you learned how to write a non-trivial program involving thousands ofsprites, collision detection, and sound. We will take that concept considerably further in this module by writing a program that simulates thespread of a fatal communicable disease within a population (a pandemic) and displays the results in animated graphic form.
The disease has gained a foothold
Figure 1 shows the result of inserting a single infected sprite into a population of healthy sprites. Healthy sprites arecolored green and infected sprites are colored red.
By the time the screen shot in Figure 1 was taken, the disease had gained a foothold, several other sprites had become infected, andeight of the original 1000 sprites had died, leaving only 992 live sprites including the seven that are infected.
Figure 1 . The disease has gained a foothold. |
---|
|
The disease has spread into the population
Figure 2 shows the situation some time later when the disease has spread considerably. By this point, many sprites have becomeinfected (and are infecting others) and only 763 of the original 1000 sprites are still alive including those that are infected.
Figure 2 . The disease has spread into the population. |
---|
|
The disease has receded
Figure 3 shows the situation much later. For the set of properties used to run this simulation, the pandemic appears to be receding with 341 of the 1000 original spritesstill alive.