Android Open Source - shapemergency Default Enemy






From Project

Back to project page shapemergency.

License

The source code is released under:

GNU General Public License

If you think the Android project shapemergency listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.adsg0186.shapemergency.testgame1.blobs;
/*from  w  w w .ja v  a2 s . c  o m*/
import com.adsg0186.shapemergency.testgame1.GameSound;
import com.adsg0186.shapemergency.testgame1.TargetUtils;
import com.adsg0186.shapemergency.testgame1.GameSound.SoundId;
import com.adsg0186.shapemergency.testgame1.config.GameConfig;
import com.github.adsgray.gdxtry1.engine.blob.BlobIF;
import com.github.adsgray.gdxtry1.engine.blob.decorator.BlobDecorator;
import com.github.adsgray.gdxtry1.engine.position.BlobPosition;
import com.github.adsgray.gdxtry1.engine.util.BlobFactory;
import com.github.adsgray.gdxtry1.engine.util.GameFactory;
import com.github.adsgray.gdxtry1.engine.util.PathFactory;
import com.github.adsgray.gdxtry1.engine.util.TriggerFactory;

// this default enemy "evolves" into an "angry" version of itself
// the first time it is hit.
public class DefaultEnemy extends BlobDecorator implements DamagerIF, DamagableIF, EnemyIF {

    public enum Type {
        Initial, Angry
    }

    protected int hitPoints;
    protected Type type;

    // set up stuff in this decorator constructor?
    public DefaultEnemy(BlobIF component) {
        super(component);
        hitPoints = 10;
        type = Type.Initial;
    }

    // Damagable:
    @Override public int setHitPoints(int hp) { hitPoints = hp; return hitPoints; }
    @Override public int incHitPoints(int hp) { hitPoints += hp; return hitPoints; }
    @Override public int decHitPoints(int hp) { hitPoints -= hp; return hitPoints; }
    @Override public int getHitPoints() { return hitPoints; }

    private void setAngryPath() {
        setPath(TargetUtils.chooseBackAndForthPath(position));
    }
    
    private void angryExplosion() {
        BlobIF explosion = TargetUtils.becomeAngryExplosion(this);
        world.addBlobToWorld(explosion);
    }
    
    private void leaveCluster() {
        if (cluster != null) {
            position = new BlobPosition(cluster.getPosition());
            cluster.leaveCluster(this);
        }
    }

    protected void becomeAngry() {
        if (type == Type.Initial) {
            type = Type.Angry;

            // is this where the leak is?
            BlobIF angryMe = BlobFactory.rainbowColorCycler(component, 5);
            component = angryMe;
            
            angryExplosion();
            leaveCluster(); // if part of a cluster, leave it as our path is about to become independent
            setAngryPath();
            
            // we're now worth more to kill
            hitPoints = 15;

            // also change missile source so that they are faster
            // by replacing tickDeathTrigger. And have this enemy
            // fire almost immediately (after 10 ticks)
            setLifeTime(10);
            clearTickDeathTriggers();
            registerTickDeathTrigger(GameConfig.get().angryEnemyFireLoop());
 
            /*
            // Also a N% chance that parent will move down closer to defender
            // should this be in here??
            if (TargetUtils.rnd.nextInt(100) < 25) {
                PositionIF ppos = parent.getPosition();
                ppos.setY(ppos.getY() - 5);
            }
            */
        }
    }

    // EnemyIF
    @Override
    public BlobIF reactToMissileHit(BlobIF missile) {
        BlobIF ret = this;

        // show a quick little flash message
        // at the location of the enemy to show the
        // number of points awarded? or is that too busy?
        if (type == Type.Initial) {
            becomeAngry();
            GameSound.get().playSoundId(SoundId.enemyBecomeAngry);
        } else {
                
            // explode
            GameSound.get().explosionAll();
            ret = TriggerFactory.replaceWithExplosion(this);

            // then throw some more bombs down as we die
            for (int i = 0; i < 2; i++) {
                // angryTargetMissileSource adds the target to the world.
                BlobIF bomb = TargetUtils.angryTargetMissileSource.get(this);
            }
            
            // also randomly throw down some extra hit points
            // set the hitPoints on this to negative so that
            // (a) when it collides with the ship it gives hitPoints (subtract a neg. number)
            // (b) if you shoot it, you lose points haha.
            if (GameConfig.get().dropBonusOnDeath()) {
                EnemyFactory.hitPointBonusSource.get(this);
            }
        }
        
        return ret;
    }

    @Override public int getWeight() { return 1; } 
}




Java Source Code List

com.adsg0186.shapemergency.GameActivity.java
com.adsg0186.shapemergency.GameScreen.java
com.adsg0186.shapemergency.HelpView.java
com.adsg0186.shapemergency.HighScoreView.java
com.adsg0186.shapemergency.MainActivity.java
com.adsg0186.shapemergency.SettingsView.java
com.adsg0186.shapemergency.testgame1.AngryTargetMissileSource.java
com.adsg0186.shapemergency.testgame1.BonusFactory.java
com.adsg0186.shapemergency.testgame1.BossTargetMissileSource.java
com.adsg0186.shapemergency.testgame1.CreateEnemyTrigger.java
com.adsg0186.shapemergency.testgame1.DefenderCollisionTrigger.java
com.adsg0186.shapemergency.testgame1.FiringGameTest.java
com.adsg0186.shapemergency.testgame1.GameSound.java
com.adsg0186.shapemergency.testgame1.MissileBlobSource.java
com.adsg0186.shapemergency.testgame1.MissileCollisionTrigger.java
com.adsg0186.shapemergency.testgame1.ShieldCollisionTrigger.java
com.adsg0186.shapemergency.testgame1.TargetMissileSource.java
com.adsg0186.shapemergency.testgame1.TargetUtils.java
com.adsg0186.shapemergency.testgame1.Vibrate.java
com.adsg0186.shapemergency.testgame1.blobs.BonusDropper.java
com.adsg0186.shapemergency.testgame1.blobs.BonusIF.java
com.adsg0186.shapemergency.testgame1.blobs.BossEnemy.java
com.adsg0186.shapemergency.testgame1.blobs.DamagableIF.java
com.adsg0186.shapemergency.testgame1.blobs.DamagerIF.java
com.adsg0186.shapemergency.testgame1.blobs.DefaultEnemy.java
com.adsg0186.shapemergency.testgame1.blobs.EnemyBomb.java
com.adsg0186.shapemergency.testgame1.blobs.EnemyFactory.java
com.adsg0186.shapemergency.testgame1.blobs.EnemyIF.java
com.adsg0186.shapemergency.testgame1.blobs.FiringBlobDecorator.java
com.adsg0186.shapemergency.testgame1.blobs.FlashMessage.java
com.adsg0186.shapemergency.testgame1.blobs.HitpointBonusDecorator.java
com.adsg0186.shapemergency.testgame1.blobs.ScoreTextDisplay.java
com.adsg0186.shapemergency.testgame1.blobs.ShieldRing.java
com.adsg0186.shapemergency.testgame1.config.BaseGameConfig.java
com.adsg0186.shapemergency.testgame1.config.EasyGameConfig.java
com.adsg0186.shapemergency.testgame1.config.GameConfigIF.java
com.adsg0186.shapemergency.testgame1.config.GameConfig.java
com.adsg0186.shapemergency.testgame1.config.GamePreferences.java
com.adsg0186.shapemergency.testgame1.config.InsaneGameConfig.java
com.adsg0186.shapemergency.testgame1.config.SavedGame.java