"""
enemyL.py - Very big gray enemy (level 4 boss)
"""

import common
import enemy
import random
import shotB,shotF,shotH,shotJ
import explosionB,explosionC,explosionD,explosionE

class EnemyL(enemy.Enemy):

    # rect = 2d only! width+height will be appended!
    def __init__(self, rect):
        self.rect      = rect+[93,130]
        enemy.Enemy.__init__(self,self.rect,10000*(common.diff+1),100)
        self.images    = common.images['EnemyL']
        self.speed_y   = 2
        self.speed_x   = 2
        self.max_speed = 2
        self.weapons    = [{ 'Delay': 1,
                             'Type':  1,
                             'Level': 1 },
                           { 'Delay': 1,
                             'Type':  4,
                             'Level': 1 },
                           { 'Delay': 1,
                             'Type':  2,
                             'Level': 1 },
                           { 'Delay': 1,
                             'Type':  3,
                             'Level': 1 },
                           { 'Delay': 1,
                             'Type':  5,
                             'Level': 1 } ]
        self.explosion_delay = 5
        common.enemies.append(self)

    # from object.py
    def move(self):
        r = self.rect
        
        r[0] += self.speed_x
        r[1] += self.speed_y
        if r[0] < r[2]:
            self.speed_x = self.max_speed
        elif r[0] > common.resolution[0]-r[3]:
            self.speed_x = -self.max_speed
        if r[1] < self.max_speed and r[1] >= 0:
            self.speed_y = self.max_speed
        elif r[1] > 300:
            self.speed_y = -self.max_speed

        for w in self.weapons:
            w['Delay'] -= 1
            if w['Delay'] <= 0: # shoot
                if w['Type'] == 1:
                    w['Delay'] = random.randrange(30,50)
                    shotH.ShotH([r[0]+2,r[1]+70],w['Level'])
                    shotH.ShotH([r[0]+90,r[1]+70],w['Level'])
                elif w['Type'] == 2:
                    w['Delay'] = random.randrange(40,60)
                    shotJ.ShotJ([r[0]+35,r[1]+100],w['Level'])
                    shotJ.ShotJ([r[0]+55,r[1]+100],w['Level'])
                elif w['Type'] == 3:
                    w['Delay'] = random.randrange(40,60)
                    shotB.ShotB([r[0]+6,r[1]+100],w['Level'])
                    shotB.ShotB([r[0]+85,r[1]+100],w['Level'])
                elif w['Type'] == 4:
                    w['Delay'] = random.randrange(10,20)
                    shotJ.ShotJ([r[0]+r[2]/2,r[1]+100],w['Level'])
                    shotJ.ShotJ([r[0]+15,r[1]+55],w['Level'])
                    shotJ.ShotJ([r[0]+75,r[1]+55],w['Level'])
                elif w['Type'] == 5:
                    w['Delay'] = random.randrange(50,80)
                    shotF.ShotF([r[0]+38,r[1]+r[3]],w['Level'])
                    shotF.ShotF([r[0]+52,r[1]+r[3]],w['Level'])

        # partial explosions
        self.explosion_delay -= 1
        if self.explosion_delay <= 0:
            if common.speed: self.explosion_delay = 8
            else: self.explosion_delay = 4
            if self.alive < 1000:
                explosionD.ExplosionD([self.rect[0]+2*self.speed_x+random.randrange(self.rect[2]/2),self.rect[1]+random.randrange(self.rect[3])])
            elif self.alive < 2500:
                explosionC.ExplosionC([self.rect[0]+2*self.speed_x+random.randrange(self.rect[2]/2),self.rect[1]+random.randrange(self.rect[3])])
            elif self.alive < 5000:
                explosionB.ExplosionB([self.rect[0]+2*self.speed_x+random.randrange(self.rect[2]/2),self.rect[1]+random.randrange(self.rect[3])])

    # from enemy.py
    def explode(self):
        explosionE.ExplosionE(self.rect[:2],5)
        explosionE.ExplosionE([self.rect[0]+20,self.rect[1]+10],4)
        
    def hitShield(self):
        pass
