reorganizado, creado menu

This commit is contained in:
Guillermo Roche 2020-02-18 19:39:32 +01:00
parent 9cd353b2af
commit f72eede716
10 changed files with 210 additions and 12 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -8,14 +8,21 @@ import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.graphics.g2d.SpriteBatch; import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.g2d.TextureRegion; import com.badlogic.gdx.graphics.g2d.TextureRegion;
import menus.Menu;
import menus.MenuInicio;
import menus.MenuOpcions;
import utilidades.Gifs;
public class MyGdxGame extends ApplicationAdapter { public class MyGdxGame extends ApplicationAdapter {
SpriteBatch batch; SpriteBatch batch;
Texture img; Texture img;
BitmapFont font; BitmapFont font;
int WIN_ALT; int WIN_ALT;
int WIN_ANCH; int WIN_ANCH;
private TextureRegion[] regions = new TextureRegion[14]; // #2 private TextureRegion[] regions = new TextureRegion[14];
float contadorGif = 0; float contadorGif = 0;
Gifs pinchos;
int menuSeleccionado=0;
@Override @Override
public void create () { public void create () {
batch = new SpriteBatch(); batch = new SpriteBatch();
@ -24,14 +31,9 @@ public class MyGdxGame extends ApplicationAdapter {
WIN_ALT=900; WIN_ALT=900;
WIN_ANCH=700; WIN_ANCH=700;
Gdx.graphics.setWindowedMode(WIN_ALT, WIN_ANCH); Gdx.graphics.setWindowedMode(WIN_ALT, WIN_ANCH);
for(int i = 0; i<14; i++) { pinchos = new Gifs(img, 14, 39, 49, 15, 40, 40);
regions[i] = new TextureRegion(img, 39+i*49, 15, 40, 40); Menu.menus.add(new MenuInicio());
} Menu.menus.add(new MenuOpcions());
//regions[0] = new TextureRegion(img, 40, 15, 40, 40); // #3
//regions[1] = new TextureRegion(img, 88, 15, 40, 40); // #4
//regions[2] = new TextureRegion(img, 88+48, 15, 40, 40); // #5
//regions[3] = new TextureRegion(img, 0.5f, 0.5f, 1f, 1f); // #6
} }
@Override @Override
@ -40,13 +42,19 @@ public class MyGdxGame extends ApplicationAdapter {
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
batch.begin(); batch.begin();
//batch.draw(img, 0, 0); //batch.draw(img, 0, 0);
contadorGif+=Gdx.graphics.getDeltaTime()*10; //contadorGif+=Gdx.graphics.getDeltaTime()*10;
if(contadorGif>13) { float delta = Gdx.graphics.getDeltaTime();
/*if(contadorGif>13) {
contadorGif=0; contadorGif=0;
} }
batch.draw(regions[(int)contadorGif], 75 * (0 + 1), 100); batch.draw(regions[(int)contadorGif], 75 * (0 + 1), 100);*/
/*pinchos.avanzar(10, delta);
pinchos.draw(batch, Gdx.graphics.getWidth()/5, Gdx.graphics.getHeight()/2.2f);
font.draw(batch, "iniciar", Gdx.graphics.getWidth()/3.75f,Gdx.graphics.getHeight()/2); font.draw(batch, "iniciar", Gdx.graphics.getWidth()/3.75f,Gdx.graphics.getHeight()/2);
pinchos.draw(batch, Gdx.graphics.getWidth()/5+200, Gdx.graphics.getHeight()/2.2f);
font.draw(batch, "configuracion", Gdx.graphics.getWidth()/5,Gdx.graphics.getHeight()/4); font.draw(batch, "configuracion", Gdx.graphics.getWidth()/5,Gdx.graphics.getHeight()/4);
*/
this.menuSeleccionado=Menu.menus.get(this.menuSeleccionado).draw(batch, delta);
batch.end(); batch.end();
} }

65
core/src/menus/Menu.java Normal file
View File

@ -0,0 +1,65 @@
package menus;
import java.util.ArrayList;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Input;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import utilidades.Gifs;
public abstract class Menu {
String[] opciones;
int resolucion;
int position;
int n_opciones;
boolean pres;
static final int MIN=0;
static final int HD=1;
static final int FHD=2;
static final int INICIAL=0;
static final int OPCIONES=1;
int local;
static int resolution;
BitmapFont font;
static Gifs selector;
public static ArrayList<Menu> menus=new ArrayList<Menu>();
public Menu() {
this.position=0;
this.pres=true;
font = new BitmapFont(Gdx.files.internal("CentieSans.fnt"));
selector = new Gifs("125760.png", 14, 39, 49, 15, 40, 40);
}
abstract public int draw(SpriteBatch batch, float delta);
void dispose() {
font.dispose();
}
int cambiarSeleccionado() {
if (Gdx.input.isKeyPressed(Input.Keys.DOWN)) {
if(!this.pres) {
this.position++;
this.pres=true;
}
}else if (Gdx.input.isKeyPressed(Input.Keys.UP)) {
if(!this.pres) {
this.position--;
this.pres=true;
}
}else if (Gdx.input.isKeyPressed(Input.Keys.ENTER)){
if(!this.pres) {
return darSeleccionado();
}
}else if(this.pres) {
this.pres=false;
}
this.position%=this.n_opciones;
if(this.position<0)this.position=this.n_opciones-1;
return this.local;
}
abstract int darSeleccionado();
}

View File

@ -0,0 +1,39 @@
package menus;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
public class MenuInicio extends Menu{
public MenuInicio() {
super();
this.n_opciones=2;
this.local=Menu.INICIAL;
}
@Override
public int draw(SpriteBatch batch, float delta) {
Menu.selector.avanzar(10, delta);
switch(this.position) {
case 0:{
Menu.selector.draw(batch, Gdx.graphics.getWidth()/5, Gdx.graphics.getHeight()/2.2f);
Menu.selector.draw(batch, Gdx.graphics.getWidth()/5+200, Gdx.graphics.getHeight()/2.2f);
break;
}
case 1:{
Menu.selector.draw(batch, Gdx.graphics.getWidth()/5, Gdx.graphics.getHeight()/5f);
Menu.selector.draw(batch, Gdx.graphics.getWidth()/5+400, Gdx.graphics.getHeight()/5f);
}
}
font.draw(batch, "iniciar", Gdx.graphics.getWidth()/3.75f,Gdx.graphics.getHeight()/2);
font.draw(batch, "configuracion", Gdx.graphics.getWidth()/5,Gdx.graphics.getHeight()/4);
return this.cambiarSeleccionado();
}
int darSeleccionado() {
switch(this.position) {
case 0:return 2;
case 1:return Menu.OPCIONES;
default: return -1;
}
}
}

View File

@ -0,0 +1,42 @@
package menus;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
public class MenuOpcions extends Menu{
public MenuOpcions() {
super();
this.n_opciones=2;
this.pres=true;
this.local=Menu.OPCIONES;
}
@Override
public int draw(SpriteBatch batch, float delta) {
Menu.selector.avanzar(10, delta);
switch(this.position) {
case 0:{
Menu.selector.draw(batch, Gdx.graphics.getWidth()/5, Gdx.graphics.getHeight()/2.2f);
Menu.selector.draw(batch, Gdx.graphics.getWidth()/5+200, Gdx.graphics.getHeight()/2.2f);
break;
}
case 1:{
Menu.selector.draw(batch, Gdx.graphics.getWidth()/5, Gdx.graphics.getHeight()/4.2f);
Menu.selector.draw(batch, Gdx.graphics.getWidth()/5+400, Gdx.graphics.getHeight()/4.2f);
}
}
font.draw(batch, "resolucion", Gdx.graphics.getWidth()/3.75f,Gdx.graphics.getHeight()/2);
font.draw(batch, "fondo:", Gdx.graphics.getWidth()/5,Gdx.graphics.getHeight()/4);
return this.cambiarSeleccionado();
}
int darSeleccionado() {
switch(this.position) {
case 0:return 3;
case 1:return Menu.OPCIONES;
default: return -1;
}
}
}

View File

@ -0,0 +1,44 @@
package utilidades;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
public class Gifs {
private Texture textura;
private TextureRegion[] frames;
private int n_estados;
private float contadorEstado;
public Gifs(String ruta, int n_estados, int inicio_image, int desplazamiento,
int anchura, int x, int y) {
textura = new Texture(ruta);
this.n_estados = n_estados;
frames = new TextureRegion[n_estados];
for(int i = 0; i<n_estados; i++) {
frames[i] = new TextureRegion(textura, inicio_image+i*desplazamiento
, anchura, x, y);
}
}
public Gifs(Texture textura, int n_estados, int inicio_image, int desplazamiento,
int anchura, int x, int y) {
this.textura = textura;
this.n_estados = n_estados;
frames = new TextureRegion[n_estados];
for(int i = 0; i<n_estados; i++) {
frames[i] = new TextureRegion(textura, inicio_image+i*desplazamiento
, anchura, x, y);
}
}
public void avanzar(int speed, float delta) {
this.contadorEstado+=delta*speed;
if(this.contadorEstado > this.n_estados) {
this.contadorEstado=0;
}
}
public void draw(SpriteBatch batch, float x, float y) {
batch.draw(this.frames[(int)contadorEstado], x, y);
}
}