"""
enemyB.py - Medium green enemies
"""

import common
import enemy
import random
import shotB,shotF
import explosionD
import shieldB

class EnemyB(enemy.Enemy):

    # rect = 2d only! width+height will be appended!
    def __init__(self, rect):
        self.rect      = rect+[31,18]
        enemy.Enemy.__init__(self,self.rect,40*(common.diff+1),10)
        self.images    = common.images['EnemyB']
        self.speed_y   = 2
        self.speed_x   = 2
        self.shield    = 20
        self.weapons    = [{ 'Delay': 1,
                             'Type':  1,
                             'Level': 0,
                             'Status':0 },
                           { 'Delay': 1,
                             'Type':  2,
                             'Level': 0,
                             'Status':0 } ]
        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'])

    # from enemy.py
    def explode(self):
        explosionD.ExplosionD(self.rect[:2],5)
        explosionD.ExplosionD([self.rect[0]+20,self.rect[1]+10],4)
        
    def hitShield(self):
        shieldB.ShieldB(self.rect[:2])
