"""
shotG.py - homing rocket
"""

import common
import random
import shot
import explosionC

class ShotG(shot.Shot):

    # rect = 2d pos -> width and height will be appended!
    def __init__(self,rect,level=0):
        rect   += [7,7]
        shot.Shot.__init__(self,0,rect)
        self.images  = common.images['ShotG']
        if len(common.enemies) == 0: return
        self.target  = common.enemies[random.randrange(len(common.enemies))]
        self.speed_x = 4
        self.speed_y = 4
        self.level   = level
        self.damage  = 10+level*10

        common.shots_player.append(self)

    # from object.py
    def move(self):
        if not self.target in common.enemies:
            self.kill()
            return
        r = self.rect
        old = r[:]
        e = self.target.rect
        if r[0] < e[0]:
            r[0] += self.speed_x
        else:
            r[0] -= self.speed_x
        if r[1] < e[1]:
            r[1] += self.speed_y
        else:
            r[1] -= self.speed_y
            
        #if r[0]+r[2] < -10 or r[0] > common.resolution[0]+10 or r[1]+r[3] < -10:
        #    common.shots_player.remove(self)

    # from shot.py
    def explode(self):
        explosionC.ExplosionC(self.rect[:2])
