"""
enemyG.py - Gray ufo
"""

import common
import enemy
import random
import shotJ
import explosionD

class EnemyG(enemy.Enemy):

    # rect = 2d only! width+height will be appended!
    def __init__(self, rect):        
        rect          += [21,17]
        enemy.Enemy.__init__(self,rect,20*(common.diff+1),1)
        self.images    = common.images['EnemyG']
        self.speed_y   = 3
        self.speed_x   = 3
        self.max_speed = 3
        self.weapon    = { 'Delay':1,
                           'Type':1,
                           'Level':0,
                           'Status':0 }
        common.enemies.append(self)
        self.delay = 20

    # from object.py
    def move(self):
        r = self.rect
        r[0] += self.speed_x
        r[1] += self.speed_y

        if random.randrange(1000) < 10:
            # change direction
            if random.randrange(2):
                self.speed_x *= -1
            else:
                self.speed_y *= -1
        
        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
        if r[1] < r[3]:
            self.speed_y = self.max_speed
        elif r[1] > common.resolution[1]-r[3]:
            self.speed_y = -self.max_speed
            
        w = self.weapon
        w['Delay'] -= 1
        if w['Delay'] <= 0: # shoot
            w['Delay'] = random.randrange(80,120)
            shotJ.ShotJ([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])
