hey guys, i tried to make a score counter like on the YouTube :
but my score didn't increase even i shot my enemy, can anyone help me fix the code?
this the code for the shooter :
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* A bullet to be shot at asteroids.
*
* The Shot moves to the top of the screen and then expires. If it hits an asteroid
* on the way, it destroys the asteroid, and then expires immediately.
*/
public class Shot extends Actor
{
private SpaceShip myShip;
private static final int damage = 16;
public Shot(SpaceShip myShip)
{
this.myShip = myShip;
}
/**
* Act - do whatever the Shot wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
int ypos = getY();
if (ypos > 0) {
ypos = ypos - 1;
setLocation(getX(), ypos);
Actor rock = getOneIntersectingObject(Asteroid.class);
if (rock != null) {
// We've hit an asteroid!
hitAnAsteroid();
World myWorld = getWorld();
getWorld().removeObject(rock);
ScrollWorld sw = (ScrollWorld)myWorld;
Counter counter = sw.getCounter();
counter.addScore();
getWorld().removeObject(this);
}
}
else {
// I reached the top of the screen
getWorld().removeObject(this);
}
}
}
