package menus; import com.badlogic.gdx.Gdx; import com.badlogic.gdx.Input; import com.badlogic.gdx.graphics.Texture; import com.badlogic.gdx.graphics.g2d.SpriteBatch; import utilidades.Bot; import utilidades.Personaje; public class Battle extends Menu{ Personaje p1; Bot p2; Texture suelo; float contador; boolean cambio; boolean finalRound; public Battle(String np1, String np2) { this.finalRound=false; this.cambio=true; this.p2=new Bot(np2, true); this.p1=new Personaje(np1, false); this.p1.setEnemigo(p2.getCaja()); this.p2.setEnemigo(p1.getCaja()); switch(((MenuOpcions)Menu.menus.get(Menu.OPCIONES)).getFondo()) { case 0: suelo = new Texture("suelos/sueloChina.png"); break; case 1: suelo = new Texture("suelos/sueloChinaCiudad.png"); break; case 2: suelo = new Texture("suelos/sueloItalia.png"); break; } } @Override public int draw(SpriteBatch batch, float delta) { batch.draw(suelo,0,0); if (Gdx.input.isKeyPressed(Input.Keys.E)) { p1.cambiarEstado(p1.MEDIO); }else if(Gdx.input.isKeyPressed(Input.Keys.W)){ p1.cambiarEstado(p1.ALTO); }else if(Gdx.input.isKeyPressed(Input.Keys.S)){ p1.cambiarEstado(p1.BAJO); }else{ p1.cambiarEstado(p1.STAND); } contador+=delta; if(contador>0.5) { if(cambio) { p2.cambiarEstado((int)Math.round(Math.random()*2)); cambio=false; } if(finalRound) { if(contador>2) { contador=0; cambio=true; } }else { if(contador>1) { contador=0; cambio=true; } } }else { p2.cambiarEstado(p2.STAND); } p1.mover(); p2.mover(); p2.recivir(p1.atacar(delta)); if(finalRound) { p1.recivir(p2.atacar(delta).ataqueFinal()); }else { p1.recivir(p2.atacar(delta)); } this.p1.draw(batch, delta); this.p2.draw(batch, delta); if(p1.muerto()) { font.draw(batch, "Has perdido", Gdx.graphics.getWidth()/4,Gdx.graphics.getHeight()/2.6f); }else if(p2.muerto()){ font.draw(batch, "Has ganado", Gdx.graphics.getWidth()/4,Gdx.graphics.getHeight()/2.6f); } return darSeleccionado(); } @Override int darSeleccionado() { if(p1.muerto()) { Menu.menus.remove(Menu.BATTLE); return Menu.FINAL; }else if(p2.muerto()) { if(finalRound) { Menu.menus.remove(Menu.BATTLE); return Menu.FINAL; }else { this.p1=new Personaje(p1.toString(), false); this.p2=new Bot(p2.toString(),true); this.p1.setEnemigo(p2.getCaja()); this.p2.setEnemigo(p1.getCaja()); finalRound=true; suelo = new Texture("suelos/sueloBuda.png"); } } return Menu.BATTLE; } public void dispose() { super.dispose(); p1.dispose(); p2.dispose(); } }