Android Open Source - BlockHopper High Scores






From Project

Back to project page BlockHopper.

License

The source code is released under:

Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION...

If you think the Android project BlockHopper 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.example.blockhopper;
//w w w .j av a2  s  .  c o  m
import org.andengine.engine.Engine;
import org.andengine.engine.camera.Camera;
import org.andengine.entity.scene.Scene;
import org.andengine.entity.scene.background.Background;
import org.andengine.entity.sprite.Sprite;
import org.andengine.entity.text.Text;
import org.andengine.entity.text.TextOptions;
import org.andengine.input.touch.TouchEvent;
import org.andengine.opengl.font.Font;
import org.andengine.opengl.font.FontFactory;
import org.andengine.opengl.texture.atlas.bitmap.BitmapTextureAtlas;
import org.andengine.opengl.texture.atlas.bitmap.BitmapTextureAtlasTextureRegionFactory;
import org.andengine.opengl.texture.region.ITextureRegion;
import org.andengine.opengl.vbo.VertexBufferObjectManager;
import org.andengine.ui.activity.BaseGameActivity;
import org.andengine.util.HorizontalAlign;
import org.andengine.util.color.Color;

import android.graphics.Typeface;



public class HighScores extends Scene {
  private Camera camera;
  private BaseGameActivity activity;
  private Engine eng;
  private int deaths;
  private Scene  highSS = new Scene();
  private BitmapTextureAtlas menuTexture;
  private ITextureRegion menuTextureRegion;
  private Font font;
  private Text scoreText,highScoreText;

  
  public HighScores(BaseGameActivity act, Engine eng, Camera cam){
    this.activity = act; //passes this class the game engine, BaseGameactivty, and the camera objects
    this.eng = eng;
    this.camera = cam;
  
  }
  public void loadScene() {
    highSS.setTouchAreaBindingOnActionDownEnabled(true);
    //sets background to harcoded colour
    highSS.setBackground(new Background(new Color(0.6039215686274509803921568627451f,0.8078431372549019607843137254902f,0.5960784313725490196078431372549f)));
    //creates text and fonts
    font = FontFactory.create(eng.getFontManager(), eng.getTextureManager(),128, 64, Typeface.create(Typeface.DEFAULT, Typeface.BOLD), 24);
    font.load();
    
    scoreText = new Text(camera.getWidth()/2 - 64,  camera.getHeight()/2, font, "Deaths: " + deaths, new TextOptions(HorizontalAlign.CENTER), eng.getVertexBufferObjectManager());  
    highScoreText = new Text(camera.getWidth()/2 - 64  ,  20, font, "SCORE", new TextOptions(HorizontalAlign.CENTER), eng.getVertexBufferObjectManager());

    
    BitmapTextureAtlasTextureRegionFactory.setAssetBasePath("gfx/");  
    //creates texture for the home button
    menuTexture  = new BitmapTextureAtlas(this.activity.getTextureManager(),128, 32); //creates the texture for the home button
    menuTextureRegion = BitmapTextureAtlasTextureRegionFactory.createFromAsset(menuTexture, this.activity, "home.png", 0, 0);
    menuTexture.load();


  }
  
  public void createScene(){
    VertexBufferObjectManager vbom = eng.getVertexBufferObjectManager();         
    Sprite homebutton = new Sprite(camera.getCenterX() - 84, camera.getHeight() - 64, menuTextureRegion,vbom){ //creates a button thatt takes the user to the home screen
    
      
            @Override
      
            public boolean onAreaTouched(final TouchEvent pSceneTouchEvent, final float pTouchAreaLocalX, final float pTouchAreaLocalY) {
              MenuScene mscene = new MenuScene(activity,eng,camera); //creates a menu scene obj 
              mscene.loadMenuScene(); //loads the menu scene, creates it and sets the scene to the menu scene
              mscene.createMenuScene();
              eng.setScene(mscene.getScene());
      
               return true;
      
            }
      
         };
  highSS.registerTouchArea(homebutton); //registers the touch area on the sprite
  highSS.attachChild(homebutton); //attaches the button,and text objects
  highSS.attachChild(scoreText);
  highSS.attachChild(highScoreText);

    

    
  }
  public Scene getScene(){    
    return highSS;

  }
  public void setScore(int score){
    this.deaths = score;
    
  }

}




Java Source Code List

com.example.blockhopper.BuildConfig.java
com.example.blockhopper.GameScene.java
com.example.blockhopper.HighScores.java
com.example.blockhopper.Levels.java
com.example.blockhopper.MainActivity.java
com.example.blockhopper.MenuScene.java
com.example.blockhopper.SplashScene.java