
import Thing
from Thing import *
import Texture
from Texture import *
from math import *
import globalVars
from util import *


class Shot(Thing):

    shotTex = None
    
    def __init__(self,start,end):
        Thing.__init__(self)
        if(Shot.shotTex == None):
            Shot.shotTex = Texture("shot1", group=1)
        self.texture = Shot.shotTex
        
        self.distance = 0 # how far do I have to go
        self.shotRange = 500
	self.landed = False
	self.start = start # start position
        self.end = end # end position
        
        self.width = 8
        self.height = 8
        self.start[0] -= 4
	self.start[1] -= 4
	
	self.speed = 8.0
	
	self.dying = 0
	self.dead = 0
	
	self.damage = 50
	
	
	        
        self.setv(start)
        
        self.setSpeeds(self.start,self.end)
        
    
    def setSpeeds(self, start, end):
        tx = end[0] - start[0]
        ty = end[1] - start[1]
        d = sqrt(tx**2 + ty**2)
        self.setSpeed(tx * self.speed / d, ty * self.speed / d)
        
    def getDistance(self):
        self.distance = sqrt(((self.x - self.start[0]) ** 2) + ((self.y - self.start[1]) ** 2))

    def update(self,delta):
        Thing.update(self, delta)
        self.getDistance()
        if self.distance > self.shotRange:
            self.dead = 1
        if self.edge == 1:
            self.dead = 1
        if not self.dead:
            for guy in globalVars.alienList:
                if circleCollide(self, guy):
                    guy.hit(self.damage)
                    self.dead = 1
                    break
        self.draw()

    def draw(self):
        self.texture.draw(pos=(self.x, self.y), width=8,height=8)