Package org.newdawn.slick

Examples of org.newdawn.slick.Input


    public void onSlickInit(GriffonApplication app, GameContainer container) {
        model.load();
    }

    public void onSlickUpdate(GriffonApplication app, GameContainer container, int delta) {
        Input input = container.getInput();
        Image plane = model.getPlane();

        if(input.isKeyDown(Input.KEY_A)) {
            plane.rotate(-0.2f * delta);
        }

        if(input.isKeyDown(Input.KEY_D)) {
            plane.rotate(0.2f * delta);
        }

        if(input.isKeyDown(Input.KEY_W)) {
            float hip = 0.4f * delta;

            float rotation = plane.getRotation();

            double x = model.getX() + (hip * Math.sin(Math.toRadians(rotation)));
            double y = model.getY() - (hip * Math.cos(Math.toRadians(rotation)));
            model.setX((float) x);
            model.setY((float) y);
        }

        float scale = model.getScale();
        if(input.isKeyDown(Input.KEY_Z)) {
            scale += (scale >= 5.0f) ? 0 : 0.1f;
            plane.setCenterOfRotation(plane.getWidth()/2.0f*scale, plane.getHeight()/2.0f*scale);
        }
        if(input.isKeyDown(Input.KEY_O)) {
            scale -= (scale <= 1.0f) ? 0 : 0.1f;
            plane.setCenterOfRotation(plane.getWidth()/2.0f*scale, plane.getHeight()/2.0f*scale);
        }
        model.setScale(scale);
    }
