diff --git a/CREDITS b/CREDITS new file mode 100644 index 0000000..6f336e9 --- /dev/null +++ b/CREDITS @@ -0,0 +1,8 @@ +"Long Time Coming" Kevin MacLeod (incompetech.com) +Licensed under Creative Commons: By Attribution 3.0 +http://creativecommons.org/licenses/by/3.0/ + +Long Time Coming by Kevin MacLeod is licensed under CC Attribution 3.0. +Direct Link: http://incompetech.com/music/royalty-free/index.html?isrc=USUAN1100173. +ISRC: USUAN1100173 +© 2006 Kevin MacLeod diff --git a/core/src/es/danirod/jumpdontdie/game/CreditsScreen.java b/core/src/es/danirod/jumpdontdie/game/CreditsScreen.java new file mode 100644 index 0000000..fd642f3 --- /dev/null +++ b/core/src/es/danirod/jumpdontdie/game/CreditsScreen.java @@ -0,0 +1,126 @@ +/* + * This file is part of Jump Don't Die + * Copyright (C) 2015 Dani Rodríguez + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package es.danirod.jumpdontdie.game; + +import com.badlogic.gdx.Gdx; +import com.badlogic.gdx.graphics.GL20; +import com.badlogic.gdx.graphics.Texture; +import com.badlogic.gdx.scenes.scene2d.Actor; +import com.badlogic.gdx.scenes.scene2d.Stage; +import com.badlogic.gdx.scenes.scene2d.ui.Image; +import com.badlogic.gdx.scenes.scene2d.ui.Label; +import com.badlogic.gdx.scenes.scene2d.ui.Skin; +import com.badlogic.gdx.scenes.scene2d.ui.TextButton; +import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener; +import com.badlogic.gdx.utils.viewport.FitViewport; + +/** + * Extra screen to show the credits for the work. + */ +public class CreditsScreen extends BaseScreen { + + /** The stage where all the buttons are added. */ + private Stage stage; + + /** The skin that we use to set the style of the buttons. */ + private Skin skin; + + /** The label with all the information. */ + private Label credits; + + /** The back button you use to jump to the game screen. */ + private TextButton back; + + public CreditsScreen(final MainGame game) { + super(game); + + // Create a new stage, as usual. + stage = new Stage(new FitViewport(640, 360)); + + // Load the skin file. The skin file contains information about the skins. It can be + // passed to any widget in Scene2D UI to set the style. It just works, amazing. + skin = new Skin(Gdx.files.internal("skin/uiskin.json")); + + // For instance, here you see that I create a new button by telling the label of the + // button as well as the skin file. The background image for the button is in the skin + // file. + back = new TextButton("Back", skin); + + credits = new Label("Jump Don't Die v1.0.1\n" + + "Copyright (C) 2015 Dani Rodriguez\n" + + "This game is GNU GPL. Get the code at github.com/danirod/JumpDontDie\n\n" + + + "Music: \"Long Time Coming\" Kevin MacLeod (incompetech.com)\n" + + "Licensed under Creative Commons: By Attribution 3.0", skin); + + // Add capture listeners. Capture listeners have one method, changed, that is executed + // when the button is pressed or when the user interacts somehow with the widget. They are + // cool because they let you execute some code when you press them. + back.addCaptureListener(new ChangeListener() { + @Override + public void changed(ChangeEvent event, Actor actor) { + // Take me to the game screen! + game.setScreen(game.menuScreen); + } + }); + + // Now I position things on screen. Sorry for making this the hardest part of this screen. + // I position things on the screen so that they look centered. This is why I make the + // buttons the same size. + credits.setPosition(20, 340 - credits.getHeight()); + back.setSize(200, 80); + back.setPosition(40, 50); + + // Do not forget to add actors to the stage or we wouldn't see anything. + stage.addActor(back); + stage.addActor(credits); + } + + @Override + public void show() { + // Now this is important. If you want to be able to click the button, you have to make + // the Input system handle input using this Stage. Stages are also InputProcessors. By + // making the Stage the default input processor for this game, it is now possible to + // click on buttons and even to type on input fields. + Gdx.input.setInputProcessor(stage); + } + + @Override + public void hide() { + // When the screen is no more visible, you have to remember to unset the input processor. + // Otherwise, input might act weird, because even if you aren't using this screen, you are + // still using the stage for handling input. + Gdx.input.setInputProcessor(null); + } + + @Override + public void dispose() { + // Dispose assets. + stage.dispose(); + skin.dispose(); + } + + @Override + public void render(float delta) { + Gdx.gl.glClearColor(0.2f, 0.3f, 0.5f, 1f); + Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); + stage.act(); + stage.draw(); + } +} diff --git a/core/src/es/danirod/jumpdontdie/game/MainGame.java b/core/src/es/danirod/jumpdontdie/game/MainGame.java index 337f518..a4f780b 100644 --- a/core/src/es/danirod/jumpdontdie/game/MainGame.java +++ b/core/src/es/danirod/jumpdontdie/game/MainGame.java @@ -39,7 +39,7 @@ public class MainGame extends Game { * just public variables. For instance, you could create an ArrayList or maybe use some * structure such as a map where you can associate a number or a string to a screen. */ - public BaseScreen loadingScreen, menuScreen, gameScreen, gameOverScreen; + public BaseScreen loadingScreen, menuScreen, gameScreen, gameOverScreen, creditsScreen; @Override public void create() { @@ -71,6 +71,7 @@ public void finishLoading() { menuScreen = new MenuScreen(this); gameScreen = new GameScreen(this); gameOverScreen = new GameOverScreen(this); + creditsScreen = new CreditsScreen(this); setScreen(menuScreen); } diff --git a/core/src/es/danirod/jumpdontdie/game/MenuScreen.java b/core/src/es/danirod/jumpdontdie/game/MenuScreen.java index e352340..a6b36e5 100644 --- a/core/src/es/danirod/jumpdontdie/game/MenuScreen.java +++ b/core/src/es/danirod/jumpdontdie/game/MenuScreen.java @@ -47,7 +47,7 @@ public class MenuScreen extends BaseScreen { private Image logo; /** The play button you use to jump to the game screen. */ - private TextButton play; + private TextButton play, credits; public MenuScreen(final MainGame game) { super(game); @@ -63,6 +63,7 @@ public MenuScreen(final MainGame game) { // button as well as the skin file. The background image for the button is in the skin // file. play = new TextButton("Play", skin); + credits = new TextButton("Credits", skin); // Also, create an image. Images are actors that only display some texture. Useful if you // want to display a texture in a Scene2D based screen but you don't want to rewrite code. @@ -79,16 +80,26 @@ public void changed(ChangeEvent event, Actor actor) { } }); + credits.addCaptureListener(new ChangeListener() { + @Override + public void changed(ChangeEvent event, Actor actor) { + game.setScreen(game.creditsScreen); + } + }); + // Now I position things on screen. Sorry for making this the hardest part of this screen. // I position things on the screen so that they look centered. This is why I make the // buttons the same size. logo.setPosition(440 - logo.getWidth() / 2, 320 - logo.getHeight()); - play.setSize(200, 100); - play.setPosition(40, 50); + play.setSize(200, 80); + credits.setSize(200, 80); + play.setPosition(40, 140); + credits.setPosition(40, 40); // Do not forget to add actors to the stage or we wouldn't see anything. stage.addActor(play); stage.addActor(logo); + stage.addActor(credits); } @Override