|
001 packagepackage is used to name the directory or folder a class is in Brandon;
002
003 importimport means to make the classes and/or packages available in this program wiki.Wiki;
004 importimport means to make the classes and/or packages available in this program fang.*;
005 importimport means to make the classes and/or packages available in this program java.awt.*;
006 importimport means to make the classes and/or packages available in this program java.awt.geom.*;
007
008 /**
009 * Class: ITEC2120
010 * Assignment: Interactive Art
011 * Author: Brandon Adams
012 * Due Date: 02/19/08
013 */
014 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 GameLoop
015 {open braces start code blocks and must be matched with a close brace
016 /**Rectangle sprite that serves as a background*/
017 privateprivate is used to restrict access to the current class only RectangleSprite background;
018
019 /**Text strings forfor is a looping structure for repeatedly executing a block of code the author and title information*/
020 privateprivate is used to restrict access to the current class only StringSprite title, author;
021
022 /**Booleans forfor is a looping structure for repeatedly executing a block of code toggling the help screen, sprite action, and background changing*/
023 privateprivate is used to restrict access to the current class only booleanboolean is a type that is either true or false info, run, holdBG, up;
024
025 /**Integer used in the fading process*/
026 privateprivate is used to restrict access to the current class only intint is the type for whole numbers and it is short for integer counter, rgb, r, g, b;
027
028 /**Starts the game by creating and initializing sprites, and setting other applet/object properties.*/
029 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value startGame()
030 {open braces start code blocks and must be matched with a close brace
031 makeShapes();
032 makeStrings();
033
034 info =this assignment operator makes the left side equal to the right side falsefalse is a value for the boolean type and means not true;
035 run =this assignment operator makes the left side equal to the right side holdBG =this assignment operator makes the left side equal to the right side up =this assignment operator makes the left side equal to the right side truetrue is the boolean value that is the opposite of false;
036
037 //holdBG =false;
038
039 counter =this assignment operator makes the left side equal to the right side rgb =this assignment operator makes the left side equal to the right side r =this assignment operator makes the left side equal to the right side g =this assignment operator makes the left side equal to the right side b =this assignment operator makes the left side equal to the right side 0;
040
041 canvas.addSprite(background, title, author);
042
043 setHelpText("H = Show/hide Help <br><br> R = Restart <br><br> P = Pause/Unpause <br><br> S = Sound On/Off");
044
045 scheduleAbsolute(newnew is used to create objects by calling the constructor Hold(), 1);
046 }close braces end code blocks and must match an earlier open brace
047
048 /**Creates and initializes geometric shapes*/
049 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value makeShapes()
050 {open braces start code blocks and must be matched with a close brace
051 background =this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor RectangleSprite(1, 1);
052 background.setLocation(0.5, 0.5);
053 background.setColor(Color.BLACK);
054 }close braces end code blocks and must match an earlier open brace
055
056 /**Creates and initializes strings*/
057 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value makeStrings()
058 {open braces start code blocks and must be matched with a close brace
059 title =this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor StringSprite(" Title: Interactive Art");
060 title.setHeight(0.03);
061 title.setColor(Color.WHITE);
062 title.leftJustify();
063 title.topJustify();
064 title.setLocation(0, 0);
065
066 author =this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor StringSprite("Author: Brandon Adams ");
067 author.setHeight(0.03);
068 author.setColor(Color.WHITE);
069 author.rightJustify();
070 author.topJustify();
071 author.setLocation(1, 0);
072 }close braces end code blocks and must match an earlier open brace
073
074 /**Called 25 times per second to control applet's functions*/
075 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value advanceFrame(doubledouble is the type for numbers that can contain decimal fractions timePassed)
076 {open braces start code blocks and must be matched with a close brace
077 ifif executes the next statement only if the condition in parenthesis evaluates to true(run)
078 {open braces start code blocks and must be matched with a close brace
079 ifif executes the next statement only if the condition in parenthesis evaluates to true(!this is the not operator, which changes true to false and false to trueholdBG)
080 fade(background, 10);
081
082 title.setColor(newnew is used to create objects by calling the constructor Color(rand(255), rand(255), rand(255)));
083 author.setColor(newnew is used to create objects by calling the constructor Color(rand(255), rand(255), rand(255)));
084 }close braces end code blocks and must match an earlier open brace
085
086 handleKeys(getPlayer().getKeyboard().getLastKey());
087 }close braces end code blocks and must match an earlier open brace
088
089 /**Calls various control methods in response to certain key presses*/
090 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value handleKeys(charchar is the type for a single letter or symbol and it is short for character key)
091 {open braces start code blocks and must be matched with a close brace
092 switchswitch is used with case for multiple alternatives (like if/else if...) (key)
093 {open braces start code blocks and must be matched with a close brace
094 casecase is used with switch for multiple alternatives (like if/else if...) 'r': scheduleRelative(newnew is used to create objects by calling the constructor Reset(), 1); breakbreak terminates the loop immediately;
095 casecase is used with switch for multiple alternatives (like if/else if...) 'p': run =this assignment operator makes the left side equal to the right side !this is the not operator, which changes true to false and false to truerun; breakbreak terminates the loop immediately;
096 casecase is used with switch for multiple alternatives (like if/else if...) 's': toggleAudible(); breakbreak terminates the loop immediately;
097 casecase is used with switch for multiple alternatives (like if/else if...) 'h': info =this assignment operator makes the left side equal to the right side !this is the not operator, which changes true to false and false to trueinfo; help.setVisible(info); breakbreak terminates the loop immediately;
098 }close braces end code blocks and must match an earlier open brace
099 }close braces end code blocks and must match an earlier open brace
100
101 /**Toggles holdBG on and off every second to control background's color*/
102 privateprivate is used to restrict access to the current class only classclass is a group of fields and methods used for making objects Hold implementsimplements means providing method bodies for the methods declared in the corresponding interface Alarm
103 {open braces start code blocks and must be matched with a close brace
104 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value alarm()
105 {open braces start code blocks and must be matched with a close brace
106 ifif executes the next statement only if the condition in parenthesis evaluates to true(run)
107 {open braces start code blocks and must be matched with a close brace
108 holdBG =this assignment operator makes the left side equal to the right side !this is the not operator, which changes true to false and false to trueholdBG;
109 rgb =this assignment operator makes the left side equal to the right side rand(2);
110 r =this assignment operator makes the left side equal to the right side rand(255);
111 g =this assignment operator makes the left side equal to the right side rand(255);
112 b =this assignment operator makes the left side equal to the right side rand(255);
113 counter =this assignment operator makes the left side equal to the right side 0;
114 }close braces end code blocks and must match an earlier open brace
115
116 scheduleRelative(thisthis means the current object (the implicit parameter), 1);
117 }close braces end code blocks and must match an earlier open brace
118 }close braces end code blocks and must match an earlier open brace
119
120 /**Waits one second to restart after R is pressed*/
121 privateprivate is used to restrict access to the current class only classclass is a group of fields and methods used for making objects Reset implementsimplements means providing method bodies for the methods declared in the corresponding interface Alarm
122 {open braces start code blocks and must be matched with a close brace
123 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value alarm()
124 {open braces start code blocks and must be matched with a close brace
125 startOver();
126 }close braces end code blocks and must match an earlier open brace
127 }close braces end code blocks and must match an earlier open brace
128
129 /**Returns a random integer value between 0 and limit*/
130 privateprivate is used to restrict access to the current class only intint is the type for whole numbers and it is short for integer rand(intint is the type for whole numbers and it is short for integer limit)
131 {open braces start code blocks and must be matched with a close brace
132 intint is the type for whole numbers and it is short for integer val =this assignment operator makes the left side equal to the right side (intint is the type for whole numbers and it is short for integer)Math.round(Math.random() * limit);
133 returnreturn means to provide the result of the method and/or cease execution of the method immediately val;
134 }close braces end code blocks and must match an earlier open brace
135
136 /**Fades a sprite's color back and forth from black to white, at a multiplied rate*/
137 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value fade(Sprite sprite, intint is the type for whole numbers and it is short for integer mult)
138 {open braces start code blocks and must be matched with a close brace
139 forfor is a looping structure for repeatedly executing a block of code(intint is the type for whole numbers and it is short for integer i =this assignment operator makes the left side equal to the right side 0; i < mult; i++this is the increment operator, which increases the variable by 1)
140 {open braces start code blocks and must be matched with a close brace
141 ifif executes the next statement only if the condition in parenthesis evaluates to true(up)
142 {open braces start code blocks and must be matched with a close brace
143 ifif executes the next statement only if the condition in parenthesis evaluates to true((counter +adds two numbers together or concatenates Strings together mult) > 255)
144 {open braces start code blocks and must be matched with a close brace
145 counter =this assignment operator makes the left side equal to the right side 255;
146 up =this assignment operator makes the left side equal to the right side falsefalse is a value for the boolean type and means not true;
147 }close braces end code blocks and must match an earlier open brace
148 elseelse is what happens when the if condition is false
149 counter++this is the increment operator, which increases the variable by 1;
150 }close braces end code blocks and must match an earlier open brace
151 elseelse is what happens when the if condition is false
152 {open braces start code blocks and must be matched with a close brace
153 ifif executes the next statement only if the condition in parenthesis evaluates to true((counter - mult) < 0)
154 {open braces start code blocks and must be matched with a close brace
155 counter =this assignment operator makes the left side equal to the right side 0;
156 up =this assignment operator makes the left side equal to the right side truetrue is the boolean value that is the opposite of false;
157 }close braces end code blocks and must match an earlier open brace
158 elseelse is what happens when the if condition is false
159 counter--this is the decrement operator, which decreases the variable by 1;
160 }close braces end code blocks and must match an earlier open brace
161 }close braces end code blocks and must match an earlier open brace
162
163 switchswitch is used with case for multiple alternatives (like if/else if...) (rgb)
164 {open braces start code blocks and must be matched with a close brace
165 casecase is used with switch for multiple alternatives (like if/else if...) 0: sprite.setColor(newnew is used to create objects by calling the constructor Color(counter, g, b)); breakbreak terminates the loop immediately;
166 casecase is used with switch for multiple alternatives (like if/else if...) 1: sprite.setColor(newnew is used to create objects by calling the constructor Color(r, counter, b)); breakbreak terminates the loop immediately;
167 casecase is used with switch for multiple alternatives (like if/else if...) 2: sprite.setColor(newnew is used to create objects by calling the constructor Color(r, g, counter)); breakbreak terminates the loop immediately;
168 }close braces end code blocks and must match an earlier open brace
169 }close braces end code blocks and must match an earlier open brace
170 }close braces end code blocks and must match an earlier open brace
|