Brandon/Wackadot

From ggc

Jump to: navigation, search

01 package Brandon;
02 
03 import wiki.Wiki;
04 import fang.*;
05 import java.awt.*;
06 import java.awt.geom.*;
07 
08 public class Wackadot extends GameLoop
09 {
10     private Sprite dot;
11     private ImageSprite ast1, ast2, bg;    //player dot, target asteroids
12     
13      private int score, r, g, b;     //score, random color ints
14     
15     private StringSprite scoreSprite;
16 
17     public void startGame()
18     {
19         makeSprites();
20         addSprites();
21     }
22     
23     private void makeSprites()      //set object attributes
24     {
25         dot = new OvalSprite(11);
26         dot.setScale(0.1);
27         dot.setLocation(0.50.5);
28         dot.setColor(Color.RED);
29         
30         ast1 = new ImageSprite(Wiki.getMedia("Asteroid.gif"));
31         ast1.setScale(0.15);
32         ast1.setLocation(random.nextDouble(), random.nextDouble());
33         ast1.setLooping(true);
34         ast1.startAnimationNow();
35         
36         ast2 = new ImageSprite(Wiki.getMedia("Asteroid.gif"));
37         ast2.setScale(0.15);
38         ast2.setLocation(random.nextDouble(), random.nextDouble());
39         ast2.setLooping(true);
40         ast2.startAnimationNow();
41         
42         bg = new ImageSprite(Wiki.getMedia("Space2.gif"));
43         bg.setScale(1);
44         bg.setLocation(0.5,0.5);
45         
46         scoreSprite = new StringSprite("Score: " + score);
47         scoreSprite.setHeight(0.05);
48         scoreSprite.rightJustify();
49         scoreSprite.topJustify();
50         scoreSprite.setLocation(10);
51         scoreSprite.setColor(Color.WHITE);
52     }
53     
54     private void addSprites()
55     {
56         canvas.addSprite(bg, dot, ast1, ast2, scoreSprite);    //add background, dot, asteroids and score
57     }
58     
59     private void repositionRandomly(Sprite sprite)
60     {
61         sprite.setLocation(random.nextDouble(), random.nextDouble());   //random asteroid placement
62     }
63     
64     private int rand(int val)
65     {
66         val = (int)Math.round(Math.random() 255);
67         return val;
68     }
69     
70     private void handleCollisions()
71     {
72         if(dot.intersects(ast1))
73         {
74             score++;
75             
76             repositionRandomly(ast1);
77             dot.setColor(new Color(rand(r),rand(g),rand(b)));
78         }
79         
80         if(dot.intersects(ast2))
81         {
82             score++;
83             
84             repositionRandomly(ast2);
85             dot.setColor(new Color(rand(r),rand(g),rand(b)));
86         }
87         
88         scoreSprite.setText("Score: " + score);
89     }
90     
91     public void advanceFrame(double timePassed)
92     {
93         Point2D.Double mouse = getPlayer().getMouse().getLocation();
94         dot.setLocation(mouse);
95         
96         handleCollisions();
97     }
98 }

Compiler Errors:
----------
1. ERROR in Brandon/Wackadot.java (at line 30)
	ast1 = new ImageSprite(Wiki.getMedia("Asteroid.gif"));
	       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
The constructor ImageSprite(URL) is undefined
----------
2. ERROR in Brandon/Wackadot.java (at line 36)
	ast2 = new ImageSprite(Wiki.getMedia("Asteroid.gif"));
	       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
The constructor ImageSprite(URL) is undefined
----------
3 problems (3 errors)

Download/View Brandon/Wackadot.java




Views
Personal tools
Add to 
del.icio.usAdd to 
diggAdd to 
FacebookAdd to 
favoritesAdd to 
GoogleAdd to 
MySpaceAdd to 
PrintAdd to 
SlashdotAdd to 
StumbleUponAdd to 
Twitter