"""
enemyAI.py - These small green enemies - AI Level I
"""

import common
import enemy
import random
import shotB
import explosionC

class EnemyAI(enemy.Enemy):

    # rect = 2d only! width+height will be appended!
    # x_dir = 1 -> flying to right
    # x_dir = -1 -> flying to left
    def __init__(self, rect, x_dir=1):
        self.rect      = rect+[19,15]
        enemy.Enemy.__init__(self,self.rect,5*(common.diff+1),1)
        self.images    = common.images['EnemyA']
        self.speed_x   = 3*x_dir
        self.speed_y   = 3
        self.weapon    = { 'Delay':1,
                           'Type':1,
                           'Level':0,
                           'Status':0 }
        common.enemies.append(self)

    # from object.py
    def move(self):
        r = self.rect
        r[1] += self.speed_y
        if r[1] > common.resolution[1]:
            common.enemies.remove(self)
        r[0] += self.speed_x
        if r[0]+r[2] < 0 or \
        r[0] > common.resolution[0]:
            common.enemies.remove(self)
        
        w = self.weapon
        w['Delay'] -= 1
        if w['Delay'] <= 0: # shoot
            w['Delay'] = random.randrange(60,80)
            shotB.ShotB([r[0]+r[2]/2,r[1]+r[3]],w['Level'])

    # from enemy.py
    def explode(self):
        explosionC.ExplosionC([self.rect[0],self.rect[1]])
        
