package de.thdeg.greiner.superpangworld.graphics.moveable;

import de.thdeg.greiner.superpangworld.gameview.GameView;
import de.thdeg.greiner.superpangworld.graphics.base.*;

import java.awt.*;
import java.util.ArrayList;

/**
 * A harpoon which can be fired upwards by the player.
 */
public class Harpoon extends CollidingGameObject implements MovingGameObject {

    /** The pixel string representing a harpoon */
    private final static String HARPOON =
                    "   B   \n"+
                    "  BBB  \n"+
                    " kkkkk \n"+
                    "k kkk k\n"+
                    "k kkk k\n";

    /**
     * Create a harpoon with default values.
     *
     * @param gameView the {@link GameView} to display the bubble
     * @param objectsToCollideWith the list of {@link CollidableGameObject} the harpoon can collide with
     */
    public Harpoon(GameView gameView, ArrayList<CollidableGameObject> objectsToCollideWith){
        super(gameView, objectsToCollideWith);
        speedInPixel = 2;
        size = 3;
        width = (int) (7 * size);
        height = (int) (5 * size);
        rotation = 0;
        getPosition().setTo(300,300);
        this.hitBox.width = width;
        this.hitBox.height = (int) (440 - position.y);
    }

    @Override
    protected void updateHitBoxPosition() {
        hitBox.x = (int) (position.x);
        hitBox.y = (int) (position.y);
        hitBox.height = (int) (440 - position.y);
    }

    @Override
    public void reactToCollision(CollidableGameObject otherObject) {

    }

    /**
     * Draws the harpoon onto the  {@link GameView}.
     */
    @Override
    public void addToCanvas(){
        gameView.addBlockImageToCanvas(HARPOON, getPosition().x, getPosition().y,size, rotation);
        gameView.addRectangleToCanvas(position.x + (width/2.0) - 2,position.y + height, 4,440 - position.y,1,true,Color.lightGray);
    }

    /**
     * Moves the harpoon a tick further upwards.
     */
    @Override
    public void updatePosition(){
        if(position.y > 8){
            getPosition().up(Math.min(speedInPixel, position.y-8));
        }else{
            gamePlayManager.destroy(this);
        }
    }

    /**
     * Deletes the harpoon if it hits the roof.
     */
    @Override
    public void updateStatus() {
    }
}
