package com.darkdimension.ritle_run;

import android.graphics.Canvas;
import android.graphics.Paint;

public class Ground extends DiPoint
{
    //Ground Width
    private int width = 1;
    private boolean selfDestruct = false;
    private int selfDestructTimer = -1;

    public Ground()
    {
        //Super Constructor
        super(15);
    }

    public boolean update()
    {
        //If it's being destroyed
        if (selfDestructTimer > -1)
        {
            //Advance animation and check if it's destroyed
            if (++selfDestructTimer >= (12 *width)/2)
            {
                //Make ground off-screen
                setBottom(GameSurface.height *2);

                //Reset SelfDestruct
                selfDestruct = false;
                selfDestructTimer = -1;

                //Return Destructed
                return true;
            }
        }

        return false;
    }

    public void draw(Canvas canvas, int offsetX, int offsetY, Paint paint)
    {
        int drawFrame, drawX;
        for (int iii = 0; iii < width; iii++)
        {
            if (selfDestructTimer < (12 *width)/2/2)
				drawFrame = frame;
            else
                drawFrame = 18;

            //First Column
            if (iii == 0) drawX = 0; else
            //Last Column
            if (iii == width -1) drawX = 2;
            //Between
            else drawX = 1;

            //First Column
            canvas.drawBitmap(image[drawFrame +drawX], x +(iii *image[frame].getWidth()) +offsetX, y +offsetY, paint);
        }
	}

    //Setters
    public void setWidth(int amount) {width = amount;}

    public void setRight (int amount) {x = amount -(width *image[frame].getWidth());}
    public void setCenterX(int amount) {x = amount -(width *image[frame].getWidth())/2;}

    public void setSelfDestruct(boolean status) {selfDestruct = status;}
    public void selfDestruct()
    {
        if (selfDestruct)
            selfDestructTimer = 0;
    }

    //Getters
    public int getRight () {return x +(image[frame].getWidth () *width);}
    public int getCenterX() {return x +(image[frame].getWidth () *width)/2;}

    public int getWidth () {return width *image[frame].getWidth ();}
    public int getBlockWidth() {return width;}

    public int getGroundLevel() {return y +image[frame].getHeight()/4;}

    public boolean isSelfDestruct() {return selfDestruct;}
}