#include ".\text.h"

Text::Text(void){
    init(0,0,0,0,0,1.0,1.0,Text::TEXT_COORDINATES::SCREEN, Text::TEXT_EFFECT::NONE);
}
Text::Text(int newX, int newY, char* newString, int newTextureId, int newLifeSpan, TEXT_COORDINATES newCoords ){
    init(newX, newY, newString, newTextureId, newLifeSpan, 1.0, 1.0, newCoords, Text::TEXT_EFFECT::NONE);
}
Text::Text(int newX, int newY, char* newString, int newTextureId, int newLifeSpan, float newScale, TEXT_COORDINATES newCoords ){
    init(newX, newY, newString, newTextureId, newLifeSpan, newScale, newScale, newCoords, Text::TEXT_EFFECT::NONE);
}
Text::Text(int newX, int newY, char* newString, int newTextureId, int newLifeSpan, float newScaleX, float newScaleY, TEXT_COORDINATES newCoords ){
    init(newX, newY, newString, newTextureId, newLifeSpan, newScaleX, newScaleY, newCoords, Text::TEXT_EFFECT::NONE);
}
Text::Text(int newX, int newY, char* newString, int newTextureId, int newLifeSpan, TEXT_COORDINATES newCoords, TEXT_EFFECT newEffect ){
    init(newX, newY, newString, newTextureId, newLifeSpan, 1.0, 1.0, newCoords, newEffect);
}

void Text::init(int newX, int newY, char* newString, int newTextureId, int newLifeSpan, float newScaleX, float newScaleY, TEXT_COORDINATES newCoords, TEXT_EFFECT newEffect){
    x = newX;
    y = newY;
    string = newString;
    lifeSpan = newLifeSpan;
    textureId = newTextureId;
    scaleX = newScaleX;
    scaleY = newScaleY;
	textCoords = newCoords;
    effect = newEffect;
    xInitial = x;
    yInitial = y;
    numTicks = 0;
}

Text::~Text(void){
    free(string);
}

// setter getter for x position
void Text::setX(int newX){
    x = newX;
}
int Text::getX(){
    return x;
}
// setter getter for y position
void Text::setY(int newY){
    y = newY;
}
int Text::getY(){
    return y;
}
// setter getter for string
void  Text::setString(char* newString){
    string = newString;
}
char* Text::getString(){
    return string;
}
// setter getter for life span
void  Text::setLifeSpan(int newLifeSpan){
    lifeSpan = newLifeSpan;
}
int   Text::getLifeSpan(){
    return lifeSpan;
}
// setter getter for alphabet texture
void  Text::setTextureId(int newTextureId){
    textureId = newTextureId;
}
int   Text::getTextureId(){
    return textureId;
}

void  Text::setScaleX(float newScaleX){
    scaleX = newScaleX;
}
float Text::getScaleX(){
    return scaleX;
}
void  Text::setScaleY(float newScaleY){
    scaleY = newScaleY;
}
float Text::getScaleY(){
    return scaleY;
}

void Text::tick(){
    numTicks++;
    if (lifeSpan != -1){
        lifeSpan--;
    }
}

bool Text::dead(){
    bool result;

    lifeSpan == 0 ? result = true : result = false;
    return result;
}

Text::TEXT_COORDINATES Text::getTextCoordinates() {
	return textCoords;
}

Text::TEXT_EFFECT Text::getTextEffect(){
	return effect;
}

void Text::gravityEffect(){
    double yAdd = 0;

    if (numTicks < 6){
        yAdd = -(numTicks*numTicks) + 5.75*numTicks;
    } else if(numTicks < 10){
        yAdd = -(numTicks*numTicks) + 16*numTicks - 60;
    } else if(numTicks < 12){
        yAdd = -2*(numTicks*numTicks) + 44*numTicks - 240;
    } else {
        yAdd = 0;
    }
    x = xInitial + 2*numTicks;
    y = yInitial - 2*(int)yAdd;
}
