diff --git a/core/bin/main/com/mygdx/game/MyGdxGame.class b/core/bin/main/com/mygdx/game/MyGdxGame.class index c8a8341..55ae773 100644 Binary files a/core/bin/main/com/mygdx/game/MyGdxGame.class and b/core/bin/main/com/mygdx/game/MyGdxGame.class differ diff --git a/core/bin/main/menus/Menu.class b/core/bin/main/menus/Menu.class new file mode 100644 index 0000000..2cb7990 Binary files /dev/null and b/core/bin/main/menus/Menu.class differ diff --git a/core/bin/main/menus/MenuInicio.class b/core/bin/main/menus/MenuInicio.class new file mode 100644 index 0000000..73584e4 Binary files /dev/null and b/core/bin/main/menus/MenuInicio.class differ diff --git a/core/bin/main/menus/MenuOpcions.class b/core/bin/main/menus/MenuOpcions.class new file mode 100644 index 0000000..cde282f Binary files /dev/null and b/core/bin/main/menus/MenuOpcions.class differ diff --git a/core/bin/main/utilidades/Gifs.class b/core/bin/main/utilidades/Gifs.class new file mode 100644 index 0000000..6ed5461 Binary files /dev/null and b/core/bin/main/utilidades/Gifs.class differ diff --git a/core/src/com/mygdx/game/MyGdxGame.java b/core/src/com/mygdx/game/MyGdxGame.java index b1ab7f3..0c26f5c 100644 --- a/core/src/com/mygdx/game/MyGdxGame.java +++ b/core/src/com/mygdx/game/MyGdxGame.java @@ -8,14 +8,21 @@ import com.badlogic.gdx.graphics.g2d.BitmapFont; import com.badlogic.gdx.graphics.g2d.SpriteBatch; import com.badlogic.gdx.graphics.g2d.TextureRegion; +import menus.Menu; +import menus.MenuInicio; +import menus.MenuOpcions; +import utilidades.Gifs; + public class MyGdxGame extends ApplicationAdapter { SpriteBatch batch; Texture img; BitmapFont font; int WIN_ALT; int WIN_ANCH; - private TextureRegion[] regions = new TextureRegion[14]; // #2 + private TextureRegion[] regions = new TextureRegion[14]; float contadorGif = 0; + Gifs pinchos; + int menuSeleccionado=0; @Override public void create () { batch = new SpriteBatch(); @@ -24,14 +31,9 @@ public class MyGdxGame extends ApplicationAdapter { WIN_ALT=900; WIN_ANCH=700; Gdx.graphics.setWindowedMode(WIN_ALT, WIN_ANCH); - for(int i = 0; i<14; i++) { - regions[i] = new TextureRegion(img, 39+i*49, 15, 40, 40); - } - //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 - + pinchos = new Gifs(img, 14, 39, 49, 15, 40, 40); + Menu.menus.add(new MenuInicio()); + Menu.menus.add(new MenuOpcions()); } @Override @@ -40,13 +42,19 @@ public class MyGdxGame extends ApplicationAdapter { Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); batch.begin(); //batch.draw(img, 0, 0); - contadorGif+=Gdx.graphics.getDeltaTime()*10; - if(contadorGif>13) { + //contadorGif+=Gdx.graphics.getDeltaTime()*10; + float delta = Gdx.graphics.getDeltaTime(); + /*if(contadorGif>13) { 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); + 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); + */ + this.menuSeleccionado=Menu.menus.get(this.menuSeleccionado).draw(batch, delta); batch.end(); } diff --git a/core/src/menus/Menu.java b/core/src/menus/Menu.java new file mode 100644 index 0000000..1f197bd --- /dev/null +++ b/core/src/menus/Menu.java @@ -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 menus=new ArrayList(); + 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(); +} diff --git a/core/src/menus/MenuInicio.java b/core/src/menus/MenuInicio.java new file mode 100644 index 0000000..e7493c5 --- /dev/null +++ b/core/src/menus/MenuInicio.java @@ -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; + } + } + +} diff --git a/core/src/menus/MenuOpcions.java b/core/src/menus/MenuOpcions.java new file mode 100644 index 0000000..2ae53e9 --- /dev/null +++ b/core/src/menus/MenuOpcions.java @@ -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; + } + } + +} diff --git a/core/src/utilidades/Gifs.java b/core/src/utilidades/Gifs.java new file mode 100644 index 0000000..4d343ab --- /dev/null +++ b/core/src/utilidades/Gifs.java @@ -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 this.n_estados) { + this.contadorEstado=0; + } + } + public void draw(SpriteBatch batch, float x, float y) { + batch.draw(this.frames[(int)contadorEstado], x, y); + } + +}