View Full Code Here


        gOver = true;

      }


      Input input = gc.getInput();
      if (!playerC.dead && !playerC.dyin ) {
        if(!playerC.attacking && input.isKeyDown(Input.KEY_1))
        {
          //bulowa
          playerC.weaponWld = 1;
        }
        if(!playerC.attacking && input.isKeyDown(Input.KEY_2) && playerC.spearQ > 0)
        {
          //kopie
          playerC.weaponWld = 2;
        }

        if(input.isKeyDown(Input.KEY_A) && !playerC.attacking)
        {
          //float oldX = playerC.x;
          playerC.x += -0.08f * delta;
          if (!checkCollison(playerC)) {
            playerC.moving = true;
            playerC.faceLeft = true;
          } else
            playerC.x += 0.08f * delta;
        }

        if(input.isKeyDown(Input.KEY_D) && !playerC.attacking)
        {
          //float oldX = playerC.x;
          playerC.x += 0.08f * delta;
          if (!checkCollison(playerC)) {
            playerC.moving = true;
            playerC.faceLeft = false;
          } else
            playerC.x -= 0.08f * delta;

        }

        if(input.isKeyDown(Input.KEY_W) && !playerC.attacking)
        {
          float oldY = playerC.y;
          playerC.y -= 0.08f * delta;
          if (!checkCollison(playerC))
            playerC.moving = true;
          else playerC.y = oldY;
        }
        if(input.isKeyDown(Input.KEY_S) && !playerC.attacking)
        {
          float oldY = playerC.y;
          playerC.y += 0.08f * delta;
          if (!checkCollison(playerC))
            playerC.moving = true;
          else playerC.y = oldY;
        }
        if(input.isKeyPressed(Input.KEY_M))
        {
          if (!muteMusic) {
            muteMusic = true;
            polka.stop();
          }
          else {
            muteMusic = false;
            polka.loop(1, 0.2f);
          }
        }
        //TODO
        if (input.isMousePressed(Input.MOUSE_LEFT_BUTTON)) {
          float mx = ((input.getMouseX()  - scrWi/2)/xScale) + playerC.x  ;
          float my = ((input.getMouseY()  - scrHe/2)/xScale) + playerC.y;
          mouz.setXY(mx, my);
          //System.out.println(" mxy = " + mx + "x" + my + " plxy = " + playerC.x + "x" + playerC.y);
          //DasGame.playSound(15, DasGame.getDRX(playerC.x), DasGame.getDRX(playerC.y));

          if (!playerC.attacking && playerC.weaponWld == 1) {
            playerC.attacking = true;
            playerC.inbatl = true;
            playerC.agro = 0;
          } else if (!playerC.attacking && playerC.weaponWld == 2 && playerC.spearQ > 0) {
            playerC.attacking = true;
            playerC.inbatl = true;
            playerC.agro = 0;
          }
          checkCollison(mouz);



        }
      }

      if (playerC.x < 0) playerC.x = 128*32;
      if (playerC.x > 128*32) playerC.x = 0;
      if (playerC.y < 0) playerC.y = 128*32;
      if (playerC.y > 128*32) playerC.y = 0;
      //Raspredelenie (48*xScale)

      upRen.clear();
      downRen.clear();


      for (Entity obj : World.objecz) {
        float wtdX = (obj.x - playerC.x) * xScale + scrWi/2;
        float wtdY = (obj.y - playerC.y)* xScale + scrHe/2;

        int xm = 64;
        int xmm = 128;
        if (wtdX >= ((128 * 32) - xm)*xScale ) wtdX -= (128 * 32)*xScale ;
        if (wtdX < scrWi + ((xm - (128 * 32))*xScale) ) wtdX =  wtdX + ((128 * 32)*xScale);
        if (wtdY >= ((128 * 32) - xm)*xScale ) wtdY -= (128 * 32)*xScale  ;
        if (wtdY < scrHe+ ((xm - (128 * 32))*xScale)  ) wtdY = wtdY + ((128 * 32)*xScale);

        /*
      if (wtdX >= -xm*xScale && wtdX < scrWi+xm*xScale
          && wtdY >= -xm*xScale && wtdY < scrHe+xm*xScale)
         */
        /*
         * if (obj.y <= playerC.y && obj.y > playerC.y - ((scrHe/1.75)/xScale) && wtdX >= -64*xScale && wtdX < scrWi+64*xScale) upRen.add(obj);
      else if (obj.x > playerC.x - ((scrWi/1.75)/xScale) && obj.x < playerC.x + ((scrWi/1.75)/xScale) && obj.y < playerC.y + ((scrHe/1.75)/xScale)+32) downRen.add(obj);

         */

        if (obj.y <= playerC.y &&  wtdY >= -xm*xScale && wtdX >= -xmm*xScale && wtdX < scrWi+xm*xScale) upRen.add(obj);
        else if (wtdX >= -xmm*xScale && wtdX < scrWi+xm*xScale && wtdY < scrHe+xm*xScale) downRen.add(obj);
      }
     

      for (int i = 0; i < upRen.size(); i++) {

        float min = upRen.get(i).y;
        int imin = i;
        for (int j = i; j < upRen.size(); j++) {

          if (upRen.get(j).y < min) {
            min = upRen.get(j).y;
            imin = j;
          }
        }

        if (i != imin) {
          Entity temp = upRen.get(i);
          upRen.set(i, upRen.get(imin));
          upRen.set(imin, temp);
        }
      }
      for (int i = 0; i < downRen.size(); i++) {

        float min = downRen.get(i).y;
        int imin = i;
        for (int j = i; j < downRen.size(); j++) {

          if (downRen.get(j).y < min) {
            min = downRen.get(j).y;
            imin = j;
          }
        }

        if (i != imin) {
          Entity temp = downRen.get(i);
          downRen.set(i, downRen.get(imin));
          downRen.set(imin, temp);
        }
      }
    }
    else if (!drawvoid && isIntrd1) {
      if (!muteMusic) {
        System.out.println("igsray!");
        polka.fade(2000, 0, true);
        muteMusic = true;
      }
      if (gOver && !gameEnded) {
        Input input = gc.getInput();
        if (input.isKeyDown(input.KEY_R)) restartgame();
      }


      //TODO ���������� ����
   
View Full Code Here

        grphcs.drawString("press SPACE to play again or ESC to exit", posX, posY);
    }

    @Override
    public void update(GameContainer gc, StateBasedGame sbg, int delta) throws SlickException {
        Input in = gc.getInput();
       
        if(in.isKeyPressed(Input.KEY_ESCAPE)) gc.exit();
        if(in.isKeyPressed(Input.KEY_SPACE)) sbg.enterState(BlocksThatFall.GAMEPLAYSTATE);
    }
