Android Open Source - square-libgdx Lost Screen






From Project

Back to project page square-libgdx.

License

The source code is released under:

GNU General Public License

If you think the Android project square-libgdx 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 screens;
//w w w  .ja  v  a  2  s. c o m


import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Screen;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.GL10;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.Texture.TextureFilter;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.graphics.g2d.Sprite;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.g2d.TextureAtlas;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator;
import com.badlogic.gdx.scenes.scene2d.InputEvent;
import com.badlogic.gdx.scenes.scene2d.InputListener;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.scenes.scene2d.ui.Label;
import com.badlogic.gdx.scenes.scene2d.ui.Label.LabelStyle;
import com.badlogic.gdx.scenes.scene2d.ui.Skin;
import com.badlogic.gdx.scenes.scene2d.ui.Table;
import com.badlogic.gdx.scenes.scene2d.ui.TextButton;
import com.badlogic.gdx.scenes.scene2d.ui.TextButton.TextButtonStyle;
import com.badlogic.gdx.scenes.scene2d.utils.ClickListener;
import com.denzyldick.square.BackgroundAnimation;
import com.denzyldick.square.Font;
import com.denzyldick.square.SoundManager;
import com.denzyldick.square.SquareMain;

public class LostScreen implements Screen {
  
  private SquareMain game;
  private TextButton tryAgainButton, menuButton;
  private Label heading;
  private final float buttonPadding = 5;
  private final float buttonBottomSpacing = 3;
  private SoundManager sound;  
  private SpriteBatch batch;
  private TextureAtlas atlas;
  private Skin skin;
  private Stage stage;
  private Table table;
  private OrthographicCamera camera;
  private BackgroundAnimation backgroundAnimation;
  private String currentLevel;
  private Font font;
  
  public LostScreen(SquareMain game) {
    // TODO Auto-generated constructor stub
    this.game = game;
    backgroundAnimation = new BackgroundAnimation();
    font = new Font();
    sound  = new SoundManager();

  }

  @Override
  public void render(float delta) {
    // TODO Auto-generated method stub

    Gdx.gl.glClearColor(1,35,3,1);
    Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);    
    batch.begin();    
    batch.end();
    backgroundAnimation.draw(batch);  
    stage.act(delta);
    stage.draw();
  }

  @Override
  public void resize(int width, int height) {
    // TODO Auto-generated method stub
    table.invalidateHierarchy();
    table.setSize(width,height);
    stage.setViewport(width, height, true);
    
  }

  @Override
  public void show() {
    // TODO Auto-generated method stub
    float w = Gdx.graphics.getWidth();
    float h = Gdx.graphics.getHeight();
    
    camera = new OrthographicCamera(1, h/w);
    batch = new SpriteBatch(); 
      
    atlas = game.manager.get("ui/button.pack",TextureAtlas.class);
    skin = new Skin(atlas);
  
    stage = new Stage();
    Gdx.input.setInputProcessor(stage);
    
    table = new Table(skin);
  
    table.setBounds(0, stage.getHeight()/4, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
    
    TextButtonStyle  textButtonStyle = new TextButtonStyle();
    textButtonStyle.up = skin.getDrawable("button.normal");
    textButtonStyle.down = skin.getDrawable("button.normal");

    textButtonStyle.pressedOffsetX = 1;
    textButtonStyle.pressedOffsetY = -1;
    textButtonStyle.font = font.getFont();
    tryAgainButton = new TextButton("try again",textButtonStyle);
    tryAgainButton.pad(buttonPadding);

    tryAgainButton.addListener( new InputListener()
    {
      public boolean touchDown (InputEvent event, float x, float y, int pointer, int button) {
        sound.buttonClick();
        new GameMenu(game).setStage(currentLevel);
        return true;
      }

      
    });
    
    menuButton = new TextButton("menu",textButtonStyle);
    menuButton.pad(buttonPadding);

    menuButton.addListener( new InputListener()
    {
      public boolean touchDown (InputEvent event, float x, float y, int pointer, int button) {
        sound.buttonClick();
        game.setScreen(game.menu);
        return true;
      }

      
    });
    LabelStyle headingStyle = new LabelStyle(font.getFont(),Color.RED);

    heading = new Label("bad luck !", headingStyle);

    table.add(heading).spaceBottom(buttonBottomSpacing);
    table.row();
    table.add(tryAgainButton).spaceBottom(buttonBottomSpacing);
  
    table.row();

    table.add(menuButton).spaceBottom(buttonBottomSpacing);
    
    table.debug();
    stage.addActor(table);
    
  
  }
  public void setCurrentLevel(String level)
  {
    currentLevel = level;
  }
  @Override
  public void hide() {
    // TODO Auto-generated method stub
    
  }

  @Override
  public void pause() {
    // TODO Auto-generated method stub
    
  }

  @Override
  public void resume() {
    // TODO Auto-generated method stub
    
  }

  @Override
  public void dispose() {
    // TODO Auto-generated method stub
    
  }


}




Java Source Code List

actors.Square.java
com.denzyldick.square.Assets.java
com.denzyldick.square.BackgroundAnimation.java
com.denzyldick.square.File.java
com.denzyldick.square.Font.java
com.denzyldick.square.Main.java
com.denzyldick.square.SoundManager.java
com.denzyldick.square.SquareMain.java
com.denzyldick.square.StarManagement.java
com.denzyldick.square.client.GwtLauncher.java
com.denzyldick.square.json.JsonArray.java
com.denzyldick.square.json.JsonLiteral.java
com.denzyldick.square.json.JsonNumber.java
com.denzyldick.square.json.JsonObject.java
com.denzyldick.square.json.JsonParser.java
com.denzyldick.square.json.JsonString.java
com.denzyldick.square.json.JsonValue.java
com.denzyldick.square.json.JsonWriter.java
com.denzyldick.square.json.ParseException.java
com.realcode.square.MainActivity.java
screens.GameMenu.java
screens.GameScreen.java
screens.LostScreen.java
screens.MenuScreen.java
screens.OptionsScreen.java
screens.SplashScreen.java
screens.TutorialScreen.java
screens.WonScreen.java