examples/transformertest/TransformerTest

From FANG

Revision as of 17:59, 19 September 2009 by Jam Jenkins (Talk | contribs)
(diff) ← Older revision | Current revision (diff) | Newer revision → (diff)
Jump to: navigation, search

01 package examples.transformertest;
02 //start auto-imports
03 //end auto-imports
04 
05 import java.awt.geom.*;
06 
07 import fang2.attributes.*;
08 import fang2.core.*;
09 import fang2.sprites.*;
10 import fang2.transformers.*;
11 
12 
13 /**This class is a good utility for 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 this class
17  * before adding them to more complex game
18  * code.
19  @author Jam Jenkins
20  */
21 public class TransformerTest extends Game
22 {
23   /**sprite to move*/
24   private Sprite sprite;
25 
26   /**makes and adds the sprite to the screen*/
27   public void setup()
28   {
29     makeSprites();
30     addSprites();
31     setHelp("resources/TransformerTestHelp.txt");
32   }
33 
34 
35   /**makes an ellipse and sets it in
36    * motion given a transformer */
37   private void makeSprites()
38   {
39     Sprite pentagon=new PolygonSprite(5);
40     pentagon.setScale(0.5);
41     pentagon.setLocation(0.50.5);
42     addSprite(pentagon);
43 
44     sprite=new OvalSprite(10.5);
45     sprite.setScale(0.2);
46     sprite.setLocation(0.50.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=new 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(true);
57 
58     //this makes a transformer that has no rotation
59     SpinTransformer spinner=new 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=new PulseTransformer(0.81.21);
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   }
74 
75   /**adds the sprite to the screen*/
76   private void addSprites()
77   {
78     addSprite(sprite);
79   }
80 
81   public static void main(String[] argv)
82   {
83     new TransformerTest().runAsApplication();
84   }
85 }
86 
87 //Uploaded on Sat Sep 19 13:58:06 EDT 2009


Download/View examples/transformertest/TransformerTest.java





Views
Personal tools
Add to 
del.icio.usAdd to 
diggAdd to 
FacebookAdd to 
favoritesAdd to 
GoogleAdd to 
MySpaceAdd to 
PrintAdd to 
SlashdotAdd to 
StumbleUponAdd to 
Twitter

Games
Games