On the Scenario asteroid I am having trouble with why it won't accept the color on my code for Space, the textColor for my counter and a new GreenfootImage(); on Explosion
here are my codes
Thanks in advance for any help that you may be able to give!
import greenfoot.*; // (World, Actor, GreenfootImage, and Greenfoot)
import java.awt.Color;
/**
* Space. Something for rockets to fly in.
*
*
* @version 1.0
*/
public class Space extends World
{
private Counter scoreCounter;
private int startAsteroids = 3;
public Space()
{
super(800, 700, 1);
GreenfootImage background = getBackground();
background.setColor(Color.BLACK);
background.fill();
createStars(300);
Rocket rocket = new Rocket();
addObject(rocket, getWidth()/2 + 100, getHeight()/2);
addAsteroids(startAsteroids);
scoreCounter = new Counter("Score: ");
addObject(scoreCounter, 60, 380);
Explosion.initializeImages();
ProtonWave.initializeImages();
}
/**
* Add a given number of asteroids to our world. Asteroids are only added into
* the left half of the world.
*/
private void addAsteroids(int count)
{
for(int i = 0; i < count; i++)
{
int x = Greenfoot.getRandomNumber(getWidth()/2);
int y = Greenfoot.getRandomNumber(getHeight()/2);
addObject(new Asteroid(), x, y);
}
}
private void createStars(int number)
{
GreenfootImage background = getBackground();
for(int i = 0; i < number; i++) {
int x = Greenfoot.getRandomNumber( getWidth() );
int y = Greenfoot.getRandomNumber(getHeight() );
int color = 120 - Greenfoot.getRandomNumber(100);
background.setColor(new Color(color,color,color));
background.fillOval(x,y, 2, 2);
}
}
/**
* This method is called when the game is over to display the final score.
*/
public void gameOver()
{
addObject(new ScoreBoard(getCounter().getValue()), getWidth()/2, getHeight()/2);
}
public Counter getCounter()
{
return scoreCounter;
}
}import greenfoot.*; // (World, Actor, GreenfootImage, and Greenfoot)
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics;
/**
* Counter that displays a text and number.
*
*
* @version 1.0.1
*/
public class Counter extends Actor
{
private static final Color textColor = new Color(255, 180, 150);
private int value = 0;
private static int target = 0;
private String text;
private int stringLength;
public Counter()
{
this("0");
}
public Counter(String prefix)
{
text = prefix;
stringLength = (text.length() + 2) * 10;
setImage(new GreenfootImage(stringLength, 16));
GreenfootImage image = getImage();
image.setColor(textColor);
updateImage();
}
public void act() {
if(value < target) {
value++;
updateImage();
}
else if(value > target) {
value--;
updateImage();
}
}
public static void add(int score)
{
target += score;
}
public int getValue()
{
return value;
}
/**
* Make the image
*/
private void updateImage()
{
GreenfootImage image = getImage();
image.clear();
image.drawString(text + value, 1, 12);
}
}import greenfoot.*; // (World, Actor, GreenfootImage, and Greenfoot)
/**
* An explosion. It starts by expanding and then collapsing.
* The explosion will explode other obejcts that the explosion intersects.
*
*
* @version 1.0.1
*/
public class Explosion extends Actor
{
/** How many images should be used in the animation of the explostion */
private final static int IMAGE_COUNT= 12;
/**
* The images in the explosion. This is static so the images are not
* recreated for every object (improves performance significantly).
*/
private static GreenfootImage images;
/** Current size of the explosion */
private int imageNo = 0;
/** How much do we increment the index in the explosion animation. */
private int increment=1;
/**
* Create a new explosion.
*/
public Explosion()
{
initializeImages();
setImage(images);
Greenfoot.playSound("MetalExplosion.wav");
}
/**
* Create the images for explosion.
*/
public synchronized static void initializeImages()
{
if(images == null) {
GreenfootImage baseImage = new GreenfootImage("explosion-big.png");
images = new GreenfootImage();
for (int i = 0; i < IMAGE_COUNT; i++)
{
int size = (i+1) * ( baseImage.getWidth() / IMAGE_COUNT );
images = new GreenfootImage(baseImage);
images.scale(size, size);
}
}
}
/**
* Explode!
*/
public void act()
{
setImage(images);
imageNo += increment;
if(imageNo >= IMAGE_COUNT) {
increment = -increment;
imageNo += increment;
}
if(imageNo < 0) {
getWorld().removeObject(this);
}
}
}
