Android Open Source - ssniper-andengine Plant 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;
//from  ww  w  .j  a va2s . co  m
import com.cladophora.ssniper.BaseActivity;
import com.cladophora.ssniper.PlantPool;
import com.cladophora.ssniper.scene.GameScene;
import org.andengine.entity.Entity;

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

public class PlantLayer extends Entity {

    public static LinkedList<Plant> plants;
  public static PlantLayer instance;
  public int plantCount;
    public BaseActivity activity;

    final public static float[] plantBounds = {0.05f, 0.90f, 0.75f, 0.33f};
    final public static float upperBound = plantBounds[0]; // top bound
    final public static float rightBound = plantBounds[1]; // right bound
    final public static float lowerBound = plantBounds[2]; // bottom bound
    final public static float leftBound = plantBounds[3]; // left bound
    final public static float plant_BOUNDS_WIDTHRATIO = rightBound - leftBound;
    final public static float plant_BOUNDS_HEIGHTRATIO = lowerBound - upperBound;

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

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

    public static int size() { return (plants.size()); }

  public static Iterator<Plant> getIterator() {
    return plants.iterator();
  }

    public void purge() {
    for (Plant plant : plants) {
            PlantPool.getSharedInstance().recyclePoolItem(plant);
    }
        plants.clear();
  }

  public PlantLayer(int x) {
        activity = BaseActivity.getSharedInstance();
        plants = new LinkedList<Plant>();
    instance = this;
    plantCount = x;
  }

    public void addPlants(int n) {
        for (int i = 0; i < n; i++) {
            final Plant plant = PlantPool.getSharedInstance().obtainPoolItem();
            GameScene.getSharedInstance().attachChild(plant.sprite);
            plant.sprite.setZIndex((int) (plant.sprite.getY() + plant.sprite.getHeight()));
            plants.add(plant);
        }
    }

    public static void addPlantsRandomly() {
        clear();
        int nPlants = 3 + BaseActivity.r.nextInt(3);
        getSharedInstance().addPlants(nPlants);
    }

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

    public static void clear() {
        getSharedInstance().purge();
    }

    public static void show() {
        for (Plant p : plants) { p.sprite.setVisible(true); }
    }

    public static void hide() {
        for (Plant p : plants) { p.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