In my scenario : http://www.greenfoot.org/scenarios/9071
when I click reset, the score is not resetting to 0 after every game. below is the code i used for the projectile:
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Projectile
*
* @redninja21
* @1.0
*/
public class Projectile extends Actor
{
/**
* Act - do whatever the Projectile wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
move(10);
checkForWorldEdge();
}
public void checkForWorldEdge(){
if(atWorldEdge()){
getWorld().removeObject(this);
}
else{
if(canSee(Asteroid.class)){
getWorld().removeObject(getOneIntersectingObject(Asteroid.class));
getWorld().removeObject(this);
SpaceWorld world = (SpaceWorld) getWorld();
world.asteroids--;
world.asteroidcount++; //whenever an asteroid is destroyed it adds one to the score
}
}
}
/**
* Test if we are close to one of the edges of the world. Return true is we are.
*/
public boolean atWorldEdge()
{
if(getX() < 10 || getX() > getWorld().getWidth() - 10)
return true;
if(getY() < 10 || getY() > getWorld().getHeight() - 10)
return true;
else
return false;
}
/**
* Return true if we can see an object of class 'clss' right where we are.
* False if there is no such object here.
*/
public boolean canSee(Class clss)
{
Actor actor = getOneObjectAtOffset(0, 0, clss);
return actor != null;
}
/**
* Try to eat an object of class 'clss'. This is only successful if there
* is such an object where we currently are. Otherwise this method does
* nothing.
*/
public void eat(Class clss)
{
Actor actor = getOneObjectAtOffset(0, 0, clss);
if(actor != null) {
getWorld().removeObject(actor);
}
}
}
and here is the code i used to display the score:
import greenfoot.*;
import java.awt.Color;
public class GameOver extends Actor
{
Color colors = { Color.ORANGE, Color.RED };
int colorNum = 0;
int counter = 1;
public void act()
{
if (--counter == 0)
{
colorNum = ++colorNum % 2;
updateImage();
counter = 50;
}
}
public void updateImage()
{
SpaceWorld world = (SpaceWorld) getWorld();
String s1 = new String();
s1 = "" + world.asteroidcount;
setImage(new GreenfootImage("GAME\nOVER\nYOUR SCORE : " + s1, 96, colors, new Color(0, 0, 0, 0)));
}
}
someone please help

