This page is optimized for mobile devices, if you would prefer the desktop version just click here

1.14 Game 2302-0140: our first 3d game program  (Page 19/27)

Copy off-screen image, insert time delay, etc

Listing 29 copies the off-screen image to the canvas and then causes the animation thread to sleep for 166 milliseconds.

Listing 29 . Copy off-screen image, insert time delay, etc.
//Copy the off-screen image to the canvas and then // do it all again.myCanvas.repaint();//Insert a time delay. Change the sleep time to // speed up or slow down the animation.try{ Thread.currentThread().sleep(166);}catch(Exception e){ e.printStackTrace();}//end catch }//end animation loop}//end run method }//end inner class named Animate

Listing 29 also signals the end of the animation loop, the end of the run method, and the end of the inner class named Animate .

That is all of the code that I will explain for this program. You can view the remainder of the code in Listing 31 near the end of the module.

Not a graphics program

Even though this program produces quite a lot of 3D graphics, and those graphics are important in the playing of the game, this is not a graphicsprogram. Rather, it is a 3D data-processing program that produces graphics as a side effect.

That is not to say that the graphics are unimportant. To the contrary, the graphics provide visual feedback to the player, which allows the player toimplement a strategy for success. Without graphics, the game would be very boring. However, the programming effort to produce the graphics represents analmost trivial part of the total programming effort for this game.

An almost trivial part of the programming effort

Exclusive of the code required to draw the large circle shown in Figure 1 , all of the graphics shown in Figure 1 , Figure 5 , Figure 6 , Figure 7 , and Figure 8 are produced by only two calls to game-math library methods named draw . In other words, all of the required graphics are produced by only two statementsin the program code. (One additional statement is required if you want to display the small circles that represent the locations of the prey fish.)

If those two statements are removed, the program will still compile and run, and the game can still be played. However, without visual feedback, the gameisn't much fun. The lack of visual feedback eliminates the strategy aspect of the game, causing it to be solely a game of chance. Be that as it may, with orwithout visual feedback, the player can still click the Start button and then repetitively click the Attack button until the display in the bottom-right of Figure 1 shows that all of the prey fish have been eaten.

Why am I telling you this?

I'm telling you this to emphasize that the essential skills required to program this game (and probably most games for that matter) consist of skills in mathematics, programming logic, and several other technical areas. Theability to produce on-screen graphics is necessary for an enjoyable game, but, (given a good game-math library that supports graphics) , producing on-screen graphics is almost a trivial part of the programming effort. In thiscollection of modules, you need to be mainly concentrating on learning mathematics and programming logic and treating the production of on-screengraphics almost as an afterthought.

<< Chapter < Page Page > Chapter >>

Read also:

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.
Jobilize.com uses cookies to ensure that you get the best experience. By continuing to use Jobilize.com web-site, you agree to the Terms of Use and Privacy Policy.