"""
enemyK.py - Big gray enemies (level 3 boss)
"""

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

class EnemyK(enemy.Enemy):

    # rect = 2d only! width+height will be appended!
    def __init__(self, rect):
        self.rect      = rect+[78,86]
        enemy.Enemy.__init__(self,self.rect,3000*(common.diff+1),60)
        self.images    = common.images['EnemyK']
        self.speed_y   = 2
        self.speed_x   = 2
        self.shield    = 1000
        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': 0 } ]
        self.explosion_delay = 5
        common.enemies.append(self)

    # from object.py
    def move(self):
        r = self.rect
        if r[1] < 0:
            r[1] += self.speed_y
        
        r[0] += self.speed_x
        if r[0]+self.speed_x < 0 or \
           r[0]+r[2]+self.speed_x > common.resolution[0]:
            self.speed_x *= -1

        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]+34,r[1]+r[3]],w['Level'])
                    shotH.ShotH([r[0]+42,r[1]+r[3]],w['Level'])
                elif w['Type'] == 2:
                    w['Delay'] = random.randrange(40,60)
                    shotJ.ShotJ([r[0]+22,r[1]+60],w['Level'])
                    shotJ.ShotJ([r[0]+54,r[1]+60],w['Level'])
                elif w['Type'] == 3:
                    w['Delay'] = random.randrange(40,60)
                    shotB.ShotB([r[0]+8,r[1]+65],w['Level'])
                    shotB.ShotB([r[0]+68,r[1]+65],w['Level'])
                elif w['Type'] == 4:
                    w['Delay'] = random.randrange(40,60)
                    shotI.ShotI([r[0]+6,r[1]+65],w['Level'])
                    shotI.ShotI([r[0]+10,r[1]+65],w['Level'])
                    shotI.ShotI([r[0]+66,r[1]+65],w['Level'])
                    shotI.ShotI([r[0]+70,r[1]+65],w['Level'])
                elif w['Type'] == 5:
                    w['Delay'] = random.randrange(50,80)
                    shotF.ShotF([r[0]+32,r[1]+r[3]],w['Level'])
                    shotF.ShotF([r[0]+45,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 < 500:
                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 < 900:
                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 < 1250:
                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):
        shieldK.ShieldK([self.rect[0]+self.speed_x,self.rect[1]])
