#include <stdlib.h>
#include <math.h>
#include "vector.h"
#include "draw.h"
#include "bullet.h"

Bullet::Bullet(const Vector &p, const Vector &v, int l){
	position=p;
	longevity=l;
	velocity=v;
}

Bullet::Bullet(const Bullet &copy){
	position=copy.position;
	longevity=copy.longevity;
	velocity=copy.velocity;
}

Bullet::~Bullet(){
}

void Bullet::shoot(const Vector &p, const Vector &v, int l){
	longevity=l;
	position=p;
	velocity=v;
}

void Bullet::fly(int ticks){
	longevity-=ticks/5;
	position=position+(ticks/5)*velocity;
	while (position.x<0)
		position.x+=XMAX;
	while (position.x>=XMAX)
		position.x-=XMAX;
	while(position.y<0)
		position.y+=YMAX;
	while(position.y>=YMAX)
		position.y-=YMAX;
}

bool Bullet::dead(){
	return (longevity<=0);
}

void Bullet::draw(byte_t color, byte_t *where){
	hline(int(position.x), int(1+position.x),int(position.y),color,where);
	hline(int(position.x), int(1+position.x),int(1+position.y),color,where);
}

void Bullet::kill(){
	longevity=0;
}

Vector pos(const Bullet &b){
	return(b.position);
}

