import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * Write a description of class Krankenwagen here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class Krankenwagen extends Actor
{
    public void act() 
    {
       move(2); 
       gedrueckteTaste();
       pruefeZusammenstoss();
       punkteEinsammeln();
    } 
    
    public void gedrueckteTaste()
    {
           if (Greenfoot.isKeyDown("left")) 
        {
            turn(-4);
  
        
        }
        if (Greenfoot.isKeyDown("right")) 
        {
            turn(4);
        }
               if (Greenfoot.isKeyDown("up")) 
        {
            move(5);
        }
        if (Greenfoot.isKeyDown("down")) 
        {
            move(-5);
        }
    }
    private void pruefeZusammenstoss() 
    {
        Actor zusammenstoss = getOneObjectAtOffset(10, 10, Auto.class);
        if (zusammenstoss != null) 
        {
            GreenfootImage image;
            image = new GreenfootImage("explosion-big.png");
            setImage(image);
            Greenfoot.playSound("MetalExplosion.wav");
            Greenfoot.stop();
        }
    }
    
    private void punkteEinsammeln()
    {
        Actor einsammeln = getOneObjectAtOffset(10, 10, Zielpunkt.class);
        if(einsammeln != null) 
        {
            getWorld().removeObject(einsammeln);
            ((Arena) getWorld()).punkteZaehler.eingesammelt();
        }
    }

}
