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

import de.thdeg.greiner.superpangworld.gameview.GameView;
import de.thdeg.greiner.superpangworld.graphics.base.Bubble;
import de.thdeg.greiner.superpangworld.graphics.base.CollidableGameObject;
import de.thdeg.greiner.superpangworld.graphics.base.Position;

import java.util.List;


/**
 * The green bubble with special abilities.
 */
public class SpecialBubble extends Bubble {

    /** The pixel art for the bubble */
    private final static String GREEN_BUBBLE =
                    "    GGGG    \n"+
                    "   GWGGGG   \n"+
                    "  GWGGGGGG  \n"+
                    " GWGGGGGGGG \n"+
                    "GWGGGGGGGGGG\n"+
                    "GWGGGGGGGGGG\n"+
                    "GWGGGGGGGGWG\n"+
                    "GGGGGGGGGWWG\n"+
                    " GGGGGGGWWG \n"+
                    "  GGGGGWWG  \n"+
                    "   GGGWWG   \n"+
                    "    GGGG    \n";

    /** The pixel art for the bubble */
    private final static String STAR =
                    "      OO      \n"+
                    "     OYYO     \n"+
                    "     OYYO     \n"+
                    "    OOYYOO    \n"+
                    "OOOOOYYYYOOOOO\n"+
                    "OYYYYYYYYYYYYO\n"+
                    " OOYYYYYYYOO  \n"+
                    "  OOYYYYYYOO  \n"+
                    "   OYYYYYYO   \n"+
                    "  OYYYYYYYYO  \n"+
                    "  OYYYOOYYYO  \n"+
                    " OYYYO  OYYYO \n"+
                    " OYOO    OOYO \n"+
                    " OO        OO \n";

    /** The pixel art for the bubble */
    private final static String CLOCK =
                    " YY       YY \n"+
                    "YYYY OOO YYYY\n"+
                    "YYYOOWWWOOYYY\n"+
                    " YOBWWWWWWOY \n"+
                    "  OWBWWWBWO  \n"+
                    " OWWWBWBWWWO \n"+
                    " OWWWWBWWWWO \n"+
                    " OWWWWWWWWWO \n"+
                    "  OWWWWWWWO  \n"+
                    "  OWWWWWWWO  \n"+
                    "   OOWWWOO   \n"+
                    "    OOOOO    \n"+
                    "   O     O   \n"+
                    "  O       O  \n";

    /** Flag, if the bubble is in freeze state or in burst state */
    public boolean freezeState;
    /** The height of the star pixel art */
    private final static int STAR_HEIGHT = 14;
    /** The width of the star pixel art */
    private final static int STAR_WIDTH = 14;
    /** The height of the clock pixel art */
    private final static int CLOCK_HEIGHT = 14;
    /** The width of the clock pixel art */
    private final static int CLOCK_WIDTH = 13;

    /**
     * Create a special bubble with default values.
     *
     * @param gameView the {@link GameView} to display the bubble
     * @param objectsToCollideWith the list of {@link CollidableGameObject} the bubble can collide with
     */
    public SpecialBubble(GameView gameView, List<CollidableGameObject> objectsToCollideWith) {
        super(gameView,objectsToCollideWith);
        this.freezeState = true;
        this.hitBox.width = width-20;
        this.hitBox.height = height-20;
    }

    @Override
    public void destroy() {
        gamePlayManager.specialBubblePresent = false;
        if(freezeState){
            gamePlayManager.freezeMovement(3000);
        }else{
            gamePlayManager.destroyAllBubbles();
        }
    }

    @Override
    protected void updateHitBoxPosition() {
        hitBox.x = (int) (position.x+10);
        hitBox.y = (int) (position.y+10);
    }

    @Override
    public void addToCanvas() {
        gameView.addBlockImageToCanvas(GREEN_BUBBLE,position.x,position.y,size, rotation);

        Position iconPosition = new Position(position.x + (width/2.0),position.y + (width/2.0));
        int IconBlockSize = 3;
        if(freezeState){
            gameView.addBlockImageToCanvas(CLOCK,iconPosition.x - (CLOCK_WIDTH*IconBlockSize/2.0),iconPosition.y - (CLOCK_HEIGHT*IconBlockSize/2.0),IconBlockSize, 0);
        }else{
            gameView.addBlockImageToCanvas(STAR,iconPosition.x - (STAR_WIDTH*IconBlockSize/2.0),iconPosition.y - (STAR_HEIGHT*IconBlockSize/2.0),IconBlockSize, 0);
        }

    }

    @Override
    public int getBurstScore() {
        return 1000;
    }

    @Override
    public void updateStatus() {}
}
