/*----------------------------------------------------------------------------
 * Klasse:		    Loch.java
 * Beschreibung:	Loch wo der Ball verschwinden soll
 * Autor:		    Jack Meyer
 * Datum:		    November, 1997
 * ---------------------------------------------------------------------------
 */

import java.awt.*;


class Loch extends Hindernis {

    /**
     * Display Farbe des Loch, Klassenvariable!
     */
    static private Color colorLoch = new Color (0,0,0);
    static private int durchmesser = 6;
    private int fangRadius = 6;
    private int fangSpeed = 8;

    /**
     *  Konstruktor des Lochs
     */
    Loch (int x, int y) {
        super (x, y, 0, 0);
    };
    /**
     *  String Konstruktor des Lochs
     */
    Loch (String aStringParameter)
    throws ParsingException,
           NumberFormatException,
           StringIndexOutOfBoundsException
    {
        this (0,0);
        double[] dArgs = Parser.ParseStringToDouble(aStringParameter);

        /* testen ob genau 2 Parameter vorhanden */
        if (dArgs.length != 2) throw new ParsingException ("Loch muss genau 2 Parameter (X,Y) haben");

        /* Parameter neu setzten */
        this.setPos ((int)dArgs[0], (int)dArgs[1]);
    };


    /**
     * Zeichenmethode für das Loch
     */
    void draw (Graphics g, int posX, int posY)
    {
        g.setColor(colorLoch);
        g.fillOval(posX+position.x-durchmesser/2, posY+position.y-durchmesser/2, durchmesser, durchmesser);
        //rund = oval mit gleichen Dimensionen
    };


    /**
     * Bewegung des Balls: Test ob Kollision
     */
    void collisionDetection (Ball aBall, int posX, int posY)
    {
        // test ob im Loch, für ENDE
        // berechne distanz Ball - Loch
        int deltaX = aBall.getPosX() - (posX+this.position.x);
        int deltaY = aBall.getPosY() - (posY+this.position.y);
        int distance = (int)Math.sqrt (deltaX*deltaX + deltaY*deltaY);
//        System.out.println("Collision Detection for Loch, distance: "+distance+", Speed: "+aBall.getSpeed());
        // test ob distanz innerhalb Fangradius
        if ((distance < fangRadius) & (aBall.getSpeed() < fangSpeed)) {
            // Bingo, Loch getroffen
            System.out.println("Collision Detected in Loch");
            aBall.setPos(posX+position.x,posY+position.y);
            aBall.setSpeed (0);
        };
    };

};