/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package game;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Rectangle;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author A KUMA
 */
    public class Bullet{//cheacr con class abstrad 
        int xb,yb,bulletL,bulletH,who;//xb&yb bullet position;largo y alto de la bala
        boolean disponible=true,modeBInv;
        public Bullet(int unX,int unY,int whoShot){//position inicial
            xb=unX;
            yb=unY;
            bulletL=4;
            bulletH=10;
            who=whoShot;//quien dispara !?
        }
        public synchronized void mueve(int n){
            yb-=n*10;//<0 inv; >0 shoter
        }
        public int getWho(){
            /* who | '1'=>shotter
             *     | '0'=>null
             *     | '-1'=>invaders
             */
            return who;
        }
        public int getX(){
            return xb;
        }
        public int getY(){
            return yb;
        }
        public boolean disponible(){
            return disponible;
        }
        public void setEstado(boolean newEstado){
            disponible=newEstado;
        }
        public Rectangle getBalaPosition(){
            return new Rectangle(xb,yb,bulletL,bulletH);//aglutinar stas var en algun lado..
        }
        public void dibuja(Graphics g){
            if(getWho()>0){Bullet_a(g);}
            if(getWho()<0){Bullet_b(g);}
        }
        public void Bullet_a(Graphics g){
            g.setColor(Color.WHITE);
            g.fillRect(xb, yb, bulletL, bulletH);//estilo de la bala ... puede mejorar
        }
        public void Bullet_b(Graphics g){
            g.setColor(Color.WHITE);
            if(modeBInv){
            g.drawLine(xb+bulletL, yb, xb, yb+bulletH/3);
            g.drawLine(xb, yb+bulletH/3, xb+bulletL, yb+2*bulletH/3);
            g.drawLine(xb+bulletL, yb+2*bulletH/3, xb, yb+bulletH);
            modeBInv=!modeBInv;
            }else{
            g.drawLine(xb, yb, xb+bulletL, yb+bulletH/3);
            g.drawLine(xb+bulletL, yb+bulletH/3, xb, yb+2*bulletH/3);
            g.drawLine(xb, yb+2*bulletH/3, xb+bulletL, yb+bulletH); 
            modeBInv=!modeBInv;
            }
        }
    }
