"""
enemyC.py - Big green enemies (level 1 boss)
"""

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

class EnemyC(enemy.Enemy):

    # rect = 2d only! width+height will be appended!
    def __init__(self, rect):
        self.rect      = rect+[45,26]
        enemy.Enemy.__init__(self,self.rect,500*(common.diff+1),20)
        self.images    = common.images['EnemyC']
        self.speed_y   = 2
        self.speed_x   = 2
        self.shield    = 250
        self.weapons    = [{ 'Delay': 1,
                             'Type':  1,
                             'Level': 0 },
                           { 'Delay': 1,
                             'Type':  2,
                             'Level': 0 },
                           { 'Delay': 1,
                             'Type':  4,
                             'Level': 0 },
                           { 'Delay': 1,
                             'Type':  5,
                             'Level': 1 } ]
        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(60,80)
                    shotB.ShotB([self.rect[0]+self.rect[2]/2,self.rect[1]+self.rect[3]],w['Level'])
                elif w['Type'] == 2:
                    w['Delay'] = random.randrange(100,150)
                    shotF.ShotF([self.rect[0]+self.rect[2]/2,self.rect[1]+self.rect[3]],w['Level'])
                    shotF.ShotF([self.rect[0]+self.rect[2]/2,self.rect[1]+self.rect[3]],w['Level'])
                elif w['Type'] == 4:
                    w['Delay'] = random.randrange(40,60)
                    shotI.ShotI([self.rect[0]+2,self.rect[1]+20],w['Level'])
                    shotI.ShotI([self.rect[0]+14,self.rect[1]+22],w['Level'])
                    shotI.ShotI([self.rect[0]+30,self.rect[1]+22],w['Level'])
                    shotI.ShotI([self.rect[0]+42,self.rect[1]+20],w['Level'])
                elif w['Type'] == 5:
                    w['Delay'] = random.randrange(40,70)
                    shotJ.ShotJ([self.rect[0]+self.rect[2]/2,self.rect[1]+self.rect[3]],w['Level'])

        # partial explosions
        self.explosion_delay -= 1
        if self.explosion_delay <= 0:
            if common.speed: self.explosion_delay = 16
            else: self.explosion_delay = 8
            if self.alive < 100:
                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 < 200:
                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 < 300:
                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):
        shieldC.ShieldC(self.rect[:2])
