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

/**
 * Write a description of class Bottle here.
 * 
 * @author Jonathan, Florian
 * @version (a version number or a date)
 */
public class Bottle extends Weapon
{
    private static int sizex = 20;
    private static int sizey = 20;
    private boolean alreadypicked = false;
    private long alreadypickedmillis = 0;
    private int count = 0;
    public static boolean available;
    private long spacePressed;
    private boolean lastSpaceStatus;
    Linch linch;

    public Bottle()
    {
        GreenfootImage img = new GreenfootImage("Skins/Waffe/wodka_runter.png");
        img.scale(sizex, sizey);
        setImage(img);

    }

    /**
     * Act - do whatever the Bottle wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    public void act() 
    {
        if (Welt.pause != true)
        {
            if (available)
            {
                if(Greenfoot.isKeyDown("space")){
                    if(!lastSpaceStatus){
                        follow();
                        spacePressed = System.currentTimeMillis();
                        Greenfoot.playSound("sword.aif");
                    }else if((System.currentTimeMillis() - spacePressed) < 200){
                        follow();
                        //Greenfoot.playSound("sword.aif");
                    }else{
                        setImage(new GreenfootImage("Skins/leer.png"));
                        setLocation(0,0);
                    }
                    lastSpaceStatus = true;
                }else{
                    lastSpaceStatus = false;
                    setImage(new GreenfootImage("Skins/leer.png"));
                    setLocation(0,0);
                }

            }
        }
    }    

    public void giveLinch(Linch linchget)
    {
        linch = linchget;
    }

    public void bottlecheck(Bottlecheck bottlecheck)
    {

    }

    private void follow()
    {
        GreenfootImage img;
        if (Linch.dir == "untenlinks")
        {
            setLocation(linch.Xcoord-15,linch.Ycoord);
            img = new GreenfootImage("Skins/Waffe/wodka_links.png");
        }
        else if (Linch.dir == "untenrechts")
        {
            setLocation(linch.Xcoord+15,linch.Ycoord);
            img = new GreenfootImage("Skins/Waffe/wodka_rechts.png");
        }
        else if (Linch.dir == "unten")
        {
            setLocation(linch.Xcoord,linch.Ycoord+20);
            img = new GreenfootImage("Skins/Waffe/wodka_runter.png");
        }
        else if (Linch.dir == "rechts" || Linch.dir == "obenrechts")
        {
            setLocation(linch.Xcoord+15,linch.Ycoord);
            img = new GreenfootImage("Skins/Waffe/wodka_rechts.png");
        }
        else if (Linch.dir == "links" || Linch.dir == "obenlinks")
        {
            setLocation(linch.Xcoord-15,linch.Ycoord);
            img = new GreenfootImage("Skins/Waffe/wodka_links.png");
        }
        else        //(Linch.dir == "oben")
        {
            setLocation(linch.Xcoord,linch.Ycoord-25);
            img = new GreenfootImage("Skins/Waffe/wodka_hoch.png");
        }
        img.scale(sizex, sizey);
        setImage(img);
    }
}
