Subversion Repositories AndroidProjects

Rev

Rev 941 | Rev 963 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

package com.gebauz.burutaru.game.entities;

import com.gebauz.bauzoid.math.Matrix4;
import com.gebauz.bauzoid.math.collision.AABoundingBox;
import com.gebauz.bauzoid.math.collision.Shape;

/** Abstract base class for enemies that provides access to position, hit-check, and utility functionality. */
public abstract class Enemy
{
        // Constants========================================================================================
       
        public static final float DAMAGE_COOLDOWN_TIME = 0.5f;

        // Embedded Types===================================================================================

        // Fields===========================================================================================
       
        private int mHealth = 10;
       
        /** Timer to prevent that an object is instantly killed. */
        private float mDamageCoolDown = -1.0f;

        // Methods==========================================================================================

        public Enemy(int health)
        {
                mHealth = health;
        }
       
        public void update(float deltaTime)
        {
                if (mDamageCoolDown > 0.0f)
                        mDamageCoolDown -= deltaTime;
        }
       
        public abstract void render();
       
        public void hit(int damage)
        {
                if (mDamageCoolDown >= 0.0f)
                        return;                
               
                mHealth -= damage;
               
                if (mHealth <= 0)
                {
                        die();
                        return;
                }
               
                mDamageCoolDown = DAMAGE_COOLDOWN_TIME;
        }
       
        public abstract void die();
       
        /** Similar to die, but simply vanishes. */
        public void vanish() { mHealth = -1; }
       
        /** Return true if the shape and the enemy intersect. */
        public abstract boolean checkHit(Shape shape, Matrix4 shapeTransform);
       
        // Getters/Setters==================================================================================
       
        /** Get an axis-aligned bounding box for broad-phase collision detection. */
        public abstract AABoundingBox getBounds();
       
        public final void setHealth(int health) { mHealth = health; }
        public final void addHealth(int health) { mHealth += health; }
        public final int getHealth() { return mHealth; }
        public final boolean isAlive() { return (mHealth > 0); }

        public abstract float getX();
        public abstract float getY();
       
}