Android Open Source - libgdx-demo-pax-britannica Debris






From Project

Back to project page libgdx-demo-pax-britannica.

License

The source code is released under:

Copyright (c) 2010 Ben Abraham, Renaud B?dard, Henk Boom, Daniel Burton, Matthew Gallant Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated ...

If you think the Android project libgdx-demo-pax-britannica 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 de.swagner.paxbritannica.background;
/*from   w  w w . j  a v  a  2  s .  c o m*/
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.g2d.Batch;
import com.badlogic.gdx.graphics.g2d.Sprite;
import com.badlogic.gdx.math.MathUtils;
import com.badlogic.gdx.math.Vector2;

import de.swagner.paxbritannica.Resources;

public class Debris extends Sprite {

  private float SPEED = 5.0f;
  private float LIFETIME = MathUtils.random(8, 12);
  private float FADE_TIME = 2;

  private float random_direction = MathUtils.random(-360, 360);
  private float random_scale = MathUtils.random() * 0.75f + 0.5f;
  private float random_speed = (MathUtils.random() * 2f) - 1f;
  private float random_opacity = MathUtils.random() * 0.35f + 0.6f;

  private Vector2 position = new Vector2();
  private Vector2 facing = new Vector2(1, 0);

  public boolean alive = true;

  private float since_alive = 0;

  private float delta;

  public Debris(Vector2 position) {
    super();
    this.position = position;
    this.setPosition(position.x, position.y);

    this.facing.rotate(random_direction);
    this.setScale(random_scale, random_scale);

    switch (MathUtils.random(0, 2)) {
    case 0:
      this.set(Resources.getInstance().debrisSmall);
      break;
    case 1:
      this.set(Resources.getInstance().debrisMed);
      break;
    default:
      this.set(Resources.getInstance().debrisLarge);
      break;
    }
  }

  @Override
  public void draw(Batch batch) {
    super.draw(batch);

    delta = Math.min(0.06f, Gdx.graphics.getDeltaTime());

    since_alive += delta;

    facing.rotate((SPEED + random_speed) * delta).nor();
    position.add(facing.scl((SPEED + random_speed) * delta));
    this.setPosition(position.x, position.y);

    if (since_alive < FADE_TIME) {
      super.setColor(1, 1, 1, Math.min((since_alive / FADE_TIME) * random_opacity, random_opacity));
    } else {
      this.setColor(1, 1, 1, Math.min(1 - (since_alive - LIFETIME + FADE_TIME) / FADE_TIME, 1) * random_opacity);
    }
    if (since_alive > LIFETIME) {
      alive = false;
      this.setColor(1, 1, 1, 0);
    }
  }

  public void reset() {
    SPEED = 5.0f;
    LIFETIME = MathUtils.random(8, 12);
    FADE_TIME = 2;

    random_direction = MathUtils.random(-360, 360);
    random_scale = MathUtils.random() * 0.75f + 0.5f;
    random_speed = (MathUtils.random() * 2f) - 1f;
    random_opacity = MathUtils.random() * 0.35f + 0.6f;

    alive = true;
    since_alive = 0;

    this.position = new Vector2(MathUtils.random(-100, 800), MathUtils.random(-100, 400));
    facing = new Vector2(1, 0);

    this.setPosition(position.x, position.y);

    this.facing.rotate(random_direction);
    this.setScale(random_scale, random_scale);
  }
}




Java Source Code List

de.swagner.paxbritannica.Bullet.java
de.swagner.paxbritannica.Collision.java
de.swagner.paxbritannica.Constants.java
de.swagner.paxbritannica.DefaultScreen.java
de.swagner.paxbritannica.GameInstance.java
de.swagner.paxbritannica.GameScreen.java
de.swagner.paxbritannica.IOSLauncher.java
de.swagner.paxbritannica.PaxBritannica.java
de.swagner.paxbritannica.Resources.java
de.swagner.paxbritannica.Ship.java
de.swagner.paxbritannica.Targeting.java
de.swagner.paxbritannica.android.AndroidLauncher.java
de.swagner.paxbritannica.background.BackgroundFXRenderer.java
de.swagner.paxbritannica.background.Debris.java
de.swagner.paxbritannica.background.Fish.java
de.swagner.paxbritannica.bomber.Bomb.java
de.swagner.paxbritannica.bomber.BomberAI.java
de.swagner.paxbritannica.bomber.Bomber.java
de.swagner.paxbritannica.client.HtmlLauncher.java
de.swagner.paxbritannica.desktop.DesktopLauncher.java
de.swagner.paxbritannica.factory.EasyEnemyProduction.java
de.swagner.paxbritannica.factory.FactoryProduction.java
de.swagner.paxbritannica.factory.HardEnemyProduction.java
de.swagner.paxbritannica.factory.MediumEnemyProduction.java
de.swagner.paxbritannica.factory.PlayerProduction.java
de.swagner.paxbritannica.factory.Production.java
de.swagner.paxbritannica.fighter.FighterAI.java
de.swagner.paxbritannica.fighter.Fighter.java
de.swagner.paxbritannica.fighter.Laser.java
de.swagner.paxbritannica.frigate.FrigateAI.java
de.swagner.paxbritannica.frigate.Frigate.java
de.swagner.paxbritannica.frigate.MissileAI.java
de.swagner.paxbritannica.frigate.Missile.java
de.swagner.paxbritannica.help.Help.java
de.swagner.paxbritannica.mainmenu.Countdown.java
de.swagner.paxbritannica.mainmenu.FactorySelector.java
de.swagner.paxbritannica.mainmenu.MainMenu.java
de.swagner.paxbritannica.particlesystem.BigBubbleParticleEmitter.java
de.swagner.paxbritannica.particlesystem.BubbleParticleEmitter.java
de.swagner.paxbritannica.particlesystem.ExplosionParticleEmitter.java
de.swagner.paxbritannica.particlesystem.ParticleEmitter.java
de.swagner.paxbritannica.particlesystem.Particle.java
de.swagner.paxbritannica.particlesystem.SparkParticleEmitter.java
de.swagner.paxbritannica.settings.Settings.java