I am making a Mario game and my Mario shoots straight, but how do I make him shoot the way he does in the game. (the bullets go over ground)
public class Fireball extends Actor
{
private int gravity = /*Some Negative Number */;
private static final int DEF_GRAV = gravity;
//Whatever other variables and constructors you have
public void act()
{
if (!onGround() || gravity < 0)
fall();
else
jump();
//Whatever else you have
}
public void fall()
{
gravity++;
setLocation(getX(), getY() - gravity);
}
public void jump()
{
gravity = DEF_GRAV;
}
public boolean onGround()
{
int height = getImage().getHeight();
Ground ground = (Ground)getOneObjectAtOffset(0, height/2 + 1, Ground.class); //Basically looks for a ground object beneath it. If nothing there, it will equal null
return ground != null; //If it exists, return true, if not, return false
}
}