Java tutorial
package com.mygdx.game; import com.badlogic.gdx.Application; import com.badlogic.gdx.Audio; import com.badlogic.gdx.Game; import com.badlogic.gdx.Gdx; import com.badlogic.gdx.audio.Music; import com.badlogic.gdx.graphics.Color; import com.badlogic.gdx.graphics.OrthographicCamera; import com.badlogic.gdx.graphics.Texture; import com.badlogic.gdx.graphics.g2d.BitmapFont; import com.badlogic.gdx.graphics.g2d.SpriteBatch; import com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator; import com.badlogic.gdx.utils.Array; import javax.xml.soap.Text; import de.tomgrill.gdxfacebook.core.GDXFacebook; import de.tomgrill.gdxfacebook.core.GDXFacebookCallback; import de.tomgrill.gdxfacebook.core.GDXFacebookError; import de.tomgrill.gdxfacebook.core.GDXFacebookConfig; import de.tomgrill.gdxfacebook.core.GDXFacebookSystem; import de.tomgrill.gdxfacebook.core.SignInMode; import de.tomgrill.gdxfacebook.core.SignInResult; /** * Created by David on 12/4/2015. */ public class BoxBox extends com.badlogic.gdx.Game { public int Score; public SpriteBatch batch; public BitmapFont font; public BitmapFont font50; OrthographicCamera camera; public Texture BoxHappy; public Texture BoxSad; public Texture BoxSurprised; public Texture TimerContainer; public Texture TimerFill; public Texture BoomBoom; public Texture pipeImage; public Texture PlayButton; public Texture SettingButton; public Texture DefaultsButton; public Texture ReturnButton; public Texture SkinsButton; public Texture MusicButton; public Texture PipeButton; public Texture TutButton; public Texture CreditsButton; public MySettings settings; FreeTypeFontGenerator generator; FreeTypeFontGenerator.FreeTypeFontParameter parameter; FreeTypeFontGenerator.FreeTypeFontParameter parameter50; Music HappyMusic; public boolean pass; //Change to true once you pass loading. /* Facebook?!?!?!?!?! */ GDXFacebook facebook; GDXFacebookConfig config = new GDXFacebookConfig(); public void create() { /* Gdx.app.setLogLevel(Application.LOG_DEBUG); //For Debug - wanna see some log outputs from FB //FACEbOOK!?!? STUFF THAT SHOULD PROBABLY BE SAVED IN SETTINGS CLASS config.APP_ID = "114170742286583"; config.PREF_FILENAME = ".facebookSessionData"; config.GRAPH_API_VERSION = "v2.5"; //?!?!? facebook = GDXFacebookSystem.install(config); //?!?!?!? //Gaining access tokens that authorize us to do stuff on user's behalf -- Basic Permissions Array<String> permissions = new Array<String>(); permissions.add("email"); permissions.add("public_profile"); permissions.add("user_friends"); //Will probably just throw the sign in fcn onto the GameScreen page to be triggered by a facebook button. As it is right now it's kinda obnoxious. facebook.signIn(SignInMode.READ, permissions, new GDXFacebookCallback<SignInResult> (){ @Override public void onSuccess(SignInResult result) { // Login successful } @Override public void onError(GDXFacebookError error) { // Error handling } @Override public void onCancel() { // When the user cancels the login process } @Override public void onFail(Throwable t) { // When the login fails } }); */ //zomg FB settings = new MySettings(); //Load Settings batch = new SpriteBatch(); if (settings.getSkinStatus() == 1) { BoxHappy = new Texture(Gdx.files.internal("BBAO.png")); //Load all of Orange BoxSad = new Texture(Gdx.files.internal("BBBO.png")); BoxSurprised = new Texture(Gdx.files.internal("BBCO.png")); } else if (settings.getSkinStatus() == 2) { BoxHappy = new Texture(Gdx.files.internal("BBAP.png")); //Load all of Pink BoxSad = new Texture(Gdx.files.internal("BBBP.png")); BoxSurprised = new Texture(Gdx.files.internal("BBCP.png")); } else if (settings.getSkinStatus() == 3) { BoxHappy = new Texture(Gdx.files.internal("BBAG.png")); //Load all of Green BoxSad = new Texture(Gdx.files.internal("BBBG.png")); BoxSurprised = new Texture(Gdx.files.internal("BBCG.png")); } else if (settings.getSkinStatus() == 4) { BoxHappy = new Texture(Gdx.files.internal("BBAB.png")); //Load all of Blue BoxSad = new Texture(Gdx.files.internal("BBBB.png")); BoxSurprised = new Texture(Gdx.files.internal("BBCB.png")); } else if (settings.getSkinStatus() == 5) { BoxHappy = new Texture(Gdx.files.internal("BBAR.png")); //Load all of Red BoxSad = new Texture(Gdx.files.internal("BBBR.png")); BoxSurprised = new Texture(Gdx.files.internal("BBCR.png")); } else //in case setting is undefined { BoxHappy = new Texture(Gdx.files.internal("BBAO.png")); //Load all of Orange BoxSad = new Texture(Gdx.files.internal("BBBO.png")); BoxSurprised = new Texture(Gdx.files.internal("BBCO.png")); } if (settings.getPipeStatus() == 1) //Load the pipe based on settings~~~~~~~~~ pipeImage = new Texture("Just the Pipe.png"); else if (settings.getPipeStatus() == 2) pipeImage = new Texture("PipeG.png"); else if (settings.getPipeStatus() == 3) pipeImage = new Texture("PipeR.png"); else if (settings.getPipeStatus() == 4) pipeImage = new Texture("PipeOP.png"); else { pipeImage = new Texture("Just the Pipe.png"); //In case the setting is undefined } TimerContainer = new Texture(Gdx.files.internal("Base Bar.png")); TimerFill = new Texture(Gdx.files.internal("Timer Bar.png")); BoomBoom = new Texture(Gdx.files.internal("BoomBoom.png")); PlayButton = new Texture(Gdx.files.internal("Play.png")); SettingButton = new Texture(Gdx.files.internal("Settings.png")); DefaultsButton = new Texture(Gdx.files.internal("Defaults.png")); ReturnButton = new Texture(Gdx.files.internal("Return.png")); SkinsButton = new Texture(Gdx.files.internal("Skins.png")); MusicButton = new Texture(Gdx.files.internal("Music.png")); PipeButton = new Texture(Gdx.files.internal("Pipe.png")); TutButton = new Texture(Gdx.files.internal("Tutorial.png")); CreditsButton = new Texture(Gdx.files.internal("Credits.png")); generator = new FreeTypeFontGenerator(Gdx.files.internal("Shumi.otf")); ////////////////// LARGE FONT - SCORE ///////////////////////////// parameter = new FreeTypeFontGenerator.FreeTypeFontParameter(); parameter.size = 100; parameter.color = Color.SALMON; parameter.borderColor = Color.BLACK; parameter.borderWidth = 10; font = generator.generateFont(parameter); // font size 100 pixels //////////////////////////////////////////////////////////////////// /////////////////// HALF SIZE FONT - SETTINGS ///////////////////// parameter50 = new FreeTypeFontGenerator.FreeTypeFontParameter(); parameter50.size = 50; parameter50.color = Color.CYAN; parameter50.borderColor = Color.BLACK; parameter50.borderWidth = 5; font50 = generator.generateFont(parameter50); /////////////////////////////////////////////////////////////////// HappyMusic = Gdx.audio.newMusic(Gdx.files.internal("Upbeat Forever.mp3")); pass = false; HappyMusic.setLooping(true); /* Music: "Upbeat Forever" by Kevin MacLeod (incompetech.com) Licensed under Creative Commons: By Attribution 3.0 http://creativecommons.org/licenses/by/3.0/ Font: "Shumi" by Ivan Shumikhin */ Score = 0; camera = new OrthographicCamera(); camera.setToOrtho(false, 1080, 1920); this.setScreen(new LoadingScreen(this)); } public void render() { super.render(); if (settings.getMusicStatus() && pass == true) { HappyMusic.play(); HappyMusic.setVolume(0.8f); } else { HappyMusic.stop(); } } public void dispose() { batch.dispose(); font.dispose(); font50.dispose(); BoxHappy.dispose(); BoxSad.dispose(); BoxSurprised.dispose(); TimerContainer.dispose(); TimerFill.dispose(); BoomBoom.dispose(); PlayButton.dispose(); SettingButton.dispose(); generator.dispose(); // don't forget to dispose to avoid memory leaks! HappyMusic.dispose(); } }