From FANG
|
001 packagepackage is used to name the directory or folder a class is in scg.ch09;
002
003 importimport means to make the classes and/or packages available in this program java.awt.Color;
004 importimport means to make the classes and/or packages available in this program java.awt.event.KeyEvent;
005
006 importimport means to make the classes and/or packages available in this program fang2.core.Game;
007 importimport means to make the classes and/or packages available in this program fang2.sprites.PolygonSprite;
008
009 /**
010 * The rescuer sprite. Keyboard driven (so advance takes care of
011 * movement).
012 */
013 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 Rescuer
014 extendsextends means to customize or extend the functionality of a class SpriteWithVelocity {open braces start code blocks and must be matched with a close brace
015 /** body of the rescuer */
016 privateprivate is used to restrict access to the current class only finalfinal means not changeable (often used for constants) PolygonSprite body;
017
018 /** the rescue ring (to be thrown by the rescuer) */
019 privateprivate is used to restrict access to the current class only finalfinal means not changeable (often used for constants) RescueRing ring;
020
021 /**
022 * Create a newnew is used to create objects by calling the constructor rescuer (along with a RescueRing).
023 *
024 * @paramthis is the Javadoc tag for documenting the purpose of parameters deltaX initial x-component of velocity forfor is a looping structure for repeatedly executing a block of code rescuer
025 * @paramthis is the Javadoc tag for documenting the purpose of parameters deltaY initial y-component of velocity forfor is a looping structure for repeatedly executing a block of code rescuer
026 * @paramthis is the Javadoc tag for documenting the purpose of parameters ringDeltaX initial x-component of velocity forfor is a looping structure for repeatedly executing a block of code rescue ring
027 * @paramthis is the Javadoc tag for documenting the purpose of parameters ringDeltaY initial y-component of velocity forfor is a looping structure for repeatedly executing a block of code rescue ring
028 */
029 publicpublic is used to indicate unrestricted access (any other class can have access) Rescuer(doubledouble is the type for numbers that can contain decimal fractions deltaX, doubledouble is the type for numbers that can contain decimal fractions deltaY, doubledouble is the type for numbers that can contain decimal fractions ringDeltaX,
030 doubledouble is the type for numbers that can contain decimal fractions ringDeltaY) {open braces start code blocks and must be matched with a close brace
031 super(deltaX, deltaY);
032 body =this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor PolygonSprite(3);
033 body.setScale(1.0);
034 addSprite(body);
035 ring =this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor RescueRing(thisthis means the current object (the implicit parameter), ringDeltaX, ringDeltaY);
036 }close braces end code blocks and must match an earlier open brace
037
038 /**
039 * Advance the rescuer according to the time that has passed
040 *
041 * @paramthis is the Javadoc tag for documenting the purpose of parameters dT seconds since last frame
042 */
043 @Override
044 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value advance(doubledouble is the type for numbers that can contain decimal fractions dT) {open braces start code blocks and must be matched with a close brace
045 Game curr =this assignment operator makes the left side equal to the right side Game.getCurrentGame();
046 ifif executes the next statement only if the condition in parenthesis evaluates to true (curr.keyPressed()) {open braces start code blocks and must be matched with a close brace
047 charchar is the type for a single letter or symbol and it is short for character key =this assignment operator makes the left side equal to the right side curr.getKeyPressed();
048 ifif executes the next statement only if the condition in parenthesis evaluates to true ((key ==this is the comparison operator which evaluates to true if both sides are the same KeyEvent.VK_LEFT) ||this is boolean or, meaning if either or both are true then the result is true (key ==this is the comparison operator which evaluates to true if both sides are the same KeyEvent.VK_KP_LEFT)) {open braces start code blocks and must be matched with a close brace
049 setVelocity(-Math.abs(getDeltaX()), getDeltaY());
050 super.advance(dT);
051 }close braces end code blocks and must match an earlier open brace elseelse is what happens when the if condition is false ifif executes the next statement only if the condition in parenthesis evaluates to true ((key ==this is the comparison operator which evaluates to true if both sides are the same KeyEvent.VK_RIGHT) ||this is boolean or, meaning if either or both are true then the result is true
052 (key ==this is the comparison operator which evaluates to true if both sides are the same KeyEvent.VK_KP_RIGHT)) {open braces start code blocks and must be matched with a close brace
053 setVelocity(Math.abs(getDeltaX()), getDeltaY());
054 super.advance(dT);
055 }close braces end code blocks and must match an earlier open brace elseelse is what happens when the if condition is false ifif executes the next statement only if the condition in parenthesis evaluates to true (key ==this is the comparison operator which evaluates to true if both sides are the same KeyEvent.VK_SPACE) {open braces start code blocks and must be matched with a close brace
056 ring.startFlying();
057 }close braces end code blocks and must match an earlier open brace
058 }close braces end code blocks and must match an earlier open brace
059 }close braces end code blocks and must match an earlier open brace
060
061 /**
062 * Bounce the rescuer off the edge by pushing it back onto the screen
063 * (ifif executes the next statement only if the condition in parenthesis evaluates to true necessary)
064 */
065 @Override
066 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value bounceOffEdges() {open braces start code blocks and must be matched with a close brace
067 ifif executes the next statement only if the condition in parenthesis evaluates to true (getMinY() < 0.0) {open braces start code blocks and must be matched with a close brace
068 translateY(0.0 - getMinY());
069 }close braces end code blocks and must match an earlier open brace
070 ifif executes the next statement only if the condition in parenthesis evaluates to true (getMaxY() > 1.0) {open braces start code blocks and must be matched with a close brace
071 translateY(1.0 - getMaxY());
072 }close braces end code blocks and must match an earlier open brace
073 ifif executes the next statement only if the condition in parenthesis evaluates to true (getMinX() < 0.0) {open braces start code blocks and must be matched with a close brace
074 translateX(0.0 - getMinX());
075 }close braces end code blocks and must match an earlier open brace
076 ifif executes the next statement only if the condition in parenthesis evaluates to true (getMaxX() > 1.0) {open braces start code blocks and must be matched with a close brace
077 translateX(1.0 - getMaxX());
078 }close braces end code blocks and must match an earlier open brace
079 }close braces end code blocks and must match an earlier open brace
080
081 /**
082 * Return a reference to the rescue ring used by thisthis means the current object (the implicit parameter) rescuer
083 *
084 * @returnnull reference to the ring; should never be nullnull is the value used to refer to a non-existant object
085 */
086 publicpublic is used to indicate unrestricted access (any other class can have access) RescueRing getRescueRing() {open braces start code blocks and must be matched with a close brace
087 returnreturn means to provide the result of the method and/or cease execution of the method immediately ring;
088 }close braces end code blocks and must match an earlier open brace
089
090 /**
091 * Set the color sets the color of the parts of the rescuer
092 */
093 @Override
094 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value setColor(Color color) {open braces start code blocks and must be matched with a close brace
095 body.setColor(color);
096 }close braces end code blocks and must match an earlier open brace
097
098 /**
099 * Set the location of thisthis means the current object (the implicit parameter) rescuer. Note that the ring moves with the
100 * rescuer ifif executes the next statement only if the condition in parenthesis evaluates to true it is ready.
101 */
102 @Override
103 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value setLocation(doubledouble is the type for numbers that can contain decimal fractions x, doubledouble is the type for numbers that can contain decimal fractions y) {open braces start code blocks and must be matched with a close brace
104 super.setLocation(x, y);
105 ifif executes the next statement only if the condition in parenthesis evaluates to true (ring.isReady()) {open braces start code blocks and must be matched with a close brace
106 ring.setLocation(x, y);
107 }close braces end code blocks and must match an earlier open brace
108 }close braces end code blocks and must match an earlier open brace
109
110 /**
111 * Set the scale of the Rescuer. Note that the ring is scaled to match
112 * the rescuer.
113 */
114 @Override
115 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value setScale(doubledouble is the type for numbers that can contain decimal fractions scale) {open braces start code blocks and must be matched with a close brace
116 super.setScale(scale);
117 ring.setScale(scale);
118 }close braces end code blocks and must match an earlier open brace
119 }close braces end code blocks and must match an earlier open brace
120
121 //Uploaded on Mon Mar 29 21:40:24 EDT 2010
|
Download/View scg/ch09/Rescuer.java