Subversion Repositories AndroidProjects

Rev

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

package com.gebauz.burutaru.game.entities.enemies;

import com.gebauz.bauzoid.math.Vector2;
import com.gebauz.bauzoid.math.collision.Shape;
import com.gebauz.bauzoid.parser.ParseUtil;
import com.gebauz.bauzoid.parser.ScanException;
import com.gebauz.bauzoid.parser.Tokenizer;
import com.gebauz.burutaru.GameConsts;

/* A single instance of an enemy. */
public abstract class EnemyInstance
{


        // Constants========================================================================================

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

        // Fields===========================================================================================
       
        private Enemy mParent = null;
       
        public String name = "";
        //public float spawnAt = 0.0f;
       
        public boolean hasSpawned = false;
       
        public Vector2 spawnTrigger = new Vector2(GameConsts.VIRTUAL_SCREEN_WIDTH + 100, GameConsts.VIRTUAL_SCREEN_HEIGHT/2);
       
        public Vector2 spawnPosition = null;
       
        public int health = 100;
       
        // Methods==========================================================================================


        public EnemyInstance(Enemy parent, String instanceName, int defaultHealth)
        {
                mParent = parent;
                name = instanceName;
                health = defaultHealth;
        }
       
        /** Called post-init. */
        public abstract void init();
       
        /** Called when called into appearance. */
        public abstract void spawn();
       
        public abstract void exit();
       
        public abstract void update(float deltaTime);
       
        /** Just update the scroller and nothing else, to wait until spawning. */
        public abstract void updateScroll(float deltaTime);
       
        public abstract void render();
       
        public abstract void die();
       
        /** TODO: maybe add more parameters (source of damage, etc.).
         * Returns true if call actually damages (i.e. no cooldown).
         */

        public abstract boolean damage(int damage);

        public abstract void addImpulse(float x, float y);
       
        public abstract Shape getShape();
       
        public void applyDamage(int damage)
        {
                health -= damage;
                if (health <= 0)
                        die();
        }
       
        public boolean readParameter(Tokenizer t, String id) throws ScanException
        {
                if (id.equalsIgnoreCase("spawnTrigger"))
                {
                        spawnTrigger = ParseUtil.readVector2(t);
                }
                else if (id.equalsIgnoreCase("spawnPosition"))
                {
                        spawnPosition = ParseUtil.readVector2(t);
                }
                else
                {
                        return false;
                }
               
                t.readToken(";");
                return true;
        }

       
        // Getters/Setters==================================================================================

        public final Enemy getParent() { return mParent; }
       
        /*public final boolean hasSpawned()
        {
                return (mParent.getGameLogic().getLevelTimer() >= spawnAt);                            
        }*/

       
        /** Subclasses can define this to narrower definitions. */
        public boolean isAlive()
        {
                return (hasSpawned && (health > 0));
        }
}