Android Open Source - libgdx-demo-pax-britannica Factory Selector






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.mainmenu;
/*from  w ww. j a v a 2s  .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 com.badlogic.gdx.math.Vector3;
import com.badlogic.gdx.math.collision.BoundingBox;

import de.swagner.paxbritannica.Resources;

public class FactorySelector extends Sprite {

  public boolean picked = false;
  public boolean playerSelect = false;
  public boolean cpuSelect = false;

  public BoundingBox collision = new BoundingBox();
  public BoundingBox collisionPlayerSelect = new BoundingBox();
  public BoundingBox collisionCPUSelect = new BoundingBox();
  public Vector3 collisionMinVector = new Vector3();
  public Vector3 collisionMaxVector = new Vector3();
  
  private float fade = 0.2f;
  private float fadeButton = 0.0f;

  private float pulse_time = 0;  
  
  private Sprite button;
  private Sprite aCpuButton;
  private Sprite aPlayerButton;
  private Sprite cpuButton;
  private Sprite playerButton;
  
  float delta;
  
  private Vector2 position = new Vector2();
  
//  Mesh darkSection;
//  Mesh lightSection;
  
  public FactorySelector(Vector2 position, int id) {
    super();
    this.position = position;
    this.setPosition(position.x, position.y);

    switch (id) {
    case 1:
      this.set(Resources.getInstance().factoryP1);
      break;
    case 2:
      this.set(Resources.getInstance().factoryP2);
      break;
    case 3:
      this.set(Resources.getInstance().factoryP3);
      break;
    default:
      this.set(Resources.getInstance().factoryP4);
      break;
    }
    setRotation(90);
    this.setPosition(position.x, position.y);
    this.setColor(0, 0, 0, 1);

    button = new Sprite(Resources.getInstance().aButton);
    button.setPosition(position.x+70f,position.y + 35.f);
    
    aCpuButton = new Sprite(Resources.getInstance().aCpuButton);
    aCpuButton.setPosition(position.x+70f,position.y + 35.f);
    
    aPlayerButton = new Sprite(Resources.getInstance().aPlayerButton);
    aPlayerButton.setPosition(position.x+70f,position.y + 35.f);
    
    cpuButton = new Sprite(Resources.getInstance().cpuButton);
    cpuButton.setPosition(position.x+30f,position.y -0.f);
    
    playerButton = new Sprite(Resources.getInstance().playerButton);
    playerButton.setPosition(position.x+30f,position.y + 70.f);
    
    float pulse = (1 + MathUtils.cos((pulse_time/180.f)*2.f*MathUtils.PI))/2.f;
    float color = fade * pulse + 1 * (1-pulse);
    this.setColor(color, color, color, 1);
    button.setColor(color, color, color, 1);
    cpuButton.setColor(color, color, color, 1);  
  }
  
  public void reset() {
    picked = false;
    cpuSelect = false;
    playerSelect = false;
    
    fade = 0.2f;
    fadeButton = 0.0f;

    pulse_time = 0;    
    float pulse = (1 + MathUtils.cos((pulse_time/180.f)*2.f*MathUtils.PI))/2.f;
    float color = fade * pulse + 1 * (1-pulse);
    this.setColor(color, color, color, 1);
    button.setColor(color, color, color, 1);
    cpuButton.setColor(color, color, color, 1);  
  }

  @Override
  public void draw(Batch batch) {
    
    
    delta = Math.min(0.06f, Gdx.graphics.getDeltaTime());
    
    super.draw(batch);
    
    collisionMinVector.set(this.getVertices()[0], this.getVertices()[1], -10);
    collisionMaxVector.set(this.getVertices()[10], this.getVertices()[11], 10);
    collision.set(collisionMinVector,collisionMaxVector);
    
    collisionMinVector.set(this.getVertices()[0], this.getVertices()[1], -10);
    collisionMaxVector.set(this.getVertices()[10], this.getVertices()[11], 10);
    collisionMinVector.y += ((this.getVertices()[11]-this.getVertices()[1])/2);
    collisionPlayerSelect.set(collisionMinVector,collisionMaxVector);
    
    collisionMinVector.set(this.getVertices()[0], this.getVertices()[1], -10);
    collisionMaxVector.set(this.getVertices()[10], this.getVertices()[11], 10);
    collisionMaxVector.y -= ((this.getVertices()[11]-this.getVertices()[1])/2);
    collisionCPUSelect.set(collisionMinVector,collisionMaxVector);
    
    
    pulse_time += Gdx.graphics.getDeltaTime();

    float pulse = (1 + MathUtils.cos((pulse_time/5.f)*2.f*MathUtils.PI))/2.f;
    float color = fade * pulse + 1 * (1-pulse);
        
    if(picked && !(playerSelect || cpuSelect)) {
      button.draw(batch);
      button.setColor(0.2f, 0.2f, 0.2f, 1);
    } else {
      if(playerSelect) {
        aPlayerButton.draw(batch);
        aPlayerButton.setColor(color, color, color, 1);
      } else if(cpuSelect) {
        aCpuButton.draw(batch);
        aCpuButton.setColor(color, color, color, 1);
      } else {
        button.draw(batch);
        button.setColor(color, color, color, 1);
      }
    }
    
    if(picked && !(playerSelect || cpuSelect)) {
      fade = 0.2f;
        this.setColor(fade, fade, fade, 1);
      
        fadeButton = Math.min(fadeButton +delta, 1);
      cpuButton.setColor(fadeButton, fadeButton, fadeButton, 1);
        cpuButton.draw(batch);
        
      playerButton.setColor(fadeButton, fadeButton, fadeButton, 1);
        playerButton.draw(batch);

    } else if(playerSelect || cpuSelect) {
        fade = Math.min(fade +delta, 1);
        this.setColor(fade, fade, fade, 1);
        
      fadeButton = Math.max(fadeButton -delta, 0);
      if(cpuSelect) {
        cpuButton.setColor(0, 0, 0, fadeButton);
          cpuButton.draw(batch);
      } else {
        cpuButton.setColor(fadeButton, fadeButton, fadeButton, fadeButton);
          cpuButton.draw(batch);
      }
        
      if(playerSelect) {
        playerButton.setColor(0, 0, 0, fadeButton);
          playerButton.draw(batch);
      } else {
        playerButton.setColor(fadeButton, fadeButton, fadeButton, fadeButton);
          playerButton.draw(batch);
      }
    }

    
  }
}




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