Back to project page ssniper-andengine.
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.
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); } } }