Android Open Source - SpaceGame Particles






From Project

Back to project page SpaceGame.

License

The source code is released under:

Copyright (c) 2012 ??ukasz Patalas Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the So...

If you think the Android project SpaceGame 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.lpatalas.spacegame;
//  ww  w  .  j  a  v a 2  s.  c o  m
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.files.FileHandle;
import com.badlogic.gdx.graphics.g2d.ParticleEffect;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.math.Vector2;

import java.util.ArrayList;
import java.util.List;

/**
 * User: Lukasz
 * Date: 12.08.12
 */
class Particles {
  private static final String EXPLOSION_EFFECT_NAME = "explosion";
  private static final String PARTICLES_DIRECTORY = "particles/";

  private final List<ParticleEffect> activeEffects = new ArrayList<ParticleEffect>();
  private ParticleEffect explosionEffect;
  private FileHandle particlesImageDir;

  public Particles() {
  }

  public void addExplosion(Vector2 position) {
    ParticleEffect explosion = new ParticleEffect(explosionEffect);
    explosion.setPosition(position.x, position.y);
    explosion.start();
    activeEffects.add(explosion);
  }

  public void update() {
    removeCompletedEffects();
  }

  private void removeCompletedEffects() {
    for (int i = activeEffects.size() - 1; i >= 0; i--) {
      if (activeEffects.get(i).isComplete()) {
        activeEffects.remove(i);
      }
    }
  }

  public void render(SpriteBatch spriteBatch, float dt) {
    for (ParticleEffect effect : activeEffects) {
      effect.draw(spriteBatch, dt);
    }
  }

  public void load() {
    particlesImageDir = Gdx.files.internal(PARTICLES_DIRECTORY);
    explosionEffect = loadParticleEffect(EXPLOSION_EFFECT_NAME);
  }

  private ParticleEffect loadParticleEffect(String effectName) {
    ParticleEffect effect = new ParticleEffect();

    FileHandle effectFile = getEffectFileHandle(effectName);
    effect.load(effectFile, particlesImageDir);

    return effect;
  }

  private FileHandle getEffectFileHandle(String effectName) {
    String fullPath = PARTICLES_DIRECTORY + effectName + ".effect";
    return Gdx.files.internal(fullPath);
  }
}




Java Source Code List

com.lpatalas.spacegame.Assets.java
com.lpatalas.spacegame.Asteroid.java
com.lpatalas.spacegame.Asteroids.java
com.lpatalas.spacegame.CloudLayer.java
com.lpatalas.spacegame.Clouds.java
com.lpatalas.spacegame.DesktopStarter.java
com.lpatalas.spacegame.GameplayScreen.java
com.lpatalas.spacegame.MainMenuScreen.java
com.lpatalas.spacegame.Particles.java
com.lpatalas.spacegame.PlayerInputProcessor.java
com.lpatalas.spacegame.Player.java
com.lpatalas.spacegame.SpaceGameActivity.java
com.lpatalas.spacegame.SpaceGame.java
com.lpatalas.spacegame.Stars.java