/*
 * Vaisseau.java
 *
 * Created on 4 janvier 2005, 17:11
 */

package hyperion;
import java.applet.*;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.Color;
/**
 *
 * @author CryoGen
 */
public class Vaisseau extends Entity {
    
    private int vie;
    private int bouclier;
    private int direction;
    private int pos_img;
    private float pos_imgf;
    private int type_proj;
    
    static public boolean clone;
    static public boolean invincible;
    static public Image img_clone;
    static public Image img_invincible;
    static public Image img_invincible_clone;
    static public Image img_burner;
    private Animation anim_burnerL, anim_burnerR;
    
    private int compteur_inv;
    
    private Image current;
    
    /** Creates a new instance of Vaisseau */
    public Vaisseau(Image image, int _x, int _y, int height, int width, Applet applet) {
        this._x = _x; this._y = _y;
        this.height = height; this.width = width;
        this.image = image;
        current = this.image;
        
        this.offset_x = 0; this.offset_y = 0;
        this.speed_x = 0; this.speed_y = 0;
        this.visible = false;
        
        this.APPLET_H = new Integer(applet.getParameter("height"));
        this.APPLET_W = new Integer(applet.getParameter("width"));
        
        this.applet = applet;
        
        this.pos_img = 3;
        this.pos_imgf = 3;
        
        this.type_proj = 0;
        
        this.bouclier = 100;
        this.vie = 3;
        
        clone = false;
        
        //(Image img, int taille, int width, int height, Applet applet)
        this.anim_burnerL = new Animation(this.img_burner, 25, 50, 25, applet);
        this.anim_burnerL.setSpeed(0.5f);
        this.anim_burnerR = new Animation(this.img_burner, 25, 50, 25, applet);
        this.anim_burnerR.setSpeed(0.5f);
        
    }

    public void setTypeProj(int type) { this.type_proj = type; }
    
    public Projectile generateProjectile() {
        return new Projectile(_x+(this.height/2), _y, type_proj, applet);
    }
    
    public Projectile generateProjectilePodL() {
        return new Projectile(_x+10, _y+35, type_proj, applet);
    }
    
    public Projectile generateProjectilePodR() {
        return new Projectile(_x+height-10, _y+35, type_proj, applet);
    }
    
    public void draw(Graphics g)
    {
        if(direction == -1 && this.pos_img > 0) this.pos_imgf -= 0.2;
        else if(direction == 1 && this.pos_img < 6) this.pos_imgf += 0.2;
        else if(direction == 0 && this.pos_img < 3) this.pos_imgf += 0.2;
        else if(direction == 0 && this.pos_img > 3) this.pos_imgf -= 0.2;
        
        this.pos_img = (int)this.pos_imgf;
        
        int dx1 = this._x;
        int dy1 = this._y;
        int dx2 = dx1 + this.width;
        int dy2 = dy1 + this.height;
        
        int sx1 = 0;
        int sy1 = this.pos_img*88;
        int sx2 = sx1 + this.width;
        int sy2 = sy1 + this.height;
        
        if(clone)
        {
            if(invincible)
            {
                current = img_invincible_clone;
                compteur_inv++;
            }
            else
            {
                current = img_clone;
            }
        }
        else
        {
            if(invincible)
            {
                current = img_invincible;
                compteur_inv++;
            }
            else
            {
                current = image;
            }
        }
        
        if(compteur_inv > 150)
        {
            invincible = false;
            compteur_inv = 0;
        }
        
        g.drawImage(current, dx1, dy1, dx2, dy2, sx1, sy1, sx2, sy2, this.applet);
        
        
        this.anim_burnerL.draw(g, _x + 11, _y + 88);
        this.anim_burnerR.draw(g, _x + height-33, _y + 88);
     
    }
    
    public void move_x(int speed)
    {
        if(speed > 0) direction = 1;
        else direction = -1;
        this._x += speed; 
    }
    
    public void setDirection(int dir) {
        this.direction = dir;
    }
    
    
    
    public void modBouclier(int inc) {
        this.bouclier += inc;
        if(this.bouclier < 0) this.bouclier = 0;
        else if(this.bouclier > 100) this.bouclier = 100;
    }
    
    public int getBouclier() {
        return this.bouclier;
    }
    
    public void modVie(int inc) {
        this.vie += inc;
    }
    
    public int getVie() {
        return this.vie;
    }
    
}