From FANG
|
001 packagepackage is used to name the directory or folder a class is in scg.ch02;
002
003
004
005 importimport means to make the classes and/or packages available in this program fang2.attributes.Vector2D;
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.core.Sprite;
008 importimport means to make the classes and/or packages available in this program fang2.sprites.OvalSprite;
009 importimport means to make the classes and/or packages available in this program fang2.sprites.RectangleSprite;
010 importimport means to make the classes and/or packages available in this program fang2.transformers.AccelerationTransformer;
011 importimport means to make the classes and/or packages available in this program fang2.transformers.BounceClassTransformer;
012 importimport means to make the classes and/or packages available in this program fang2.transformers.BounceInsideRectangleTransformer;
013 importimport means to make the classes and/or packages available in this program fang2.transformers.BounceSpriteTransformer;
014 importimport means to make the classes and/or packages available in this program fang2.transformers.BounceTransformer;
015 importimport means to make the classes and/or packages available in this program fang2.transformers.SpinTransformer;
016 importimport means to make the classes and/or packages available in this program fang2.transformers.VelocityProvider;
017 importimport means to make the classes and/or packages available in this program fang2.transformers.VelocityTransformer;
018
019 /**
020 * Models a bouncing ball. This is a sprite: an object with an
021 * on-screen appearance which can be located in different places on the
022 * screen.
023 */
024 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 BasketBallSprite
025 extendsextends means to customize or extend the functionality of a class OvalSprite {open braces start code blocks and must be matched with a close brace
026 /** the defaultdefault is what is executed when no cases are matched diameter of a ball, in screens */
027 privateprivate is used to restrict access to the current class only staticstatic means that an instance is not required for access (class level access) finalfinal means not changeable (often used for constants) doubledouble is the type for numbers that can contain decimal fractions DEFAULT_DIAMETER =this assignment operator makes the left side equal to the right side 0.10;
028
029 /** bounces the ball off of sprites on the game board */
030 privateprivate is used to restrict access to the current class only finalfinal means not changeable (often used for constants) BounceClassTransformer spriteBouncer;
031
032 /** the bouncing transformer; has velocity and bounce */
033 privateprivate is used to restrict access to the current class only finalfinal means not changeable (often used for constants) BounceInsideRectangleTransformer bouncer;
034
035 /** the acceleration transformer; wrapped around the bouncer */
036 privateprivate is used to restrict access to the current class only finalfinal means not changeable (often used for constants) AccelerationTransformer gravity;
037
038 /**
039 * Construct a brand-newnew is used to create objects by calling the constructor {open braces start code blocks and must be matched with a close brace@link BasketBallSprite}close braces end code blocks and must match an earlier open brace with the defaultdefault is what is executed when no cases are matched
040 * size and defaultdefault is what is executed when no cases are matched transformer values.
041 */
042 publicpublic is used to indicate unrestricted access (any other class can have access) BasketBallSprite() {open braces start code blocks and must be matched with a close brace
043 super(DEFAULT_DIAMETER, DEFAULT_DIAMETER);
044 bouncer =this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor BounceInsideRectangleTransformer(
045 0.0, 0.0, 1.0, 1.0, // dimensions of screen
046 newnew is used to create objects by calling the constructor VelocityTransformer(newnew is used to create objects by calling the constructor Vector2D()));
047 // amount of bounce off edges
048 bouncer.setElasticity(0.66);
049 spriteBouncer =this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor BounceClassTransformer(thisthis means the current object (the implicit parameter), bouncer);
050 spriteBouncer.add(RectangleSprite.classclass is a group of fields and methods used for making objects);
051 // amount of bounce off sprites
052 spriteBouncer.setElasticity(0.45);
053
054 gravity =this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor AccelerationTransformer(newnew is used to create objects by calling the constructor Vector2D(), spriteBouncer);
055 addTransformer(gravity);
056 setColor(Game.getColor("misty rose"));
057 }close braces end code blocks and must match an earlier open brace
058
059 /**
060 * Add a newnew is used to create objects by calling the constructor target classclass is a group of fields and methods used for making objects.
061 *
062 * @paramthis is the Javadoc tag for documenting the purpose of parameters spriteClass the classclass is a group of fields and methods used for making objects of sprite to bounce off of
063 */
064 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value addTarget(Class<? extendsextends means to customize or extend the functionality of a class Sprite> spriteClass) {open braces start code blocks and must be matched with a close brace
065 spriteBouncer.add(spriteClass);
066 }close braces end code blocks and must match an earlier open brace
067
068 /**
069 * Add a newnew is used to create objects by calling the constructor target sprite to the ones thisthis means the current object (the implicit parameter) ball will interact with
070 *
071 * @paramthis is the Javadoc tag for documenting the purpose of parameters sprite the sprite with which to interact
072 */
073 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value addTarget(Sprite sprite) {open braces start code blocks and must be matched with a close brace
074 spriteBouncer.add(sprite);
075 }close braces end code blocks and must match an earlier open brace
076
077 /**
078 * Get the accelerator transformer attached to thisthis means the current object (the implicit parameter) sprite. This is
079 * the gravity.
080 *
081 * @returnnull the acceleration transformer attached to thisthis means the current object (the implicit parameter) ball
082 */
083 publicpublic is used to indicate unrestricted access (any other class can have access) AccelerationTransformer getAccelerationNG() {open braces start code blocks and must be matched with a close brace
084 returnreturn means to provide the result of the method and/or cease execution of the method immediately gravity;
085 }close braces end code blocks and must match an earlier open brace
086
087 /**
088 * Get the bouncer attached to thisthis means the current object (the implicit parameter) ball. That way it can be modified.
089 *
090 * @returnnull the bouncer
091 */
092 publicpublic is used to indicate unrestricted access (any other class can have access) BounceInsideRectangleTransformer getBouncer() {open braces start code blocks and must be matched with a close brace
093 returnreturn means to provide the result of the method and/or cease execution of the method immediately bouncer;
094 }close braces end code blocks and must match an earlier open brace
095
096 /**
097 * Set the velocity of the velocity providers attached to the ball.
098 *
099 * @paramthis is the Javadoc tag for documenting the purpose of parameters newVelocity the newnew is used to create objects by calling the constructor velocity in screens/second
100 */
101 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value setVelocity(Vector2D newVelocity) {open braces start code blocks and must be matched with a close brace
102 bouncer.setVelocity(newVelocity);
103 }close braces end code blocks and must match an earlier open brace
104
105 /**
106 * Set the acceleration of the "gravity" obeyed by thisthis means the current object (the implicit parameter) ball
107 *
108 * @paramthis is the Javadoc tag for documenting the purpose of parameters newAcceleration the newnew is used to create objects by calling the constructor acceleration in screens/second^this performs a bit-wise exclusive or (xor)2
109 */
110 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value setAcceleration(Vector2D newAcceleration) {open braces start code blocks and must be matched with a close brace
111 gravity.setAcceleration(newAcceleration);
112 }close braces end code blocks and must match an earlier open brace
113
114 /**
115 * Get the velocity transformer attached to thisthis means the current object (the implicit parameter) sprite. Lets you set
116 * the velocity
117 *
118 * @returnnull the velocity transformer
119 */
120 publicpublic is used to indicate unrestricted access (any other class can have access) VelocityProvider getVelocityNG() {open braces start code blocks and must be matched with a close brace
121 returnreturn means to provide the result of the method and/or cease execution of the method immediately bouncer;
122 }close braces end code blocks and must match an earlier open brace
123 }close braces end code blocks and must match an earlier open brace
124
125 //Uploaded on Mon Mar 29 21:41:56 EDT 2010
|
Download/View scg/ch02/BasketBallSprite.java