-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
javosuher
committed
Aug 7, 2014
1 parent
95ffe87
commit efc2934
Showing
16 changed files
with
177 additions
and
12 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package com.mygdx.Pong; | ||
|
||
import com.badlogic.gdx.Gdx; | ||
import com.badlogic.gdx.graphics.Texture; | ||
import com.badlogic.gdx.graphics.g2d.SpriteBatch; | ||
import com.badlogic.gdx.math.Rectangle; | ||
|
||
|
||
public abstract class Button { // Clase abstracta que representa un botón cuyo comportamiento sera diferente dependiendo de los distintos tipos de botones que se tengan | ||
protected Texture texture; // Textura del botón. Se asigna en el hijo | ||
protected Rectangle bordes; // El rectangulo que establece la posición, altura y anchura del botón | ||
|
||
protected float xMinima; // Estos atributos sirven para poner las coordenadas para pulsar el botón. | ||
protected float yMinima; | ||
protected float xMaxima; | ||
protected float yMaxima; | ||
|
||
public Button(int x, int y) { | ||
Texture textura = new Texture(Gdx.files.internal("BotonExit.png")); // Para poner el ancho y alto de los botones. Suponemos que todos serán igual | ||
bordes = new Rectangle(x, y, textura.getWidth(), textura.getHeight()); | ||
|
||
// Permite asignar los bordes del botón para su correcto funcionamiento. | ||
xMinima = bordes.x; | ||
yMaxima = Gdx.graphics.getHeight() - bordes.y; | ||
xMaxima = bordes.x + bordes.width; | ||
yMinima = Gdx.graphics.getHeight() - (bordes.y + bordes.height); | ||
} | ||
|
||
public void draw(SpriteBatch batch) { | ||
batch.draw(texture, bordes.x, bordes.y, bordes.width, bordes.height); | ||
} | ||
|
||
public void update() { | ||
if(sePulsaElBoton()) | ||
funcionamiento(); | ||
} | ||
private boolean sePulsaElBoton() { // Esta función privada sirve para comprobar si se pulsa el botón. | ||
return Gdx.input.isTouched() && Gdx.input.getX() >= xMinima && Gdx.input.getX() <= xMaxima && // Devuelve true si se pulsa dentro de los límites | ||
Gdx.input.getY() >= yMinima && Gdx.input.getY() <= yMaxima; | ||
} | ||
|
||
protected abstract void funcionamiento(); // Método que implementarán las clases hijas y contendrá el comportamiento deseado | ||
|
||
// Getters and Setters ------------------------------------------------------------------------ | ||
|
||
public Rectangle getBordes() { | ||
return bordes; | ||
} | ||
|
||
public void setBordes(Rectangle bordes) { | ||
this.bordes = bordes; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package com.mygdx.Pong; | ||
|
||
import com.badlogic.gdx.Gdx; | ||
import com.badlogic.gdx.graphics.Texture; | ||
|
||
public class ButtonExit extends Button { // Botón que permitirá salir del juego | ||
|
||
public ButtonExit(int x, int y) { | ||
super(x, y); | ||
texture = new Texture(Gdx.files.internal("BotonExit.png")); // Se asigna textura. Muy importante!! | ||
} | ||
|
||
@Override | ||
protected void funcionamiento() { | ||
Gdx.app.exit(); // Cierra la aplicación | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package com.mygdx.Pong; | ||
|
||
import com.badlogic.gdx.Gdx; | ||
import com.badlogic.gdx.graphics.Texture; | ||
|
||
public class ButtonPlay extends Button { // Botón que permitira iniciar el Pong | ||
|
||
public ButtonPlay(int x, int y) { | ||
super(x, y); | ||
texture = new Texture(Gdx.files.internal("BotonPlay.png")); // Se asigna textura. Muy importante!! | ||
} | ||
|
||
@Override | ||
protected void funcionamiento() { | ||
Screens.juego.setScreen(Screens.GAMESCREEN); // Se asigna la pantalla de juego | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package com.mygdx.Pong; | ||
|
||
import com.badlogic.gdx.Gdx; | ||
import com.badlogic.gdx.graphics.GL20; | ||
import com.badlogic.gdx.graphics.Texture; | ||
import com.badlogic.gdx.graphics.g2d.SpriteBatch; | ||
|
||
public class MainScreen extends AbstractScreen { // Pantalla del menú principal del juego. | ||
public SpriteBatch batch; // "Grupo de Sprites (imagenes)" nos permite dibujar rectagulos como referencias a texturas, es necesario para mostrar todo por pantalla. | ||
private Button exit; | ||
private Button play; | ||
|
||
public MainScreen(Main main) { | ||
super(main); | ||
} | ||
|
||
@Override | ||
public void show() { // Método que se llama cuando se establece esta pantalla como actual | ||
batch = main.getBatch(); | ||
Texture texture = new Texture(Gdx.files.internal("BotonExit.png")); // Cogemos la textura del botón para usar su ancho y alto | ||
int centroY = Gdx.graphics.getHeight() / 2 - texture.getHeight() / 2; // Centro en el eje x de la pantalla centrando el botón | ||
int centroX = Gdx.graphics.getWidth() / 2 - texture.getWidth() / 2; // Centro en el eje y de la pantalla centrando el botón | ||
exit = new ButtonExit(centroX, centroY - 50); | ||
play = new ButtonPlay(centroX, centroY + 50); | ||
} | ||
|
||
@Override | ||
public void render(float delta) { // Método que permite actualizar los valores del juego y dibujar el juego para que lo vea el usuario. | ||
//Gdx es una clase con la que podemos acceder a variables que hacen referencia a todos los subsitemas, como son graficos, audio, ficheros, entrada y aplicaciones | ||
// gl es una variable de tipo GL, nos permite acceder a metodos de GL10, GL11 y GL20 | ||
//En este caso glClearColor es un bucle (game loop) que establecera el fondo de la pantalla negro (0,0,0) con transparencia 1 | ||
Gdx.gl.glClearColor(0, 0, 0, 1); | ||
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); // Despues de la funcion anterior es necesario ejecutar esta, para que se lleve a cabo | ||
|
||
exit.update(); // Comprobamos que se pulsan los botones | ||
play.update(); | ||
|
||
batch.begin(); | ||
exit.draw(batch); // Dibujamos el botón exit | ||
play.draw(batch); // Dibujamos el botón play | ||
batch.end(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package com.mygdx.Pong; | ||
|
||
public final class Screens { // Clase que tiene las distintas pantallas del juego para poder acceder a ellas desde cualquier clase | ||
public static Main juego; // Objeto de la clase principal del juego. Nos sirve para cambiar de una pantalla a otra | ||
public static AbstractScreen GAMESCREEN; // Pantalla de juego | ||
public static AbstractScreen MAINSCREEN; // Pantalla del menú | ||
} |