The game I am coding consists of "digging" holes into the sand which I do by repeatedly adding the actor Drawinghole to form a line or a path. How to I make my actor (a ball called "Jaune") fall according to the path and not fall when it no longer touches it? This is my code but it does not seem to work:
private final int GRAVITY = 1;
private int velocity;
public jaune (){
velocity = 0;
}
public void act()
{
if(oktomove()){
fall();
}
Actor touche2 = getOneIntersectingObject(rouge1.class);
if(touche2 != null) Greenfoot.setWorld(new Niveau2());
}
public void fall(){
setLocation(getX() + velocity, getY() + velocity);
Actor touche2 = getOneIntersectingObject(Drawinghole.class);
if(touche2 == null) velocity = 0;
else velocity += GRAVITY;
}
public boolean oktomove()
{
boolean movingisok = false;
Actor touche = getOneIntersectingObject(Peg.class);
if(touche != null) movingisok = false;
int imageWidth = getImage().getWidth();
int imageHeight = getImage().getHeight();
if (getOneObjectAtOffset(imageWidth / 2, imageHeight , Drawinghole.class) != (null)) movingisok = true;
return movingisok;
}
