From ggc
|
01 packagepackage is used to name the directory or folder a class is in jam;
02
03 importimport means to make the classes and/or packages available in this program wiki.Wiki;
04 importimport means to make the classes and/or packages available in this program fang.*;
05 importimport means to make the classes and/or packages available in this program java.awt.*;
06 importimport means to make the classes and/or packages available in this program java.awt.geom.*;
07
08 /**
09 * All about my game here.
10 * @authorthis is the Javadoc tag for documenting who created the source code Jam Jenkins
11 */
12 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 RunAway extendsextends means to customize or extend the functionality of a class GameLoop
13 {open braces start code blocks and must be matched with a close brace
14 /**an oval*/
15 privateprivate is used to restrict access to the current class only Sprite oval;
16 privateprivate is used to restrict access to the current class only Sprite runner;
17 privateprivate is used to restrict access to the current class only ProjectileTracker backgroundMover;
18 privateprivate is used to restrict access to the current class only RunAwayTracker runAway;
19 privateprivate is used to restrict access to the current class only CompositeTracker composite;
20
21 /**sets up the game*/
22 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value startGame()
23 {open braces start code blocks and must be matched with a close brace
24 setSize(600, 400);
25 makeSprites();
26 addSprites();
27 }close braces end code blocks and must match an earlier open brace
28
29 /**makes the sprites*/
30 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value makeSprites()
31 {open braces start code blocks and must be matched with a close brace
32 backgroundMover=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor ProjectileTracker(0, 0.3);
33
34 oval=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor OvalSprite(1, 1);
35 oval.setScale(0.15);
36 oval.setLocation(0.5, 0.5);
37
38 runner=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor OvalSprite(1, 1);
39 runner.setScale(0.1);
40 runner.setLocation(0.5, 0.95);
41 composite=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor CompositeTracker();
42
43 runAway=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor RunAwayTracker(0, 0.2);
44 runAway.setVillain(runner);
45 runAway.setGoodGuy(oval);
46
47 composite.addTracker(runAway);
48 composite.addTracker(backgroundMover);
49 composite.addTracker(newnew is used to create objects by calling the constructor AimlessTracker(0, 0.05));
50 runner.setTracker(composite);
51 }close braces end code blocks and must match an earlier open brace
52
53 /**adds the sprites to the screen*/
54 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value addSprites()
55 {open braces start code blocks and must be matched with a close brace
56 canvas.addSprite(oval, runner);
57 }close braces end code blocks and must match an earlier open brace
58
59 /**handle input and game events*/
60 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)
61 {open braces start code blocks and must be matched with a close brace
62 Point2D.Double mouseLocation=this assignment operator makes the left side equal to the right sidegetPlayer().getMouse().getLocation();
63 doubledouble is the type for numbers that can contain decimal fractions angle=this assignment operator makes the left side equal to the right sideMath.atan2(mouseLocation.y-0.5, mouseLocation.x-0.5);
64 backgroundMover.setVelocityDirection(angle);
65 ifif executes the next statement only if the condition in parenthesis evaluates to true(oval.getLocation().distance(runner.getLocation())<0.2)
66 {open braces start code blocks and must be matched with a close brace
67 composite.removeTracker(runAway);
68 }close braces end code blocks and must match an earlier open brace
69 elseelse is what happens when the if condition is false
70 {open braces start code blocks and must be matched with a close brace
71 composite.addTracker(runAway);
72 }close braces end code blocks and must match an earlier open brace
73 }close braces end code blocks and must match an earlier open brace
74 }close braces end code blocks and must match an earlier open brace
|
Download/View jam/RunAway.java