"""
enemyD.py - Red fighter
"""

import common
import enemy
import random
import shotH
import explosionC

class EnemyD(enemy.Enemy):

    # rect = 2d only! width+height will be appended!
    def __init__(self, rect):        
        rect          += [23,23]
        enemy.Enemy.__init__(self,rect,20*(common.diff+1),3)
        self.images    = common.images['EnemyD']
        #for x in self.images:
        #    x.set_alpha(128)
        self.speed_y   = 3
        self.speed_x   = 2
        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[1] += self.speed_y
        if r[1] > common.resolution[1]-50:
            self.speed_y = -2
        if r[1] < 10:
            self.speed_y = 3
        r[0] += self.speed_x
        self.delay -= 1
        if self.delay <= 0:
            self.delay = 20
            self.speed_x = -self.speed_x
            
        w = self.weapon
        w['Delay'] -= 1
        if w['Delay'] <= 0: # shoot
            w['Delay'] = random.randrange(20,30)
            if self.speed_y > 0:
                shotH.ShotH([self.rect[0]+self.rect[2]/2,self.rect[1]+self.rect[3]],w['Level'])
            
    # from enemy.py
    def explode(self):
        explosionC.ExplosionC(self.rect[:2])
