"""
shotF.py - simple green+red enemy homing shot
"""

import common
import shot
import explosionA

class ShotF(shot.Shot):

    # rect = 2d pos -> width+height will be appended!
    def __init__(self,rect,level):
        rect  += [8,8]
        shot.Shot.__init__(self,1,rect)
        self.images  = common.images['ShotF']
        self.speed_x = 2
        self.speed_y = 3
        self.level   = level
        self.delay   = 10
        self.damage  = 3
        self.state   = 0
        common.shots_enemy.append(self)

    # from object.py
    def move(self):
        # this homing shot only works as long
        # as the shot is above the player
        # this is a feature! so that the player can
        # avoid getting hit by "overflying" the shot
        r = self.rect
        p = common.player.rect
        r[1] += self.speed_y
        if r[1] <= p[1]+p[3]:
            if r[0] < p[0]:
                r[0] += self.speed_x
            else:
                r[0] -= self.speed_x
                        
        if self.rect[1] > common.resolution[1]:
            common.shots_enemy.remove(self)

        self.delay -= 1
        if self.delay <= 0:
            self.delay = 10
            self.state = not self.state

    # from object.py
    def show(self):        
        r = common.screen.blit(self.images[self.state],self.rect)
        return self.optimizeDirtyRect(r)

    def explode(self):
        explosionA.ExplosionA([self.rect[0],self.rect[1]])
