
/**
 * Write a description of class player here.
 * 
 * @author Xander Friedlander 
 * @version 0.01 Sat, Aug 15, 2009
 */

import java.lang.*;
import java.applet.*;
import java.awt.*;
import javax.swing.*;
import java.awt.geom.*;

public abstract class Player extends Actor implements Runnable
{
    Thread t;
    int health, maxHealth, rotation;
    double speed, posX, posY, speedX, speedY, dmgMod, armorMod;
    Image characterImage, deadImage;
    AffineTransform geometry;

    /**
     * Constructor for objects of class player
     */
    
    public Player(Image img1, Image img2)
    {

        characterImage = img1;
        deadImage = img2;


        t = new Thread(this);
        t.start();
        
        rotation = 0;
        speedX = 0;
        speedY = 0;
        x = 50;
        y = 100;
        r = 160;

    }

    /**
     * Methods for abstract class player
     */   

    
    public int getPosX()
    {
        return (int)x;
    }
    
    public int getPosY()
    {
        return (int)y;
    }
    
    public int getHealth()
    {
        return health;
    }
    
    public int getMaxHealth()
    {
        return maxHealth;
    }
    
    public Image playerImage()
    {
        return characterImage;
    }
    
    public void forward()
    {
        speedX = speed * Math.cos(Math.toRadians(rotation));
        speedY = speed * Math.sin(Math.toRadians(rotation));
    }
    
    public void backward()
    {
        speedX = -speed * Math.cos(Math.toRadians(rotation));
        speedY = -speed * Math.sin(Math.toRadians(rotation));
    }    
    
    public void strfL()
    {
        speedX = -.8*speed * Math.sin(Math.toRadians(rotation));
        speedY = .8*speed * Math.cos(Math.toRadians(rotation));
    }
    
    public void strfR()
    {
        speedX = .8*speed * Math.sin(Math.toRadians(rotation));
        speedY = -.8*speed * Math.cos(Math.toRadians(rotation));
    }
    
    
    public void takeDmg(int m_dmg)
    {
        health = (int)Math.floor(health - (m_dmg * armorMod));
    }
    
    public void stop()
    {
        speedX = 0;
        speedY = 0;
    }
    
    public boolean isAlive()
    {
        if (health > 0)
          return true;
        else return false;
    }
    
    public void setRotation(int theta)
    {
        rotation = theta;
    }
    
    public void useAbility1()
    {
        this.takeDmg(5);
    }
    
    public void useAbility2()
    {

    }
    
    public void useAbility3()
    {
    }
    
    public int getRadius()
    {
        return r;
    }
    
    public void run()
    {
        while(true)
        {
            if (health > maxHealth) health = maxHealth;
            x += speedX;
            y += speedY;
            
            if (health < 0) health = 0;
            
            if (!this.isAlive()) characterImage = deadImage;
            
            
            try {
                t.sleep(16);
            } catch (InterruptedException e)
            { ; }
        }
    }

}

