Android Open Source - ssniper-andengine Item






From Project

Back to project page ssniper-andengine.

License

The source code is released under:

Apache License

If you think the Android project ssniper-andengine 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.cladophora.ssniper.entity;
//from  ww w  . jav a2 s  .  com
import com.cladophora.ssniper.BaseActivity;
import com.cladophora.ssniper.HUDManager;
import com.cladophora.ssniper.SpriteManager;
import com.cladophora.ssniper.scene.GameScene;
import org.andengine.entity.primitive.Rectangle;
import org.andengine.entity.sprite.Sprite;
import org.andengine.opengl.vbo.VertexBufferObjectManager;
import org.andengine.util.color.Color;

public class Item {
    public Rectangle hitBox;
    public Sprite sprite;
    public BaseActivity activity;
    public int itemType;
    public float width;
    public float height;

    private VertexBufferObjectManager vbom;

  public Item() {
        activity = BaseActivity.getSharedInstance();
        vbom = activity.getVertexBufferObjectManager();
        init();
   }

    public void setItemType(int n) {
        itemType = n;
    }

    public void initializeSprite() {
        switch (itemType) {
            case 1:
                sprite = new Sprite(0, 0, SpriteManager.mCashTR, vbom);
                sprite.setScaleCenter(0,0);
                sprite.detachSelf();
                sprite.setScale(GameScene.itemScale * 1.2f);
                break;
            case 2:
                sprite = new Sprite(0, 0, SpriteManager.mMedkitTR, vbom);
                sprite.setScaleCenter(0,0);
                sprite.detachSelf();
                sprite.setScale(GameScene.itemScale * 0.50f);
                break;
            case 3:
                sprite = new Sprite(0, 0, SpriteManager.mAmmoTR, vbom);
                sprite.setScaleCenter(0, 0);
                sprite.detachSelf();
                sprite.setScale(GameScene.itemScale * 0.50f);
                break;
            case 4:
                sprite = new Sprite(0, 0, SpriteManager.mBCaseTR, vbom);
                sprite.setScaleCenter(0, 0);
                sprite.detachSelf();
                sprite.setScale(GameScene.itemScale * 1.50f);
                break;
        }
    }

    public void initializeHitBoxes() {
        width = sprite.getWidthScaled();
        height = sprite.getHeightScaled();
        hitBox = new Rectangle(0, 0, width, height, vbom);

        hitBox.setScaleCenter(0, 0);
        hitBox.detachSelf();
        hitBox.setColor(Color.TRANSPARENT);
    }

  /*
  method for initializing a new instance
  used by constructor and pool class
  */
    public void init() {

  }

    public void setPosition(float x1, float y1) {
        sprite.setPosition(x1, y1);
        hitBox.setPosition(x1, y1);
    }

  public void clean() {
        hitBox.detachSelf();
        sprite.detachSelf();
    hitBox.clearEntityModifiers();
        hitBox.clearUpdateHandlers();
        sprite.clearEntityModifiers();
        sprite.clearUpdateHandlers();
    }

    public static boolean isHit(Item item) {
        if (Reticle.center.collidesWith(item.hitBox)) {
            if (item.itemType == 3) {
                Rifle.roundsLeft = Rifle.roundsLeft + 5;
            } else if (item.itemType == 2) {
                GameScene.setHP(GameScene.playerHP + 1);
            } else if (item.itemType == 1) {
                GameScene.cash = GameScene.cash + 10000;
                HUDManager.updateCashCount();
            } else if (item.itemType == 4) {
                GameScene.cash = GameScene.cash + 1000000;
                HUDManager.updateCashCount();
            }
            item.clean();

            return true;
        } else {
            return false;
        }
    }

}




Java Source Code List

com.cladophora.ssniper.BaseActivity.java
com.cladophora.ssniper.DeviceUtil.java
com.cladophora.ssniper.EnemyPool.java
com.cladophora.ssniper.GameEffects.java
com.cladophora.ssniper.GameEvents.java
com.cladophora.ssniper.GameLoopUpdateHandler.java
com.cladophora.ssniper.GameUtil.java
com.cladophora.ssniper.HUDManager.java
com.cladophora.ssniper.HoverListener.java
com.cladophora.ssniper.ItemPool.java
com.cladophora.ssniper.LevelLoader.java
com.cladophora.ssniper.PlantPool.java
com.cladophora.ssniper.SPenHoverView.java
com.cladophora.ssniper.ScopeEngine.java
com.cladophora.ssniper.SoundManager.java
com.cladophora.ssniper.SpriteManager.java
com.cladophora.ssniper.andengine.IRandomTimerCallBack.java
com.cladophora.ssniper.andengine.RandomTimerHandler.java
com.cladophora.ssniper.entity.EnemyLayer.java
com.cladophora.ssniper.entity.Enemy.java
com.cladophora.ssniper.entity.ItemLayer.java
com.cladophora.ssniper.entity.Item.java
com.cladophora.ssniper.entity.PlantLayer.java
com.cladophora.ssniper.entity.Plant.java
com.cladophora.ssniper.entity.Reticle.java
com.cladophora.ssniper.entity.Rifle.java
com.cladophora.ssniper.entity.SPen.java
com.cladophora.ssniper.scene.GameScene.java
com.cladophora.ssniper.scene.InstructionScene.java
com.cladophora.ssniper.scene.IntroScene.java
com.cladophora.ssniper.scene.MainMenuScene.java
com.cladophora.ssniper.scene.PauseScene.java
com.cladophora.ssniper.scene.ResultScene.java
com.cladophora.ssniper.scene.ShopScene.java
com.cladophora.ssniper.scene.SplashScene.java
com.cladophora.ssniper.scene.SurvivorIntroScene.java
com.cladophora.ssniper.scene.SurvivorScene.java
com.cladophora.ssniper.scene.TutorialScene.java
com.cladophora.ssniper.scene.WeaponInfoScene.java