|
001 packagepackage is used to name the directory or folder a class is in Charles;
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 Charles
010 */
011 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
012 {open braces start code blocks and must be matched with a close brace
013 privateprivate is used to restrict access to the current class only StringSprite title;
014 privateprivate is used to restrict access to the current class only String helptxt;
015 privateprivate is used to restrict access to the current class only PolygonSprite poly;
016 privateprivate is used to restrict access to the current class only OutlineSprite border;
017 privateprivate is used to restrict access to the current class only OvalSprite ball;
018 privateprivate is used to restrict access to the current class only ImageSprite pump1, witch, explode;
019 privateprivate is used to restrict access to the current class only LineSprite lbar, rbar;
020 privateprivate is used to restrict access to the current class only Sound door=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor Sound("Door_cre.wav");;
021
022 /**sets up the game*/
023 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value setup()
024 {open braces start code blocks and must be matched with a close brace
025 makeHelp();
026 makeAndAddBorder();
027 makeBall();
028 makeAndAddLeftBar();
029 makeAndAddRightBar();
030 makeAndAddPumpkins();
031 makeAndAddWitch();
032 makeAndAddExplosion();
033 makeAndAddTitle();
034 blowUpWitch();
035
036 playSoundImmediately();
037 door.setVolume(0.2);
038
039 }close braces end code blocks and must match an earlier open brace
040 /**Creates the title of the program and the authers*/
041 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value makeAndAddTitle()
042 {open braces start code blocks and must be matched with a close brace
043 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 By: Charles and Chanelle");
044 title.setLocation(0.5, 0.1);
045 title.setSize(0.9);
046 title.setColor(Palette.getColor("Purple"));
047 addSprite(title);
048 }close braces end code blocks and must match an earlier open brace
049 /**Creates the text displayed in the help menu*/
050 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value makeHelp()
051 {open braces start code blocks and must be matched with a close brace
052 helptxt=this assignment operator makes the left side equal to the right side
053 "*To begin click the Start button.<br>"+adds two numbers together or concatenates Strings together
054 "*Click anywhere in the green box to release your ball.<br>"+adds two numbers together or concatenates Strings together
055 "*Press the B key on your keyboard to get a suprise!!";
056 setHelpText(helptxt);
057 }close braces end code blocks and must match an earlier open brace
058 /**Creates the border forfor is a looping structure for repeatedly executing a block of code the game area where the ball will bounce in*/
059 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value makeAndAddBorder()
060 {open braces start code blocks and must be matched with a close brace
061 poly=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor PolygonSprite(0.01, 0.15, 0.99, 0.15, 0.99, 0.99, 0.01, 0.99);
062 border=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor OutlineSprite(poly);
063 border.setSize(0.99);
064 border.setLineThickness(0.05);
065 border.setLocation(0.5, 0.55);
066 border.setColor(Palette.getColor("Green"));
067 addSprite(border);
068 }close braces end code blocks and must match an earlier open brace
069 /** creates the ball and projectile transformer that bounces within the game area*/
070 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value makeBall()
071 {open braces start code blocks and must be matched with a close brace
072 ball=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor OvalSprite(1,1);
073 ball.setSize(.05);
074 ball.setColor(Palette.getColor("Purple"));
075 doubledouble is the type for numbers that can contain decimal fractions x=this assignment operator makes the left side equal to the right siderandom.nextInt(2);
076 ifif executes the next statement only if the condition in parenthesis evaluates to true(x==this is the comparison operator which evaluates to true if both sides are the same0)
077 {open braces start code blocks and must be matched with a close brace
078 x=this assignment operator makes the left side equal to the right side-0.1;
079 }close braces end code blocks and must match an earlier open brace
080 elseelse is what happens when the if condition is false
081 {open braces start code blocks and must be matched with a close brace
082 x=this assignment operator makes the left side equal to the right side0.1;
083 }close braces end code blocks and must match an earlier open brace
084 ProjectileTransformer bounce=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor ProjectileTransformer(x, -0.35);
085 ball.setTracker(bounce);
086 }close braces end code blocks and must match an earlier open brace
087
088 /**creates the bar that occupies the left side of the game area*/
089 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value makeAndAddLeftBar()
090 {open braces start code blocks and must be matched with a close brace
091 lbar=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor LineSprite(1, 1, 1, 1.5);
092 lbar.setSize(0.1);
093 lbar.setLineThickness(0.1);
094 lbar.setColor(Palette.getColor("Fire Brick"));
095 lbar.setLocation(0.15,0.7);
096 OutlineTransformer track1;
097 track1=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor OutlineTransformer(0.12, 0.15, 0.7, 0.2, 0.5, 0.3, 0.7, 0.15, 0.7);
098 track1.setLooping(truetrue is the boolean value that is the opposite of false);
099 lbar.addTransformer(track1);
100 addSprite(lbar);
101 }close braces end code blocks and must match an earlier open brace
102
103 /**creates the bar that occupies the right side of the game area*/
104 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value makeAndAddRightBar()
105 {open braces start code blocks and must be matched with a close brace
106 rbar=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor LineSprite(1, 1, 1, 1.5);
107 rbar.setSize(0.1);
108 rbar.setLineThickness(0.1);
109 rbar.setColor(Palette.getColor("Fire Brick"));
110 rbar.setLocation(0.85,0.65);
111 OutlineTransformer track2;
112 track2=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor OutlineTransformer(0.13, 0.2, 0.5, 0.13, 0.7, 0.2, 0.5);
113 track2.setLooping(truetrue is the boolean value that is the opposite of false);
114 rbar.addTransformer(track2);
115 addSprite(rbar);
116 }close braces end code blocks and must match an earlier open brace
117
118 /**creates the pumkin image that spins in the center of the game area*/
119 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value makeAndAddPumpkins()
120 {open braces start code blocks and must be matched with a close brace
121 pump1=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor ImageSprite("Pumpkin.JPG");
122 pump1.setLocation(.5, 0.5);
123 pump1.setSize(0.1);
124 addSprite(pump1);
125
126 Spinner spinRight;
127 spinRight=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor Spinner(0);
128 spinRight.setRotationDegrees(45);
129
130 pump1.addTransformer(spinRight);
131 }close braces end code blocks and must match an earlier open brace
132
133 /**creates the witch image that moves across the top of the game area*/
134 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value makeAndAddWitch()
135 {open braces start code blocks and must be matched with a close brace
136 witch=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor ImageSprite("Witch.jpg");
137 OutlineTransformer flight;
138 flight=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor OutlineTransformer(0.2,0.1, 0.1,0.8, 0.1, 0.1, 0.1);
139 flight.setLooping(truetrue is the boolean value that is the opposite of false);
140 witch.addTransformer(flight);
141 witch.setLocation(0.15, 0.24);
142 witch.setSize(.15);
143 addSprite(witch);
144 }close braces end code blocks and must match an earlier open brace
145
146 /**creates the explosion image that appears when the "b" key is pressed*/
147 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value makeAndAddExplosion()
148 {open braces start code blocks and must be matched with a close brace
149 explode=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor ImageSprite("Explode.png");
150 explode.setLocation(.5, 0.5);
151 explode.setSize(0.3);
152 addSprite(explode);
153 explode.setVisible(falsefalse is a value for the boolean type and means not true);
154 }close braces end code blocks and must match an earlier open brace
155 /**makes the ball bounce off of the selected objects*/
156 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value handleBounce()
157 {open braces start code blocks and must be matched with a close brace
158 ball.bounceOffOf(border);
159 ball.bounceOffOf(lbar);
160 ball.bounceOffOf(rbar);
161 ball.bounceOffOf(witch);
162 ball.bounceOffOf(pump1);
163
164 }close braces end code blocks and must match an earlier open brace
165 /** makes the delayed release of the ball*/
166 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
167 {open braces start code blocks and must be matched with a close brace
168 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value act()
169 {open braces start code blocks and must be matched with a close brace
170 addSprite(ball);
171 }close braces end code blocks and must match an earlier open brace
172 }close braces end code blocks and must match an earlier open brace
173
174 /** replaces the pumpkin image with the explosion image*/
175 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value blowUpWitch()
176 {open braces start code blocks and must be matched with a close brace
177 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'b')
178 {open braces start code blocks and must be matched with a close brace
179 pump1.setVisible(falsefalse is a value for the boolean type and means not true);
180 explode.setVisible(truetrue is the boolean value that is the opposite of false);
181 }close braces end code blocks and must match an earlier open brace
182 }close braces end code blocks and must match an earlier open brace
183
184 /**creates the door creaking sound when game starts*/
185 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value makeDoorCreek()
186 {open braces start code blocks and must be matched with a close brace
187
188 playSoundImmediately();
189 door.setVolume(0.2);
190 }close braces end code blocks and must match an earlier open brace
191 /**handle input and game events*/
192 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value advance()
193 {open braces start code blocks and must be matched with a close brace
194 handleBounce();
195 blowUpWitch();
196 /** sets up the delay forfor is a looping structure for repeatedly executing a block of code the ball release*/
197 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)
198 {open braces start code blocks and must be matched with a close brace
199 ball.setLocation(getClick2D());
200 schedule(newnew is used to create objects by calling the constructor DelayedResponse(), 1.5);
201 }close braces end code blocks and must match an earlier open brace
202 }close braces end code blocks and must match an earlier open brace
203 }close braces end code blocks and must match an earlier open brace
|