From FANG
|
01 packagepackage is used to name the directory or folder a class is in examples.transformertest;
02 //start auto-imports
03 //end auto-imports
04
05 importimport means to make the classes and/or packages available in this program java.awt.geom.*;
06
07 importimport means to make the classes and/or packages available in this program fang2.attributes.*;
08 importimport means to make the classes and/or packages available in this program fang2.core.*;
09 importimport means to make the classes and/or packages available in this program fang2.sprites.*;
10 importimport means to make the classes and/or packages available in this program fang2.transformers.*;
11
12
13 /**This classclass is a group of fields and methods used for making objects is a good utility forfor is a looping structure for repeatedly executing a block of code testing
14 * out newly written transformers to make sure they
15 * move properly. It's usually easier to
16 * first test out the transformers using thisthis means the current object (the implicit parameter) classclass is a group of fields and methods used for making objects
17 * before adding them to more complex game
18 * code.
19 * @authornull Jam Jenkins
20 */
21 publicpublic is used to indicate unrestricted access (any other class can have access) classclass is a group of fields and methods used for making objects TransformerTest extendsextends means to customize or extend the functionality of a class Game
22 {open braces start code blocks and must be matched with a close brace
23 /**sprite to move*/
24 privateprivate is used to restrict access to the current class only Sprite sprite;
25
26 /**makes and adds the sprite to the screen*/
27 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value setup()
28 {open braces start code blocks and must be matched with a close brace
29 makeSprites();
30 addSprites();
31 setHelp("resources/TransformerTestHelp.txt");
32 }close braces end code blocks and must match an earlier open brace
33
34
35 /**makes an ellipse and sets it in
36 * motion given a transformer */
37 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value makeSprites()
38 {open braces start code blocks and must be matched with a close brace
39 Sprite pentagon=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor PolygonSprite(5);
40 pentagon.setScale(0.5);
41 pentagon.setLocation(0.5, 0.5);
42 addSprite(pentagon);
43
44 sprite=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor OvalSprite(1, 0.5);
45 sprite.setScale(0.2);
46 sprite.setLocation(0.5, 0.25);
47 sprite.setColor(getColor("yellow"));
48
49 //this makes a transformer that traces the outline of a sprite
50 //the second parameter is how fast to move - 0.5 screens/second
51 OutlineTransformer move=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor OutlineTransformer(pentagon, 0.5);
52
53 //the default behavior of the OutlineTransformer is to stop
54 //moving once the ouline is traced. This makes it continue
55 //to trace the sprite indefinitely
56 move.setLooping(truetrue is the boolean value that is the opposite of false);
57
58 //this makes a transformer that has no rotation
59 SpinTransformer spinner=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor SpinTransformer(0);
60
61 //this makes the sprite spin at 1 revolution/second
62 spinner.setAngularVelocityRevolutions(1);
63
64 //make the sprite pulse between 120% and 80% its original size
65 PulseTransformer pulse=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor PulseTransformer(0.8, 1.2, 1);
66
67 //transformers act upon the sprites they are added to
68 //multiple transformers can be added to the same sprite
69 //and one transformer can be added to multiple sprites
70 sprite.addTransformer(move);
71 sprite.addTransformer(spinner);
72 sprite.addTransformer(pulse);
73 }close braces end code blocks and must match an earlier open brace
74
75 /**adds the sprite to the screen*/
76 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value addSprites()
77 {open braces start code blocks and must be matched with a close brace
78 addSprite(sprite);
79 }close braces end code blocks and must match an earlier open brace
80
81 publicpublic is used to indicate unrestricted access (any other class can have access) staticstatic means that an instance is not required for access (class level access) voidvoid means the method does not return a value mainThe main method is the place where applications begin executing.(String[brackets are typically used to declare, initialize and index (indicate which element of) arrays]brackets are typically used to declare, initialize and index (indicate which element of) arrays argv)
82 {open braces start code blocks and must be matched with a close brace
83 newnew is used to create objects by calling the constructor TransformerTest().runAsApplication();
84 }close braces end code blocks and must match an earlier open brace
85 }close braces end code blocks and must match an earlier open brace
86
87 //Uploaded on Sat Sep 19 13:58:06 EDT 2009
|
Download/View examples/transformertest/TransformerTest.java