Exemplo n.º 1
0
 public void listenInput(GameContainer gc, StateBasedGame sbg, int delta) {
   Input input = gc.getInput();
   if (input.isKeyPressed(Input.KEY_DOWN)) {
     cursor = Math.min(cursor + 1, 2);
   } else if (input.isKeyPressed(Input.KEY_UP)) {
     cursor = Math.max(cursor - 1, 0);
   }
   if (cursor == 0 && input.isKeyDown(Input.KEY_RIGHT)) {
     control.changeVolume(delta * 0.5f);
   } else if (cursor == 0 && input.isKeyDown(Input.KEY_LEFT)) {
     control.changeVolume(-delta * 0.5f);
   }
   if (cursor == 1 && input.isKeyDown(Input.KEY_RIGHT)) {
     control.goFullScreen(true);
   } else if (cursor == 1 && input.isKeyDown(Input.KEY_LEFT)) {
     control.goFullScreen(false);
   }
   if (cursor == 2 && input.isKeyDown(Input.KEY_RIGHT)) {
     control.changeBrightness(+5);
   } else if (cursor == 2 && input.isKeyDown(Input.KEY_LEFT)) {
     control.changeBrightness(-5);
   } else if (input.isKeyDown(Input.KEY_ENTER)) {
     ((GameController) gc).changeState("pause");
     //			sbg.enterState(((Game)sbg).prevState);
     ((GameController) gc).changeState(((Game) sbg).prevState);
   }
 }
Exemplo n.º 2
0
  @Override
  public void update(GameContainer container, int delta) throws SlickException {
    // throw new UnsupportedOperationException("Not supported yet.");
    Input input = container.getInput();

    // rotate quad
    double x1 = jugador1.getPosicion().getX();
    double y1 = jugador1.getPosicion().getY();

    if (Keyboard.isKeyDown(Keyboard.KEY_LEFT)) {
      plane1.rotate(-0.2f * delta);
    }
    if (Keyboard.isKeyDown(Keyboard.KEY_RIGHT)) {
      plane1.rotate(0.2f * delta);
    }

    if (Keyboard.isKeyDown(Keyboard.KEY_DOWN)) {
      float hip = 0.4f * delta;
      float rotation = plane1.getRotation();
      x1 -= hip * Math.sin(Math.toRadians(rotation));
      y1 += hip * Math.cos(Math.toRadians(rotation));
    }
    if (Keyboard.isKeyDown(Keyboard.KEY_UP)) {
      float hip = 0.4f * delta;
      float rotation = plane1.getRotation();
      x1 += hip * Math.sin(Math.toRadians(rotation));
      y1 -= hip * Math.cos(Math.toRadians(rotation));
    }

    // keep quad on the screen
    if (x1 < 10) {
      x1 = 10;
    }
    if (x1 > 790) {
      x1 = 790;
    }
    if (y1 < 10) {
      y1 = 10;
    }
    if (y1 > 590) {
      y1 = 590;
    }

    Vector posicion = jugador1.getPosicion();
    posicion.setX(x1);
    posicion.setY(y1);
    jugador1.setPosicion(posicion);

    // jugador 2
    if (Keyboard.isKeyDown(Keyboard.KEY_W)) lastSteering = 1;
    if (Keyboard.isKeyDown(Keyboard.KEY_A)) lastSteering = 2;
    if (Keyboard.isKeyDown(Keyboard.KEY_F)) lastSteering = 3;
    if (Keyboard.isKeyDown(Keyboard.KEY_S)) lastSteering = 4;
    /*
    switch(lastSteering) {
        case 1: jugador2.update(steeringW.getSteering(), delta);
            break;
        case 2: jugador2.update(steeringA.getSteering(), delta);
            break;
        case 3: jugador2.update(steeringF.getSteering(), delta);
            break;
        case 4: jugador2.update(steeringS.getSteering(), delta);
            break;
        default:
    }*/

    // plane2.rotate((float) jugador2.getOrientacion());

    if (input.isKeyPressed(Input.KEY_F1)) {
      Image target = new Image(container.getWidth(), container.getHeight());
      container.getGraphics().copyArea(target, 0, 0);
      ImageOut.write(target.getFlippedCopy(false, true), "screenshot.png", false);
      target.destroy();
    }
  }