Android Open Source - ssniper-andengine Game Effects






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;
// w ww .  j av  a 2s. c  om
import org.andengine.engine.handler.timer.ITimerCallback;
import org.andengine.engine.handler.timer.TimerHandler;
import org.andengine.entity.IEntity;
import org.andengine.entity.IEntityFactory;
import org.andengine.entity.particle.ParticleSystem;
import org.andengine.entity.particle.emitter.PointParticleEmitter;
import org.andengine.entity.particle.initializer.VelocityParticleInitializer;
import org.andengine.entity.particle.modifier.AlphaParticleModifier;
import org.andengine.entity.particle.modifier.RotationParticleModifier;
import org.andengine.entity.primitive.Rectangle;
import org.andengine.ui.activity.SimpleBaseGameActivity;
import org.andengine.util.color.Color;

/**
 * Created by jmar on 1/26/14.
 */
public class GameEffects {
    public static void createExplosion(final float posX, final float posY, final IEntity target, final SimpleBaseGameActivity activity) {
        final int nParticles = 128;
        final float effectDuration = GameEvents.ENEMY_DEATH_ANIMATION_DURATION / 0.6f;
        final float particleSizeX = 2 / target.getScaleX();
        final float particleSizeY = 2 / target.getScaleY();

        PointParticleEmitter particleEmitter = new PointParticleEmitter(posX, posY);
        IEntityFactory<Rectangle> recFact = new IEntityFactory<Rectangle>() {
            @Override
            public Rectangle create(final float pX, final float pY) {
                Rectangle rect = new Rectangle(posX, posY, particleSizeX, particleSizeY, activity.getVertexBufferObjectManager());
                rect.setColor(Color.RED);
                return rect;
            }
        };
        final ParticleSystem<Rectangle> particleSystem = new ParticleSystem<Rectangle>(recFact, particleEmitter, 800, 1500, nParticles);

        particleSystem.addParticleInitializer(new VelocityParticleInitializer<Rectangle>(-150, 0, -60, 30));
        particleSystem.addParticleModifier(new AlphaParticleModifier<Rectangle>(0, 0.6f * effectDuration, 1, 0));
        particleSystem.addParticleModifier(new RotationParticleModifier<Rectangle>(0, effectDuration, 0, 360));
        particleSystem.setX(posX);
        particleSystem.setY(posY);
        target.attachChild(particleSystem);

        target.registerUpdateHandler(
                new TimerHandler(effectDuration,
                        new ITimerCallback() {
                            @Override
                            public void onTimePassed(final TimerHandler pTimerHandler) {
                                particleSystem.detachSelf();
                                //target.sortChildren();
                                target.unregisterUpdateHandler(pTimerHandler);
                            }
                        }
                )
        );
    }

    public static void createSmallExplosion(final float posX, final float posY, final IEntity target, final SimpleBaseGameActivity activity) {
        final int nParticles = 64;
        final float effectDuration = GameEvents.ENEMY_DEATH_ANIMATION_DURATION * 2;
        final float particleSizeX = 2 / target.getScaleX();
        final float particleSizeY = 2 / target.getScaleY();

        PointParticleEmitter particleEmitter = new PointParticleEmitter(posX, posY);
        IEntityFactory<Rectangle> recFact = new IEntityFactory<Rectangle>() {
            @Override
            public Rectangle create(final float pX, final float pY) {
                Rectangle rect = new Rectangle(posX, posY, particleSizeX, particleSizeY, activity.getVertexBufferObjectManager());
                rect.setColor(Color.RED);
                return rect;
            }
        };
        final ParticleSystem<Rectangle> particleSystem = new ParticleSystem<Rectangle>(recFact, particleEmitter, 350, 500, nParticles);

        particleSystem.addParticleInitializer(new VelocityParticleInitializer<Rectangle>(-40, 40, -80, 20));
        particleSystem.addParticleModifier(new AlphaParticleModifier<Rectangle>(0, 0.6f * effectDuration, 1, 0));
        particleSystem.addParticleModifier(new RotationParticleModifier<Rectangle>(0, effectDuration, 0, 360));
        particleSystem.setX(posX);
        particleSystem.setY(posY);
        target.attachChild(particleSystem);

        target.registerUpdateHandler(
                new TimerHandler(effectDuration,
                        new ITimerCallback() {
                            @Override
                            public void onTimePassed(final TimerHandler pTimerHandler) {
                                particleSystem.detachSelf();
                                //target.sortChildren();
                                target.unregisterUpdateHandler(pTimerHandler);
                            }
                        }
                )
        );
    }
}




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