"""
enemyJ.py - Gray bomber
"""

import common
import enemy
import random
import shotB,shotH,shotI
import explosionD

class EnemyJ(enemy.Enemy):

    # rect = 2d only! width+height will be appended!
    def __init__(self, rect):        
        rect          += [43,22]
        enemy.Enemy.__init__(self,rect,175*(common.diff+1),15)
        self.images    = common.images['EnemyJ']
        self.speed_x   = 2
        self.speed_y   = 2
        self.max_speed = 2
        self.weapons   = [ { 'Delay' :1,
                             'Type'  :1,
                             'Level' :0 },
                           { 'Delay' :1,
                             'Type'  :2,
                             'Level' :0 },
                           { 'Delay' :1,
                             'Type'  :3,
                             'Level' :1 }]
        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] < r[3] and r[1] >= 0:
            self.speed_y = self.max_speed
        elif r[1] > 300-r[3]:
            self.speed_y = -self.max_speed
        if r[0] < r[2]:
            self.speed_x = self.max_speed
        elif r[0] > common.resolution[0]-r[2]:
            self.speed_x = -self.max_speed

        for w in self.weapons:
            w['Delay'] -= 1
            if w['Delay'] <= 0: # shoot
                if w['Type'] == 1:
                    w['Delay'] = random.randrange(60,80)
                    shotH.ShotH([r[0],r[1]+18],w['Level'])
                    shotH.ShotH([r[0]+40,r[1]+18],w['Level'])
                elif w['Type'] == 2:
                    w['Delay'] = random.randrange(40,60)
                    shotI.ShotI([r[0]+4,r[1]+r[3]],w['Level'])
                    shotI.ShotI([r[0]+10,r[1]+r[3]],w['Level'])
                    shotI.ShotI([r[0]+32,r[1]+r[3]],w['Level'])
                    shotI.ShotI([r[0]+38,r[1]+r[3]],w['Level'])
                elif w['Type'] == 3:
                    w['Delay'] = random.randrange(50,70)
                    shotB.ShotB([r[0]+15,r[1]+18],w['Level'])
                    shotB.ShotB([r[0]+24,r[1]+18],w['Level'])


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