"""
enemyE.py - Red bomber
"""

import common
import enemy
import random
import shotJ
import explosionC,explosionD

class EnemyE(enemy.Enemy):

    # rect = 2d only! width+height will be appended!
    def __init__(self, rect):        
        rect          += [33,27]
        enemy.Enemy.__init__(self,rect,40*(common.diff+1),5)
        self.images    = common.images['EnemyE']
        self.speed_x   = 2
        self.speed_y   = 2
        self.weapon    = { 'Delay':1,
                           'Type': 5,
                           'Level':0,
                           }
        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[1] > common.resolution[1]-r[3]:
            self.speed_y = -2
            if r[0] < r[2]:
                self.speed_x = 2
            elif r[0] > common.resolution[0]-r[2]:
                self.speed_x = -2
            elif random.randrange(2)==0:
                self.speed_x *= -1            
        elif r[1] < 30:
            self.speed_y = 2
            if r[0] < r[2]:
                self.speed_x = 2
            elif r[0] > common.resolution[0]-r[2]:
                self.speed_x = -2
            elif random.randrange(2)==0:
                self.speed_x *= -1
        elif r[0] < r[2]:
            self.speed_x = 2
            if random.randrange(2)==0:
                self.speed_y *= -1
        elif r[0] > common.resolution[0]-r[2]:
            self.speed_x = -2
            if random.randrange(2)==0:
                self.speed_y *= -1
        
        w = self.weapon
        w['Delay'] -= 1
        if w['Delay'] <= 0: # shoot
            w['Delay'] = random.randrange(100,200)
            shotJ.ShotJ([r[0]+r[2]/2,r[1]+r[3]],w['Level'])

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