Android Open Source - ssniper-andengine Item Layer






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;
/*  w w  w  .  jav  a 2 s. c  o m*/
import com.cladophora.ssniper.BaseActivity;
import com.cladophora.ssniper.ItemPool;
import com.cladophora.ssniper.scene.GameScene;
import org.andengine.entity.Entity;

import java.util.Iterator;
import java.util.LinkedList;

public class ItemLayer extends Entity {

  private static LinkedList<Item> items;
  public static ItemLayer instance;

    private static final int rollRequiredForCash = 599;
    private static final int rollRequiredForAmmo = 925;
    private static final int rollRequiredForMedkit = 975;
    private static final int rollRequiredForBriefcase = 995;


    public static ItemLayer getSharedInstance() {
        if (instance == null) {
            instance = new ItemLayer();
        }
    return instance;
  }

  public static boolean isEmpty() {
    return (items.size() == 0);
  }

  public static Iterator<Item> getIterator() {
    return items.iterator();
  }

  public static void purge() {
    getSharedInstance().detachChildren();
    for (Item i : items) {
      ItemPool.getSharedInstance().recyclePoolItem(i);
    }
    items.clear();
  }

  public ItemLayer() {
        items = new LinkedList<Item>();
    instance = this;
  }

    public static void spawnItem(final float x, final float y, final int modifier, final int enemyType) {

        final int roll = BaseActivity.r.nextInt(999);

        int mod2 = 0;
        if (enemyType == 2) {
            mod2 = 1;
        } else if (enemyType == 3) {
            mod2 = 3;
        }

        int itemType;
        int bcRequirement = rollRequiredForBriefcase - ((modifier * 5) + (modifier * mod2 * 20));
        if (roll > bcRequirement) {
            itemType = 4;
        } else if (roll > rollRequiredForMedkit - (modifier * 20)) {
            itemType = 2;
        } else if (roll > rollRequiredForAmmo - (modifier * 25)) {
            itemType = 3;
        } else if (roll > (rollRequiredForCash - ((modifier * 100)) + (mod2 * 100))) {
            itemType = 1;
        } else {
            itemType = 0;
        }

        if (itemType == 0) { return; }

        final Item item = ItemPool.getSharedInstance().obtainPoolItem();
        item.setItemType(itemType);
        item.initializeSprite();
        item.initializeHitBoxes();
        item.setPosition(x, y);
        GameScene.getSharedInstance().attachChild(item.sprite);
        GameScene.getSharedInstance().attachChild(item.hitBox);
        item.sprite.setZIndex((int) (item.sprite.getY() + item.sprite.getHeight()));
        item.sprite.setVisible(true);
        items.add(item);
    }

  @Override
  public void onDetached() {
    purge();
    clearUpdateHandlers();
    super.onDetached();
  }

    public static void show() {
        for (Item i : items) { i.sprite.setVisible(true); }
    }

    public static void hide() {
        for (Item i : items) { i.sprite.setVisible(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