|
01 packagepackage is used to name the directory or folder a class is in Brandon;
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 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 Wackadot extendsextends means to customize or extend the functionality of a class GameLoop
09 {open braces start code blocks and must be matched with a close brace
10 privateprivate is used to restrict access to the current class only Sprite dot;
11 privateprivate is used to restrict access to the current class only ImageSprite ast1, ast2, bg; //player dot, target asteroids
12
13 privateprivate is used to restrict access to the current class only intint is the type for whole numbers and it is short for integer score, r, g, b; //score, random color ints
14
15 privateprivate is used to restrict access to the current class only StringSprite scoreSprite;
16
17 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value startGame()
18 {open braces start code blocks and must be matched with a close brace
19 makeSprites();
20 addSprites();
21 }close braces end code blocks and must match an earlier open brace
22
23 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value makeSprites() //set object attributes
24 {open braces start code blocks and must be matched with a close brace
25 dot =this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor OvalSprite(1, 1);
26 dot.setScale(0.1);
27 dot.setLocation(0.5, 0.5);
28 dot.setColor(Color.RED);
29
30 ast1 =this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor ImageSprite(Wiki.getMedia("Asteroid.gif"));
31 ast1.setScale(0.15);
32 ast1.setLocation(random.nextDouble(), random.nextDouble());
33 ast1.setLooping(truetrue is the boolean value that is the opposite of false);
34 ast1.startAnimationNow();
35
36 ast2 =this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor ImageSprite(Wiki.getMedia("Asteroid.gif"));
37 ast2.setScale(0.15);
38 ast2.setLocation(random.nextDouble(), random.nextDouble());
39 ast2.setLooping(truetrue is the boolean value that is the opposite of false);
40 ast2.startAnimationNow();
41
42 bg =this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor ImageSprite(Wiki.getMedia("Space2.gif"));
43 bg.setScale(1);
44 bg.setLocation(0.5,0.5);
45
46 scoreSprite =this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor StringSprite("Score: " +adds two numbers together or concatenates Strings together score);
47 scoreSprite.setHeight(0.05);
48 scoreSprite.rightJustify();
49 scoreSprite.topJustify();
50 scoreSprite.setLocation(1, 0);
51 scoreSprite.setColor(Color.WHITE);
52 }close braces end code blocks and must match an earlier open brace
53
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(bg, dot, ast1, ast2, scoreSprite); //add background, dot, asteroids and score
57 }close braces end code blocks and must match an earlier open brace
58
59 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value repositionRandomly(Sprite sprite)
60 {open braces start code blocks and must be matched with a close brace
61 sprite.setLocation(random.nextDouble(), random.nextDouble()); //random asteroid placement
62 }close braces end code blocks and must match an earlier open brace
63
64 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 val)
65 {open braces start code blocks and must be matched with a close brace
66 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() * 255);
67 returnreturn means to provide the result of the method and/or cease execution of the method immediately val;
68 }close braces end code blocks and must match an earlier open brace
69
70 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value handleCollisions()
71 {open braces start code blocks and must be matched with a close brace
72 ifif executes the next statement only if the condition in parenthesis evaluates to true(dot.intersects(ast1))
73 {open braces start code blocks and must be matched with a close brace
74 score++this is the increment operator, which increases the variable by 1;
75
76 repositionRandomly(ast1);
77 dot.setColor(newnew is used to create objects by calling the constructor Color(rand(r),rand(g),rand(b)));
78 }close braces end code blocks and must match an earlier open brace
79
80 ifif executes the next statement only if the condition in parenthesis evaluates to true(dot.intersects(ast2))
81 {open braces start code blocks and must be matched with a close brace
82 score++this is the increment operator, which increases the variable by 1;
83
84 repositionRandomly(ast2);
85 dot.setColor(newnew is used to create objects by calling the constructor Color(rand(r),rand(g),rand(b)));
86 }close braces end code blocks and must match an earlier open brace
87
88 scoreSprite.setText("Score: " +adds two numbers together or concatenates Strings together score);
89 }close braces end code blocks and must match an earlier open brace
90
91 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)
92 {open braces start code blocks and must be matched with a close brace
93 Point2D.Double mouse =this assignment operator makes the left side equal to the right side getPlayer().getMouse().getLocation();
94 dot.setLocation(mouse);
95
96 handleCollisions();
97 }close braces end code blocks and must match an earlier open brace
98 }close braces end code blocks and must match an earlier open brace
|