"""
enemyF.py - Red megabomber
"""

import common
import enemy
import random
import shotH,shotI,shotJ
import explosionD

class EnemyF(enemy.Enemy):

    # rect = 2d only! width+height will be appended!
    def __init__(self, rect):        
        rect          += [49,21]
        enemy.Enemy.__init__(self,rect,100*(common.diff+1),10)
        self.images    = common.images['EnemyF']
        self.speed_x   = 2
        self.speed_y   = 2
        self.max_speed = 2
        self.attack    = 0
        self.weapons   = [ { 'Delay' :1,
                             'Type'  :1,
                             'Level' :0 },
                           { 'Delay' :1,
                             'Type'  :2,
                             'Level' :0 },
                           { 'Delay' :1,
                             'Type'  :5,
                             'Level' :0 }]
        common.enemies.append(self)

    # from object.py
    def move(self):
        r = self.rect
        r[1] += self.speed_y
        if self.attack:
            if r[1] > common.resolution[1]-r[2]-20:
                self.speed_y = -self.max_speed
            elif r[1] < 50:
                self.attack = 0
        else:
            r[0] += self.speed_x
            if r[1] < r[3] and r[1] >= 0:
                self.speed_y = self.max_speed
            elif r[1] > 100-r[3]:
                self.speed_y = -self.max_speed
            if r[0] < r[2]:
                self.speed_x = self.max_speed
            elif r[0] > common.resolution[0]-r[2]:
                self.speed_x = -self.max_speed
            if random.randrange(500) < 5:
                self.attack = 1
                self.speed_y = 2*self.max_speed

        for w in self.weapons:
            w['Delay'] -= 1
            if w['Delay'] <= 0: # shoot
                if w['Type'] == 1:
                    w['Delay'] = random.randrange(60,80)
                    shotH.ShotH([r[0]+12,r[1]+r[3]],w['Level'])
                    shotH.ShotH([r[0]+30,r[1]+r[3]],w['Level'])
                elif w['Type'] == 2:                    
                    w['Delay'] = random.randrange(40,60)
                    if self.attack:
                        shotI.ShotI([r[0],r[1]+10],w['Level'])
                        shotI.ShotI([r[0]+r[2]-2,r[1]+10],w['Level'])
                        shotI.ShotI([r[0]+13,r[1]+15],w['Level'])
                        shotI.ShotI([r[0]+32,r[1]+15],w['Level'])
                elif w['Type'] == 5:
                    w['Delay'] = random.randrange(50,100)
                    shotJ.ShotJ([r[0]+r[2]/2,r[1]+r[3]],w['Level'])

    # from enemy.py
    def explode(self):
        r = self.rect
        explosionD.ExplosionD([r[0],r[1]+r[3]/2])
        explosionD.ExplosionD([r[0]+r[2],r[1]+r[3]/2])
        explosionD.ExplosionD([r[0]+r[2]/2,r[1]])

