Android Open Source - ssniper-andengine Plant






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 www .  j a  v  a 2s.  c o  m
import com.cladophora.ssniper.BaseActivity;
import com.cladophora.ssniper.SpriteManager;
import com.cladophora.ssniper.scene.GameScene;
import org.andengine.entity.sprite.Sprite;
import org.andengine.opengl.vbo.VertexBufferObjectManager;

public class Plant {
    public Plant instance;
    public Sprite sprite;
    public BaseActivity activity;
    private VertexBufferObjectManager vbom;

  public Plant() {
        instance = this;
        activity = BaseActivity.getSharedInstance();
        vbom = activity.getVertexBufferObjectManager();
        init();
   }

    /* method for initializing a new instance
    * used by constructor and pool class */
    public void init() {
        initializeSprite();
        setRandomPosition();
        sprite.setIgnoreUpdate(false);
        sprite.setVisible(true);
    }

    public void initializeSprite() {
        switch (GameScene.backgroundType) {
            case 0:
                sprite = new Sprite(0, 0, SpriteManager.mTree1TR, vbom);
                break;
            case 1:
                switch (BaseActivity.r.nextInt(6)) {
                    case 0:
                        sprite = new Sprite(0, 0, SpriteManager.mTree3TR, vbom);
                        break;
                    case 1:
                        sprite = new Sprite(0, 0, SpriteManager.mPlant1TR, vbom);
                        break;
                    case 2:
                        sprite = new Sprite(0, 0, SpriteManager.mCactus1TR, vbom);
                        break;
                    case 3:
                        sprite = new Sprite(0, 0, SpriteManager.mCactus2TR, vbom);
                        break;
                    case 4:
                        sprite = new Sprite(0, 0, SpriteManager.mCactus3TR, vbom);
                        break;
                    case 5:
                        sprite = new Sprite(0, 0, SpriteManager.mCactus4TR, vbom);
                        break;
                }
                break;
            case 2:
                switch (BaseActivity.r.nextInt(2)) {
                    case 0:
                        sprite = new Sprite(0, 0, SpriteManager.mTree2TR, vbom);
                        break;
                    case 1:
                        sprite = new Sprite(0, 0, SpriteManager.mPlant1TR, vbom);
                        break;
                }
                break;
            default:
                sprite = new Sprite(0, 0, SpriteManager.mTree1TR, vbom);
                break;
        }
        sprite.setScaleCenter(0, 0);
        sprite.setScale(GameScene.plantScale);
    }

    public void setRandomPosition() {
        float x = BaseActivity.SCOPE_SIZE + (BaseActivity.r.nextFloat() * (BaseActivity.CAMERA_WIDTH - BaseActivity.SCOPE_SIZE));
        float y = (BaseActivity.r.nextFloat() * BaseActivity.CAMERA_HEIGHT) - sprite.getHeightScaled();
        /*
        // nudge back onto screen
        if (x + sprite.getWidthScaled() > BaseActivity.CAMERA_WIDTH) {x -= (sprite.getWidthScaled() * 0.7f) + (sprite.getWidthScaled() * 0.3f) * BaseActivity.r.nextFloat();}
        if (y + sprite.getHeightScaled() > BaseActivity.CAMERA_HEIGHT) {y -= (sprite.getHeightScaled() * 0.7f) + (sprite.getHeightScaled() * 0.3f) * BaseActivity.r.nextFloat();}

        // nudge away from scope
        if (x < BaseActivity.SCOPE_SIZE) {x += (sprite.getWidthScaled() * 0.6f) + (sprite.getWidthScaled() * 0.4f) * BaseActivity.r.nextFloat();}
        if (x < BaseActivity.SCOPE_SIZE && y < BaseActivity.SCOPE_SIZE) {y += (sprite.getHeightScaled() * 0.6f) + (sprite.getHeightScaled() * 0.4f) * BaseActivity.r.nextFloat();}
        */
        setPosition(x,y);
    }

    public void setPosition(final float x, final float y) { sprite.setPosition(x, y); }

  public void clean() {
        sprite.setIgnoreUpdate(true);
        sprite.setVisible(false);
        //sprite.detachSelf();
        sprite.clearEntityModifiers();
        sprite.clearUpdateHandlers();
    }

}




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