<< Chapter < Page | Chapter >> Page > |
I will also provide exercises for you to complete on your own at the end of the module. The exercises will concentrate on the material that you have learnedin this module and previous modules.
Much of the code in the library remains unchanged. I explained that code in the previous module and I won't repeat that explanation in this module. Rather,in this module, I will concentrate on explaining the modifications that I made to the library.
A complete listing of the modified game-programming library named GM2D02 is provided in Listing 26 .
This library is an update of the earlier game-math library named GM2D01 . This update added the following new capabilities:
Constructors were updated to ensure that existing points, vectors, and lines are not corrupted by using the new set methods to change the values in the ColMatrix and/or Point objects originally used to construct the points, vectors, and lines. The updated constructors create and saveclones of the ColMatrix and/or Point objects originally used to define the Point , Vector , and/or Line objects.
I will explain the new code in the library in conjunction with the explanations of the programs named PointLine03 and PointLine04 .
A complete listing of the program named PointLine03 is provided in Listing 27 .
This program illustrates the use of draw methods that were added to the GM2D02 game-math library to produce visual manifestations of Point , Line , and Vector objects instantiated from classes in the game-math library. The program also illustrates drawing on off-screenimages and then copying those images to a Canvas object in an overridden paint method.
As mentioned earlier, this program produces the screen output shown in Figure 1 .
Beginning of the class named PointLine03 and the class named GUI
Listing 1 shows the beginning of the class named PointLine03 (including the main method) and the beginning of the class named GUI .
Listing 1 . Beginning of the class named PointLine03 and the class named GUI. |
---|
class PointLine03{
public static void main(String[]args){
GUI guiObj = new GUI();}//end main
}//end controlling class PointLine03//======================================================//
class GUI extends JFrame{//Specify the horizontal and vertical size of a JFrame
// object.int hSize = 400;
int vSize = 200;Image osiA;//one off-screen image
Image osiB;//another off-screen imageint osiWidth;//off-screen image width
int osiHeight;//off-screen image heightMyCanvas myCanvas;//a subclass of Canvas |
Notification Switch
Would you like to follow the 'Game 2302 - mathematical applications for game development' conversation and receive update notifications?