View Full Code Here

        }
    }

    @Override
    public void update(GameContainer gc, StateBasedGame sbg, int delta) throws SlickException {
        Input in = gc.getInput();
       
        if(in.isKeyDown(Input.KEY_ESCAPE)) gc.exit();
        if(in.isKeyPressed(Input.KEY_P)) paused = !paused;
       
        if(paused) return;
       
        score += pit.eraseFullLines();
       
        if(in.isKeyDown(Input.KEY_DOWN)) DELAY = 50;
        else {DELAY = 300; }
       
        deltaCounter -= delta;
        if(deltaCounter <= 0) {
            boolean collides = pit.pieceCollidesAt(piece, posX, posY+1);
            if(!collides) posY += 1;
            else {
                pit.insertPieceAt(piece, posX, posY);
                piece = nextPiece;
                nextPiece = pieceFactory.generateRandomPiece();
                posX = (pit.width - piece.getMatrix().toArray().length)/2;
                posY= -piece.getBlankLinesAtTop();
               
                if(pit.pieceCollidesAt(piece, posX, posY)) {
                    BlocksThatFall.score = score;
                    sbg.enterState(BlocksThatFall.GAMEOVERSTATE);
                    init(gc, sbg);
                }
               
                deltaCounter = DELAY;
                return;
            }
            deltaCounter = DELAY;
        }
       
        if(in.isKeyPressed(Input.KEY_SPACE)) {
            Piece rotatedPiece = piece.rotated();
            if(!pit.pieceCollidesAt(rotatedPiece, posX, posY)) {
                piece = rotatedPiece;
            }
        }
       
        deltaInput -= delta;
        if(deltaInput <= 0) {
            boolean leftDown = in.isKeyDown(Input.KEY_LEFT);
            boolean rightDown = in.isKeyDown(Input.KEY_RIGHT);
            if(leftDown || rightDown) {
                if(leftDown && !pit.pieceCollidesAt(piece, posX-1, posY)) posX -= 1;
                else if(rightDown && !pit.pieceCollidesAt(piece, posX+1, posY)) posX += 1;
            }
            deltaInput = DELAY/4;
View Full Code Here

        grphcs.drawString("Press SPACE to start game", posX, posY);
    }

    @Override
    public void update(GameContainer gc, StateBasedGame sbg, int delta) throws SlickException {
        Input in = gc.getInput();
       
        if(in.isKeyPressed(Input.KEY_ESCAPE)) gc.exit();
        if(in.isKeyPressed(Input.KEY_SPACE)) sbg.enterState(BlocksThatFall.GAMEPLAYSTATE);
    }
View Full Code Here

 
  public void update(GameContainer container, int delta) {
    super.update(container);
   
    if (!container.isPaused()){
      Input input = container.getInput();
      CollisionManager col = CollisionManager.getInstance();
     
      if (input.isKeyDown(Input.KEY_W) || input.isKeyDown(Input.KEY_S) ||
          input.isKeyDown(Input.KEY_A) ||input.isKeyDown(Input.KEY_D)) {
        SoundManager.getInstance().playOnce("player", "walk", 1f, 2f);
      }
     
      float newPlayerX;
      float newPlayerY;
   
   
      if(input.isKeyDown(Keyboard.KEY_A)) {
        newPlayerX = posX + -delta * WALK_SPEED;
        if (!col.collided(newPlayerX, posY)) { 
          setPosX(newPlayerX);
          setAnimation(ANIM_RUNNING_LEFT);
        }
      }
       
      if(input.isKeyDown(Keyboard.KEY_D)) { 
        newPlayerX = posX + delta * WALK_SPEED;
        if (!col.collided(newPlayerX, posY)) {   
          setPosX(newPlayerX);
          setAnimation(ANIM_RUNNING_RIGHT);
        }
      }
       
      if(input.isKeyDown(Keyboard.KEY_W)){
        newPlayerY = posY + -delta * WALK_SPEED;
        if (!col.collided(posX, newPlayerY)) { 
          setPosY(newPlayerY);
          setAnimation(ANIM_RUNNING_UP);
        }
      }
       
      if(input.isKeyDown(Keyboard.KEY_S)){
        newPlayerY = posY + delta * WALK_SPEED;
        if (!col.collided(posX, newPlayerY)) {
          setPosY(newPlayerY);
          setAnimation(Player.ANIM_RUNNING_DOWN);
        }
View Full Code Here

    mouseDownImage = image;

    currentColor = normalColor;

    state = NORMAL;
    Input input = container.getInput();
    over = area.contains(input.getMouseX(), input.getMouseY());
    mouseDown = input.isMouseButtonDown(0);
    updateImage();
  }
View Full Code Here

TOP

Related Classes of org.newdawn.slick.Input

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.