package spaceinvaders.objects;

import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.Rectangle;
import java.util.ArrayList;

public class Missile {
	private Rectangle rect;
	private int dir;
	private char sender;
	
	public Missile(int x, int y, int dir, char sender){
		rect = new Rectangle(x, y,2,17);
		this.dir = dir;
		this.sender = sender;
	}
	public void draw(Graphics2D g2){
		g2.setColor(Color.white);
		g2.fill(rect);
	}
	public void recalculate(){
		rect.setLocation((int)rect.getX(), (int)(rect.getY() + 15*dir));
	}
	public boolean playerCollision(Player player){
		return rect.intersects(player.getBorder());
	}
	public Enemie shipCollision(ArrayList<Enemie> enemies){
		for(Enemie e:enemies){
			if(rect.intersects(e.getBorder()))
				return e;
		}
		return null;
	}
	public boolean outOfScreen(int x, int y, int w, int h){
		return !rect.intersects(x, y, w, h);
	}
	public char getSender() {
		return sender;
	}
	public Rectangle getRect() {
		return rect;
	}
	
	
}
