"""
enemy.py - general enemy type class - do not instantiate
"""

import common
import object
import pygame
import random
import goodieA

class Enemy(object.Object):

    def __init__(self,rect,alive,points):
        object.Object.__init__(self,rect,alive)
        self.points = points
        self.damage = 50

    def gotHit(self,shot):
        if hasattr(self,'shield') and self.shield:
            self.shield -= shot.damage
            if self.shield < 0: self.shield = 0
            self.hitShield()
        else:
            self.alive -= shot.damage
            if self.alive <= 0:
                self.kill()

    def kill(self):
        if self.alive > 100:
            self.alive -= 100
            return
        if hasattr(self,'last_rect'):
            r = self.last_rect
        else: r = self.rect
        self.hide()
        r = self.optimizeDirtyRect(r)
        pygame.display.update(r)

        self.explode()
        common.sound.big_explode()

        common.player.addPoints(self.points)
        common.enemies.remove(self)
        if random.randrange(100) < 15:
            goodieA.GoodieA(self.rect[:2])

    #
    # do override these functions:
    #
    def explode(self): pass
    
