package xaero.rotatenjump.game.object;

import xaero.rotatenjump.game.Game;
import xaero.rotatenjump.game.graphics.Graphics;

/**
 * Created by xaero on 10/07/2017.
 */

public class Coin extends Entity {

    public static final float COIN_SIZE = 11;
    private float anim = 0;
    public static final float[] GOLD = {1, 0.843f, 0, 1};
    public static final float[] SILVER = {0.972f, 0.96f, 0.915f, 1};
    public static final float[] COPPER = {0.443f, 0.216f, 0.129f, 1};

    public Coin(float posX, float posY) {
        super(posX, posY, COIN_SIZE * 2, COIN_SIZE * 2, COIN_SIZE * 2);
    }

    @Override
    public void update(Game game){

    }

    public static float[] getCoinColour(int coinTier){
        return coinTier == 2 ? GOLD : (coinTier == 1 ? SILVER : COPPER);
    }

    @Override
    public void render(Game game, float partialTicks) {
        Graphics.color = getCoinColour(game.coinTierRender);
        Graphics.modelsLoadedFromFiles[2].draw((lastPosXRender + (posXRender - lastPosXRender) * partialTicks), lastPosYRender + (posYRender - lastPosYRender) * partialTicks, 0, anim, 0, COIN_SIZE, COIN_SIZE, COIN_SIZE);
        anim = (anim + 3) % 360;
        //Graphics.color = Graphics.WHITE;

        /* super.render(canvas, paint, partialTicks);
        SimpleGraphics.push(canvas);
        paint.setColor(Color.RED);
        SimpleGraphics.scaledTranslate(canvas, (lastPosX + (posX - lastPosX) * partialTicks), lastPosY + (posY - lastPosY) * partialTicks);
        SimpleGraphics.scaledCircle(canvas, paint, COIN_SIZE);
        paint.setColor(Color.BLACK);
        SimpleGraphics.pop(canvas);*/
    }

    public void getHit(Game game) {
        game.coinCounters[game.coinTier]++;
        game.getCoins().remove(this);
    }

    @Override
    public boolean isCollidingWith(Player player, float d, float[][] points, float collisionPartial) {
        if(d < Player.PLAYER_RADIUS + Coin.COIN_SIZE) {
            for(int j = 0; j < 4; j++) { //checkig all 4 points
                float[] point = points[j];//gets one of 4 player points
                float offX = (player.posX + point[0]) - getPosX(collisionPartial);
                float offY = (player.posY + point[1]) - getPosY(collisionPartial);
                if(Math.sqrt(offX * offX + offY * offY) < Coin.COIN_SIZE)
                    return true;
            }
        }
        return super.isCollidingWith(player, d, points, collisionPartial);
    }
}
