also do you know how to make an actor randomly jump? cause i might start a new thread about it
if (onGround() && Greenfoot.getRandomNumber(100)<JUMP_PERCENT_CHANCE) jump();
verticalSpeed += JUMP_STRENGTH;
verticalSpeed--; setLocation(getX(), getY()+verticalSpeed);
public void RandomJump ()
{
if(isOnGround && Greenfoot.getRandomNumber(100)) jump();
}
public void jump()
{
fspeed = -10;
fall();
}
public void fall()
{
setLocation ( getX(), getY() + fspeed);
fspeed = fspeed + acceleration;
}Actor heartless = getOneIntersectingObject(Heartless.class);
{
if(heartless != null)
healthBar.subtract(10);
}java.lang.NullPointerException at K.hit(K.java:132) at K.act(K.java:35) at greenfoot.core.Simulation.actActor(Simulation.java:583) at greenfoot.core.Simulation.runOneLoop(Simulation.java:541) at greenfoot.core.Simulation.runContent(Simulation.java:215) at greenfoot.core.Simulation.run(Simulation.java:205)
if(healthBar.getValue() == 0)
{
getWorld().removeObject(healthBar);
getWorld().removeObject(this);
World world = getWorld();
NewGameOver newgameover = new NewGameOver();
world.addObject(newgameover, world.getWidth()/2,world.getHeight()/2);
}
} public boolean touchingenemy()
{
Actor heartless = getOneIntersectingObject(Heartless.class);
if(heartless != null){
return true;
}
return false;
}// with boolean field (outside method)
private boolean onHeartless = false;
// then inside method
if (isTouching(Heartless.class)
{
if (!onHeartless)
{
healthBar.subtract(10);
onHeartless = true;
}
}
else onHeartless = false;