From ggc
|
01 packagepackage is used to name the directory or folder a class is in intro;
02
03 importimport means to make the classes and/or packages available in this program fang.*;
04 importimport means to make the classes and/or packages available in this program java.awt.*;
05 importimport means to make the classes and/or packages available in this program java.awt.geom.*;
06
07 /**
08 * All about my game.
09 * @authorthis is the Javadoc tag for documenting who created the source code My Name Here
10 */
11 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 ProjectileBounceExample extendsextends means to customize or extend the functionality of a class Game
12 {open braces start code blocks and must be matched with a close brace
13 privateprivate is used to restrict access to the current class only OutlineSprite boundary;
14 privateprivate is used to restrict access to the current class only OvalSprite ball;
15 privateprivate is used to restrict access to the current class only ProjectileTransformer projectile;
16
17 /**sets up the game*/
18 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value setup()
19 {open braces start code blocks and must be matched with a close brace
20 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(5));
21 boundary.setSize(0.9);
22 boundary.setLineThickness(0.2);
23 boundary.setLocation(0.5, 0.5);
24 addSprite(boundary);
25
26 ball=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);
27 ball.setLocation(0.5, 0.5);
28 addSprite(ball);
29
30 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);
31 ball.setTracker(projectile);
32 }close braces end code blocks and must match an earlier open brace
33
34 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value handleCollisions()
35 {open braces start code blocks and must be matched with a close brace
36 ifif executes the next statement only if the condition in parenthesis evaluates to true(ball.intersects(boundary))
37 {open braces start code blocks and must be matched with a close brace
38 Vector2D vector=this assignment operator makes the left side equal to the right sideprojectile.getVector2D();
39 vector.turnDegrees(180);
40 projectile.setVector2D(vector);
41 }close braces end code blocks and must match an earlier open brace
42 }close braces end code blocks and must match an earlier open brace
43
44 /**handle input and game events*/
45 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value advance()
46 {open braces start code blocks and must be matched with a close brace
47 handleCollisions();
48 }close braces end code blocks and must match an earlier open brace
49 }close braces end code blocks and must match an earlier open brace
|
Download/View intro/ProjectileBounceExample.java