Android Open Source - ssniper-andengine S Pen






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.  j  a v  a2  s.  c om*/
import com.cladophora.ssniper.BaseActivity;
import com.cladophora.ssniper.R;
import org.andengine.entity.sprite.Sprite;
import org.andengine.entity.text.Text;
import org.andengine.opengl.texture.TextureOptions;
import org.andengine.opengl.texture.atlas.bitmap.BitmapTextureAtlas;
import org.andengine.opengl.texture.atlas.bitmap.BitmapTextureAtlasTextureRegionFactory;
import org.andengine.opengl.texture.region.ITextureRegion;
import org.andengine.opengl.vbo.VertexBufferObjectManager;
import org.andengine.util.color.Color;

/**
 * Created by jmar on 1/27/14.
 */
public class SPen {
    public static SPen instance;
    public static Sprite spenSprite;
    private static BitmapTextureAtlas spenBTA;
    private static ITextureRegion spenTR;
    public static Text spenButtonText;
    public static Text spenText;

    public SPen() {
        init();
    }

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

    public static void init() {
        loadResources();
        initializeSprite();
        initializeText();
        setEntityPositions();
        attachChildren();
    }

    public static void loadResources() {
        spenBTA = new BitmapTextureAtlas(BaseActivity.getSharedInstance().getTextureManager(), 512, 512, TextureOptions.BILINEAR);
        spenTR = BitmapTextureAtlasTextureRegionFactory.createFromAsset(spenBTA, BaseActivity.getSharedInstance(), "spen.png", 0, 0);
        spenBTA.load();
    }

    public static void initializeSprite() {
        spenSprite = new Sprite(0,0,spenTR,BaseActivity.getSharedInstance().getVertexBufferObjectManager());
    }

    public static void initializeText() {
        final VertexBufferObjectManager vbom = BaseActivity.getSharedInstance().getVertexBufferObjectManager();
        spenButtonText = new Text(0,0,BaseActivity.mNotoSansFont,BaseActivity.getSharedInstance().getString(R.string.activateslowtime), vbom);
        spenText = new Text(0,0,BaseActivity.mNotoSansFont,BaseActivity.getSharedInstance().getString(R.string.hoveraimtapfire), vbom);
        spenButtonText.setColor(Color.BLACK);
        spenText.setColor(Color.BLACK);
    }

    public static void setEntityPositions() {
        float spenLeftPadding;
        if (spenButtonText.getWidth() > spenText.getWidth()) {
            spenLeftPadding = spenButtonText.getWidth();
        } else {
            spenLeftPadding = spenText.getWidth();
        }

        float x0 = BaseActivity.SCOPE_SIZE + spenLeftPadding;
        float y0 = BaseActivity.CAMERA_HEIGHT;
        setPosition(x0,y0);
        spenSprite.setScale(1.0f);

        float spenSizeRatio = (spenSprite.getWidth() + spenLeftPadding) / (BaseActivity.CAMERA_WIDTH - BaseActivity.SCOPE_SIZE);

        if (spenSizeRatio > 1) {
            spenSprite.setScale(1 / spenSizeRatio);
        }

        spenButtonText.setPosition(-spenButtonText.getWidth(), 107 - (spenButtonText.getHeight() / 2));
        spenText.setPosition(-spenText.getWidth(), 263 - (spenText.getHeight() / 2));
    }

    public static void attachChildren() {
        spenButtonText.detachSelf();
        spenText.detachSelf();
        spenSprite.attachChild(spenButtonText);
        spenSprite.attachChild(spenText);
    }

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

    public static void pointTo(final float x, final float y) {
        spenSprite.setPosition(x - (spenSprite.getWidthScaled() * 0.1f),y - spenSprite.getHeightScaled());
    }

    public static void setScale(final float scale) {
        spenSprite.setScaleCenter(0, 0);
        spenSprite.setScale(scale);
    }
}




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