Hi, I am trying to program a rocket shooting game.
I have two kind of rocks on space that should be shot by the space rocket, big rocks and small rocks. I want the big rocks to split into three rocks when they are hit with a shot.
The game works fine with no errors.
However when I try to shoot the big rocks, sometimes they split and sometimes they don't. When I say sometimes I mean when I reset the game and run it again, the same rock that splitted before it is not splitting again.
I don't know why this is happening. Please help.
these are the codes I used in the big rock object.
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class rock1 here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class BigRock extends Actor
{
public void act()
{
World w = getWorld();
move(-1);
if(isTouching(shots.class))
{
w.addObject(new SmallRock(), getX(), getY());
w.addObject(new SmallRock(), getX()+40, getY()-40);
w.addObject(new SmallRock(), getX()+40, getY()+40);
}
else if(isAtEdge())
{
setLocation(600,Greenfoot.getRandomNumber(600));
}
}
public BigRock()
{
getImage().scale(getImage().getWidth()/6, getImage().getHeight()/6);
}
}