From ggc
|
001 packagepackage is used to name the directory or folder a class is in Wilson;
002
003 importimport means to make the classes and/or packages available in this program fang.*;
004 importimport means to make the classes and/or packages available in this program java.awt.*;
005 importimport means to make the classes and/or packages available in this program java.awt.geom.*;
006
007 /**
008 * All about my game.
009 * @authorthis is the Javadoc tag for documenting who created the source code Wilson Green
010 * Used some of your example code as, well examples.
011 */
012 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 InteractiveArt extendsextends means to customize or extend the functionality of a class Game
013 {open braces start code blocks and must be matched with a close brace
014 OutlineSprite boundary;
015 OvalSprite ballSprite;
016 ProjectileTransformer projectile;
017 doubledouble is the type for numbers that can contain decimal fractions i=this assignment operator makes the left side equal to the right side0.01;
018 /**
019 *This classclass is a group of fields and methods used for making objects sets up everything
020 *Implements all of the different methods in thisthis means the current object (the implicit parameter) program
021 */
022 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value setup()
023 {open braces start code blocks and must be matched with a close brace
024 helpSetup();
025 titleSetup();
026 spiningSun();
027 boundary();
028 ballSprite();
029 }close braces end code blocks and must match an earlier open brace
030 /**
031 * This classclass is a group of fields and methods used for making objects makes the help file
032 *
033 */
034 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value helpSetup()
035 {open braces start code blocks and must be matched with a close brace
036 String helpText=this assignment operator makes the left side equal to the right side
037 "Click on the ball to change it to white after 2.5 seconds"+adds two numbers together or concatenates Strings together
038 "or press the y key, for yellow";
039 setHelpText(helpText);
040 }close braces end code blocks and must match an earlier open brace
041 /**
042 *Creates a string forfor is a looping structure for repeatedly executing a block of code the title and justifys it to the top and left.
043 *
044 */
045 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value titleSetup()
046 {open braces start code blocks and must be matched with a close brace
047 StringSprite title=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor StringSprite("Interactive Art! (Wilson Green)");
048 title.leftJustify();
049 title.topJustify();
050 title.setWidth(1);
051 addSprite(title);
052 }close braces end code blocks and must match an earlier open brace
053 /**
054 *Creates an image with "sun.gif" and sets its location, also makes it spin with a transformer
055 *
056 */
057 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value spiningSun()
058 {open braces start code blocks and must be matched with a close brace
059 ImageSprite sun=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor ImageSprite("Sun.gif");
060 Spinner spinner=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor Spinner(0);
061 sun.setLocation(.5,.2);
062 sun.setSize(.2);
063 addSprite(sun);
064 spinner.setRotationDegrees(45);
065 sun.addTransformer(spinner);
066 }close braces end code blocks and must match an earlier open brace
067 /**
068 *This method creates the boundry forfor is a looping structure for repeatedly executing a block of code which the ballSprite bounces around in
069 *
070 */
071 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value boundary()
072 {open braces start code blocks and must be matched with a close brace
073 boundary=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor OutlineSprite(newnew is used to create objects by calling the constructor PolygonSprite(6));
074 boundary.setSize(0.9);
075 boundary.setLineThickness(i);
076 boundary.setLocation(0.5, 0.5);
077 addSprite(boundary);
078 }close braces end code blocks and must match an earlier open brace
079 /**
080 *Creates the ballSprite that bounces around in the center, uses a transformer to bounce back an forth.
081 *
082 */
083 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value ballSprite()
084 {open braces start code blocks and must be matched with a close brace
085 ballSprite=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor OvalSprite(0.1, 0.1);
086 ballSprite.setLocation(0.5, 0.5);
087 addSprite(ballSprite);
088 projectile=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor ProjectileTransformer(0.1, 0.25);
089 ballSprite.setTracker(projectile);
090 }close braces end code blocks and must match an earlier open brace
091 /**
092 *Handles the collisions (hence the name) between the bondary and the ballSprite, and makes it veer to a 145 degree angle when hitting a boundary
093 *
094 */
095 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value handleCollisions()
096 {open braces start code blocks and must be matched with a close brace
097 ifif executes the next statement only if the condition in parenthesis evaluates to true(ballSprite.intersects(boundary))
098 {open braces start code blocks and must be matched with a close brace
099 Vector2D vector=this assignment operator makes the left side equal to the right sideprojectile.getVector2D();
100 vector.turnDegrees(145);
101 projectile.setVector2D(vector);
102 }close braces end code blocks and must match an earlier open brace
103 }close braces end code blocks and must match an earlier open brace
104 /**
105 *When clicking on the screen thisthis means the current object (the implicit parameter) delays the response to turn the ball white
106 *
107 */
108 classclass is a group of fields and methods used for making objects DelayedResponse extendsextends means to customize or extend the functionality of a class TimedAction
109 {open braces start code blocks and must be matched with a close brace
110 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value act()
111 {open braces start code blocks and must be matched with a close brace
112 ballSprite.setColor(getColor("white"));
113 }close braces end code blocks and must match an earlier open brace
114 }close braces end code blocks and must match an earlier open brace
115
116 /**
117 *Handles game inputs, such as clicking anywhere to turn the ball white after 2.5 seconds,
118 *or clicking y to turn the ball yellow.
119 */
120 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value advance()
121 {open braces start code blocks and must be matched with a close brace
122 handleCollisions();
123 ifif executes the next statement only if the condition in parenthesis evaluates to true(getClick2D()!=this is the not equals operator which evaluates to true if both sides are differentnullnull is the value used to refer to a non-existant object)
124 {open braces start code blocks and must be matched with a close brace
125 schedule(newnew is used to create objects by calling the constructor DelayedResponse(), 2.5);
126 }close braces end code blocks and must match an earlier open brace
127 ifif executes the next statement only if the condition in parenthesis evaluates to true(getKeyPressed()==this is the comparison operator which evaluates to true if both sides are the same'y')
128 {open braces start code blocks and must be matched with a close brace
129 ballSprite.setColor(getColor("YELLOW"));
130 }close braces end code blocks and must match an earlier open brace
131 ifif executes the next statement only if the condition in parenthesis evaluates to true(i<.05)
132 {open braces start code blocks and must be matched with a close brace
133 i=this assignment operator makes the left side equal to the right sidei+adds two numbers together or concatenates Strings together.01;
134 boundary.setLineThickness(i);
135 }close braces end code blocks and must match an earlier open brace
136 elseelse is what happens when the if condition is false ifif executes the next statement only if the condition in parenthesis evaluates to true(i>=this evaluates to true if the left side is not less than the right side.05)
137 {open braces start code blocks and must be matched with a close brace
138 i=this assignment operator makes the left side equal to the right side.01;
139 boundary.setLineThickness(i);
140 }close braces end code blocks and must match an earlier open brace
141 }close braces end code blocks and must match an earlier open brace
142 }close braces end code blocks and must match an earlier open brace
|
Download/View Wilson/InteractiveArt.java