Android Open Source - ninja-trials Shuriken Enemy Counter






From Project

Back to project page ninja-trials.

License

The source code is released under:

Apache License

If you think the Android project ninja-trials 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

//TODO Usar hud_head_shuriken.png
/*  w  ww.  j  a v  a2  s.co m*/
package com.madgear.ninjatrials.hud;

import org.andengine.entity.Entity;
import org.andengine.entity.sprite.AnimatedSprite;
import org.andengine.entity.sprite.Sprite;
import org.andengine.entity.text.Text;
import org.andengine.entity.text.TextOptions;
import org.andengine.opengl.texture.TextureManager;
import org.andengine.opengl.texture.TextureOptions;
import org.andengine.opengl.texture.atlas.bitmap.BitmapTextureAtlas;
import org.andengine.opengl.texture.atlas.bitmap.BitmapTextureAtlasTextureRegionFactory;
import org.andengine.opengl.texture.region.ITextureRegion;
import org.andengine.opengl.texture.region.ITiledTextureRegion;
import org.andengine.util.adt.align.HorizontalAlign;

import com.madgear.ninjatrials.managers.ResourceManager;

public class ShurikenEnemyCounter extends Entity{
  private int enemyCount, enemiesLeft;
  private AnimatedSprite enemyLogo;
  private Text exSymbol;
  private Text[] numbers;
  private float enemyLogoPosX, enemyLogoPosY, exPosX, exPosY, longNumberPosX,
  longNumberPosY, shortNumberPosX, shortNumberPosY;
  public ShurikenEnemyCounter(float posX, float posY, int enemyCount){
    this.enemyCount = enemyCount;
    enemiesLeft = enemyCount;
    
    enemyLogoPosX = posX;
    enemyLogoPosY = posY;
    exPosX = posX + 90;
    exPosY = posY - 25 -20;
    longNumberPosX = posX + 200;
    longNumberPosY = posY -20;
    shortNumberPosX = posX + 150;
    shortNumberPosY = posY -20;
    
    generateNumbers(enemyCount);
    for (Text number: numbers){
      attachChild(number);
    }
    generateEnemyLogo();
        attachChild(enemyLogo);
        generateExSymbol();
        attachChild(exSymbol);
  }
  
  public boolean setEnemiesLeft(int count){
    if(0 <= count && count <= enemyCount){
      numbers[enemiesLeft].setVisible(false);
      this.enemiesLeft = count;
      numbers[enemiesLeft].setVisible(true);      
      return true;
    }
    return false;  
  }
  
  private void generateExSymbol(){
    exSymbol = new Text(
                exPosX,
                exPosY,
                ResourceManager.getInstance().fontBig, "X",
                new TextOptions(HorizontalAlign.CENTER),
                ResourceManager.getInstance().engine
                .getVertexBufferObjectManager());
    exSymbol.setScale(.67f);
  }
  
  private void generateEnemyLogo(){    
    ITiledTextureRegion enemyLogoITTR = ResourceManager.getInstance().shurikenHead;
    enemyLogo = new AnimatedSprite(enemyLogoPosX, enemyLogoPosY, enemyLogoITTR, ResourceManager.getInstance().engine.getVertexBufferObjectManager());
    enemyLogo.setCurrentTileIndex(1);
    enemyLogo.setScale(.8f);
  }
  
  private void generateNumbers(int enemyCount){
    numbers = new Text[enemyCount + 1];
    for(int i = 0; i < enemyCount && i < 10; i++){
      numbers[i] = new Text(
          shortNumberPosX,
          shortNumberPosY,
                  ResourceManager.getInstance().fontBig,
                  Integer.toString(i),
                  new TextOptions(HorizontalAlign.CENTER),
                  ResourceManager.getInstance().engine
                  .getVertexBufferObjectManager());
      numbers[i].setScale(1.33f);
      numbers[i].setVisible(false);
    }
    for(int i = 10; i <= enemyCount; i++){
      numbers[i] = new Text(
          longNumberPosX,
          longNumberPosY,
                  ResourceManager.getInstance().fontBig,
                  Integer.toString(i),
                  new TextOptions(HorizontalAlign.CENTER),
                  ResourceManager.getInstance().engine
                  .getVertexBufferObjectManager());
      numbers[i].setScale(1.33f);
      numbers[i].setVisible(false);
    }
    numbers[enemyCount].setVisible(true);
  }
}




