import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class Mexicaan here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Mexicaan extends Animal
{int vSpeed;
int acceleration=1;
/**
* Act - do whatever the Mexicaan wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
// Add your action code here.
checkFall();
onGround();
fall();
die();
atWorldEdge();
moveAround();
}
public boolean onGround()
{
Object under = getOneObjectAtOffset(0, getImage().getHeight()/2 + 2, Steen.class);
return under != null;
}
public void checkFall()
{
if (onGround()) {
vSpeed = 0;
}
else {
fall();
}
}
public void fall()
{
setLocation (getX(), getY() + vSpeed);
if(vSpeed<10)
{
vSpeed += acceleration;
}
}
public void die()
{
Actor Trump = getOneIntersectingObject(Mexicaan.class);
if(Trump!=null)
{
vSpeed =-50;
}
}// bron: pws game lobster class
public boolean atWorldEdge()
{
if (getY() <= 5 || getY() >= getWorld() . getHeight() -5)
return true;
else
return false;
}// bron https://www.greenfoot.org/topics/2668
private void moveAround()
{
if (atWorldEdge())
{
getWorld().removeObject(this);
}
}
}


