Android Open Source - libgdx-demo-pax-britannica Game Instance






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;
//ww  w  .  j av  a  2 s.c om
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Preferences;
import com.badlogic.gdx.Application.ApplicationType;
import com.badlogic.gdx.graphics.g2d.TextureAtlas;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.utils.Array;

import de.swagner.paxbritannica.bomber.Bomb;
import de.swagner.paxbritannica.bomber.Bomber;
import de.swagner.paxbritannica.factory.FactoryProduction;
import de.swagner.paxbritannica.fighter.Fighter;
import de.swagner.paxbritannica.fighter.Laser;
import de.swagner.paxbritannica.frigate.Frigate;
import de.swagner.paxbritannica.frigate.Missile;
import de.swagner.paxbritannica.particlesystem.BigBubbleParticleEmitter;
import de.swagner.paxbritannica.particlesystem.ExplosionParticleEmitter;
import de.swagner.paxbritannica.particlesystem.BubbleParticleEmitter;
import de.swagner.paxbritannica.particlesystem.SparkParticleEmitter;

public class GameInstance {
  
  public boolean debugMode = false;

  public Array<Ship> fighters = new Array<Ship>();
  public Array<Ship> factorys = new Array<Ship>();
  public Array<Ship> bombers = new Array<Ship>();
  public Array<Ship> frigates = new Array<Ship>();

  public Array<Bullet> bullets = new Array<Bullet>();

  public BubbleParticleEmitter bubbleParticles = new BubbleParticleEmitter();
  public BigBubbleParticleEmitter bigBubbleParticles = new BigBubbleParticleEmitter();

  public SparkParticleEmitter sparkParticles = new SparkParticleEmitter();
  public ExplosionParticleEmitter explosionParticles = new ExplosionParticleEmitter();
  public int difficultyConfig = 0;
  public int factoryHealthConfig = 0;
  public int antiAliasConfig = 0;  

  public static GameInstance instance;

  public static GameInstance getInstance() {
    if (instance == null) {
      instance = new GameInstance();
    }
    return instance;
  }
  
  public void resetGame() {
    fighters.clear();
    factorys.clear();
    bombers.clear();
    frigates.clear();
    bullets.clear();
    
    bubbleParticles.dispose();
    bigBubbleParticles.dispose();
    sparkParticles.dispose();
    explosionParticles.dispose();

    bubbleParticles = new BubbleParticleEmitter();
    bigBubbleParticles = new BigBubbleParticleEmitter();

    sparkParticles = new SparkParticleEmitter();
    explosionParticles = new ExplosionParticleEmitter();
    
    Preferences prefs = Gdx.app.getPreferences("paxbritannica");
    GameInstance.getInstance().difficultyConfig  = prefs.getInteger("difficulty",0);
    GameInstance.getInstance().factoryHealthConfig  = prefs.getInteger("factoryHealth",0);
    GameInstance.getInstance().antiAliasConfig  = prefs.getInteger("antiAliasConfig",1);
  }

  public void bulletHit(Ship ship, Bullet bullet) {
    bullet.facing.nor();
    float offset=0;
    if(ship instanceof FactoryProduction) offset = 50;
    if(ship instanceof Frigate) offset = 20;
    if(ship instanceof Bomber) offset = 10;
    if(ship instanceof Fighter) offset = 10;
    Vector2 pos = new Vector2().set(bullet.collisionCenter.x + (offset * bullet.facing.x), bullet.collisionCenter.y + (offset * bullet.facing.y));

    // ugh. . .
    Vector2 bullet_vel = new Vector2().set(bullet.velocity);

    Vector2 bullet_dir;
    if (bullet_vel.dot(bullet_vel) == 0) {
      bullet_dir = new Vector2();
    } else {
      bullet_dir = bullet_vel.nor();
    }
    Vector2 vel = new Vector2(bullet_dir.x * 1.5f, bullet_dir.y * 1.5f);

    if (bullet instanceof Laser) {
      laser_hit(pos, vel);
    } else if (bullet instanceof Bomb) {
      explosionParticles.addMediumExplosion(bullet.position);
    } else if (bullet instanceof Missile) {
      explosionParticles.addTinyExplosion(bullet.position);
    }
  }

  public void laser_hit(Vector2 pos, Vector2 vel) {
    sparkParticles.addLaserExplosion(pos, vel);
  }

  public void explode(Ship ship) {
    explode(ship, ship.collisionCenter);
  }

  public void explode(Ship ship, Vector2 pos) {

    if (ship instanceof FactoryProduction) {
      explosionParticles.addBigExplosion(pos);
    } else if (ship instanceof Bomber) {
      explosionParticles.addMediumExplosion(pos);
    } else if (ship instanceof Frigate) {
      explosionParticles.addMediumExplosion(pos);
    }else {
      explosionParticles.addSmallExplosion(pos);
    }
  }

}




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