Android Open Source - shapemergency Boss 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;
/* ww  w  . j av  a2  s .  c  o m*/
import com.adsg0186.shapemergency.testgame1.BossTargetMissileSource;
import com.adsg0186.shapemergency.testgame1.GameSound;
import com.adsg0186.shapemergency.testgame1.TargetUtils;
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.position.PositionIF;
import com.github.adsgray.gdxtry1.engine.util.PositionFactory;
import com.github.adsgray.gdxtry1.engine.util.TriggerFactory;
import com.github.adsgray.gdxtry1.engine.velocity.BlobVelocity;
import com.github.adsgray.gdxtry1.engine.velocity.VelocityIF;

public class BossEnemy extends BlobDecorator implements DamagerIF, DamagableIF, EnemyIF {

    // TODO: put all of this into GameConfig
    protected int hitPoints = 75;
    protected PositionIF aimTarget;
    protected int bonusAfterHitChance = 25; 
    protected int goLowerTickCount = 400;
    BlobSource missileSource;

    public BossEnemy(BlobIF component, PositionIF aimTarget) {
        super(component);
        this.aimTarget = aimTarget;
        hitPoints += 5 * GameConfig.get().getNumBossesKilled();
        missileSource = new BossTargetMissileSource(aimTarget);
    }
    
    protected void sendAimedBombs(int howMany) {
        for (int i = 0; i < howMany; i++) {
            // send an aimed bomb
            BlobIF bomb = missileSource.get(this);
            bomb.setWorld(world);
            world.addTargetToWorld(bomb);
        }
    }
    
    protected void sendBonuses(int howMany) {
         for (int i = 0; i < howMany; i++) {
            BlobIF b = EnemyFactory.hitPointBonusSource.get(this);
            b.setTickPause(TargetUtils.rnd.nextInt(20));
        }       
    }
    
    // called when this enemy has died
    protected BlobIF died() {
        // throw out a bunch of bombs
        // TODO: put these in GameConfig
        sendAimedBombs(4);
        sendBonuses(1);
        // two for good measure
        GameSound.get().explosionLong();
        GameSound.get().explosionLong();
        GameConfig.get().incBossesKilled();
        return TriggerFactory.replaceWithExplosion(this);
    }

    @Override
    public BlobIF reactToMissileHit(BlobIF missile) {
        int hpToDeduct = 5;

        // TODO: make missiles into DamagerIFs??
        // is that possible with the way that
        // collision triggers work?
        if (missile instanceof DamagerIF) {
            hpToDeduct = ((DamagerIF)missile).getHitPoints();
        }

        hitPoints -= hpToDeduct;
        
        if (hitPoints <= 0) {
            return died();
        }
        
        // send some aimed bombs 
        // any number more than 1 makes it waaaay too difficult
        sendAimedBombs(1);
        
        if (TargetUtils.rnd.nextInt(100) < bonusAfterHitChance) {
            sendBonuses(1);
        }
        
        return this;
    }

    // DamagableIF
    @Override public int setHitPoints(int hp) { hitPoints = hp; return hitPoints; }
    @Override public int incHitPoints(int hp) { return setHitPoints(hp + hitPoints); }
    @Override public int decHitPoints(int hp) { return setHitPoints(hitPoints - hp); }
    // this is how much each hit is worth in terms of points...
    @Override public int getHitPoints() { return 15; }
    
    @Override public Boolean tick() {
        ticks++;
        if (ticks % goLowerTickCount == 0) {
            PositionIF p = getPosition();
            p.setY(p.getY() - 5);
        }
        return component.tick();
    }

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




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