Java Source Code List

com.madgear.ninjatrials.AchievementsScene.java
com.madgear.ninjatrials.CharacterIntroScene.java
com.madgear.ninjatrials.ControllerOptionsScene.java
com.madgear.ninjatrials.DummyMenu.java
com.madgear.ninjatrials.GameScene.java
com.madgear.ninjatrials.IUserInput.java
com.madgear.ninjatrials.MainMenuScene.java
com.madgear.ninjatrials.MainOptionsScene.java
com.madgear.ninjatrials.ManagedLayer.java
com.madgear.ninjatrials.ManagedScene.java
com.madgear.ninjatrials.MapScene.java
com.madgear.ninjatrials.NinjaTrials.java
com.madgear.ninjatrials.PlayerSelectionScene.java
com.madgear.ninjatrials.RecordsScene.java
com.madgear.ninjatrials.ResultLoseScene.java
com.madgear.ninjatrials.ResultTrial.java
com.madgear.ninjatrials.ResultWinScene.java
com.madgear.ninjatrials.achievements.AchievementSetNinjaTrial.java
com.madgear.ninjatrials.achievements.AchievementSet.java
com.madgear.ninjatrials.achievements.Achievement.java
com.madgear.ninjatrials.hud.AchievementNotify.java
com.madgear.ninjatrials.hud.Chronometer.java
com.madgear.ninjatrials.hud.GameHUD.java
com.madgear.ninjatrials.hud.HeadCharacter.java
com.madgear.ninjatrials.hud.PowerBar.java
com.madgear.ninjatrials.hud.PrecisionAngleBar.java
com.madgear.ninjatrials.hud.PrecisionBar.java
com.madgear.ninjatrials.hud.SelectionStripe.java
com.madgear.ninjatrials.hud.ShurikenEnemyCounter.java
com.madgear.ninjatrials.hud.VolumeBar.java
com.madgear.ninjatrials.layers.GameOverLayer.java
com.madgear.ninjatrials.managers.GameManager.java
com.madgear.ninjatrials.managers.ResourceManager.java
com.madgear.ninjatrials.managers.SFXManager.java
com.madgear.ninjatrials.managers.SceneManager.java
com.madgear.ninjatrials.managers.UserData.java
com.madgear.ninjatrials.records.Record.java
com.madgear.ninjatrials.records.RecordsTableSet.java
com.madgear.ninjatrials.records.RecordsTable.java
com.madgear.ninjatrials.sequences.CreditsScene.java
com.madgear.ninjatrials.sequences.EndingScene.java
com.madgear.ninjatrials.sequences.EndingSequenceRyokoEasy.java
com.madgear.ninjatrials.sequences.EndingSequenceShoEasy.java
com.madgear.ninjatrials.sequences.Intro1Scene.java
com.madgear.ninjatrials.sequences.Intro2Scene.java
com.madgear.ninjatrials.sequences.Intro2SequenceRyokoEasy.java
com.madgear.ninjatrials.sequences.Intro2SequenceShoEasy.java
com.madgear.ninjatrials.sequences.Sequence.java
com.madgear.ninjatrials.sequences.SplashIntroScene.java
com.madgear.ninjatrials.trials.TrialSceneCut.java
com.madgear.ninjatrials.trials.TrialSceneJump.java
com.madgear.ninjatrials.trials.TrialSceneRun.java
com.madgear.ninjatrials.trials.TrialSceneShuriken.java
com.madgear.ninjatrials.trials.run.RunBg.java
com.madgear.ninjatrials.trials.run.RunCharacter.java
com.madgear.ninjatrials.trials.shuriken.ShurikenCoordinates.java
com.madgear.ninjatrials.trials.shuriken.ShurikenEnemy.java
com.madgear.ninjatrials.trials.shuriken.ShurikenHands.java
com.madgear.ninjatrials.trials.shuriken.ShurikenShuriken.java
com.madgear.ninjatrials.utils.AutoDiagonalParallaxBackground.java
com.madgear.ninjatrials.utils.AutoHorizontalParallaxBackground.java
com.madgear.ninjatrials.utils.AutoVerticalParallaxBackground.java
com.madgear.ninjatrials.utils.ParallaxBackground2d.java