예제 #1
0
 // updates the sprite image and x y of player if changed
 public void update() {
   if (!isCollide) {
     animation.update();
     x += dx;
     y += dy;
   }
 }
예제 #2
0
  @Override
  public void run() {

    running = true;

    while (running) {

      while (active && animation != null) {
        long time = System.currentTimeMillis();
        active = animation.update(view, time - lastTime);
        view.redraw();
        lastTime = time;

        while (active) {
          try {
            if (view.waitForDraw(32)) { // 30Htz
              break;
            }
          } catch (InterruptedException ignore) {
            active = false;
          }
        }
      }

      synchronized (this) {
        if (running) {
          try {
            wait();
          } catch (InterruptedException ignore) {
          }
        }
      }
    }
  }
예제 #3
0
 /**
  * Handles the keyboard input.
  *
  * @param elapsed time elapsed since the last frame
  */
 private void handleControllerInput(float elapsed) {
   if (controllerActive) {
     if (controller.justPressed(KeyEvent.VK_A)) {
       simpleAttack();
     }
     if (state == DynamicObjectState.Attacking) {
       curAnim.update(elapsed);
       return;
     } else if (controller.justPressed(KeyEvent.VK_S)) spellAttack(0);
     else if (controller.justPressed(KeyEvent.VK_D)) spellAttack(1);
     else if (controller.justPressed(KeyEvent.VK_F)) spellAttack(2);
     else if (controller.justPressed(KeyEvent.VK_5)) spellManager.activateShield(ElementType.Fire);
     else if (controller.justPressed(KeyEvent.VK_6))
       spellManager.activateShield(ElementType.Water);
     else if (controller.justPressed(KeyEvent.VK_7))
       spellManager.activateShield(ElementType.Earth);
     else if (controller.isDownPressed()) move(Heading.Down);
     else if (controller.isUpPressed()) move(Heading.Up);
     else if (controller.isLeftPressed()) move(Heading.Left);
     else if (controller.isRightPressed()) move(Heading.Right);
     else if (controller.justReleased(KeyEvent.VK_LEFT)
         || controller.justReleased(KeyEvent.VK_RIGHT)
         || controller.justReleased(KeyEvent.VK_UP)
         || controller.justReleased(KeyEvent.VK_DOWN)) stopMovement();
     else if (controller.justPressed(KeyEvent.VK_ENTER)) collision.checkOnKeyTriggers(this);
   }
 }
예제 #4
0
 public synchronized void update(long timer) {
   if (loopCount != -1 && loopPlay > loopCount) {
     return;
   }
   if (isRunning) {
     if (currentFrameIndex > -1 && currentFrameIndex < size) {
       Animation animation = playAnimations.get(currentFrameIndex);
       if (animation != null) {
         if (animation.isRunning) {
           animation.update(timer);
         }
       }
     }
   }
 }
예제 #5
0
  public void update() {

    // Make the flies change direction randomly.
    if (y > randomNum3) {
      // Make the flies fly to the cake!
      if (x <= 159 - randomNum2) {
        x += 4;
        rotate -= 1;
        // cap rotation
        if (rotate <= -25) {
          rotate = -25;
        }
      } else {
        // rotate back
        if (rotate < 0) {
          rotate += 5;
        }
      }

      if (x >= 161 + randomNum2) {
        x -= 4;
        rotate += 1;
        // cap rotation
        if (rotate >= 25) {
          rotate = 25;
        }
      } else {
        // rotate back
        if (rotate > 0) {
          rotate -= 5;
        }
      }
    }
    // speed
    int speed = 2;
    y += speed;

    animation.update();
  }
예제 #6
0
  public void animationLoop() {
    long startTime = System.currentTimeMillis();
    long currTime = startTime;

    while (currTime - startTime < DEMO_TIME) {
      long elapsedTime = System.currentTimeMillis() - currTime;
      currTime += elapsedTime;

      // update animation
      anim.update(elapsedTime);

      // draw to screen
      Graphics g = screen.getFullScreenWindow().getGraphics();
      draw(g);
      g.dispose();

      // take a nap
      try {
        Thread.sleep(20);
      } catch (InterruptedException ex) {
      }
    }
  }
예제 #7
0
 /** Updates this Sprite's Animation and its position based on the velocity. */
 public void update(long elapsedTime) {
   x += dx * elapsedTime;
   y += dy * elapsedTime;
   anim.update(elapsedTime);
 }
예제 #8
0
 public void update(long elapsedTime) {
   if (isVisible) {
     animation.update(elapsedTime);
   }
 }
예제 #9
0
  @Override
  public void update(float dt) {
    if (!paused) {
      handleInput();
      if (!readyToFadeWhite) player.update(dt); // So player can be controlled upward from Sky
      else {
        // Lift player
        whiteOverlay += .3f * dt;
        player.getVelocity().add(0, -player.gravity / 2);
        player.getVelocity().scl(dt);
        player.getPosition().add(player.movement * dt, player.getVelocity().y);
        player.getVelocity().scl(1 / dt);
        float temp =
            player.normalize(
                -450, 200, (float) -Math.PI / 4f, (float) Math.PI / 4f, player.getVelocity().y);
        player.rotation = 25 * (float) Math.sin(temp);
        if (whiteOverlay > 1f) {
          dispose();
          Preferences p = Gdx.app.getPreferences(OwlCityTribute.GAME_PREFS);
          p.putInteger("level", 5);
          if (p.getInteger("maxlevel") < 5) {
            p.putInteger("maxlevel", 5);
          }
          p.flush();
          gsm.currentState = GameStateManager.SKY;
          this.gsm.setState(new Sky(this.gsm));
        }
      }
      fallen = player.getPosition().y == -OwlCityTribute.HEIGHT * .1f;

      if (!loss && fallen) {
        loss = true;
        gsm.push(new UponLoss(gsm));
      }

      note.update(dt);
      noteAnim.update(dt);
      noteRotation += 100f * dt;
      if (noteRotation > 360) noteRotation = 0;

      balloonFluctuation.update(dt);

      cam.position.x = player.getPosition().x + player.xOffset;
      float leftEdge = player.getPosition().x - (cam.viewportWidth / 2) + player.xOffset;

      // Check if note is hit
      if (!shrinking
          && Math.sqrt(
                  Math.pow(
                          (player.getPosition().x + player.getPlane().getWidth() * .75f)
                              - note.getPosition().x,
                          2)
                      + Math.pow(
                          (player.getPosition().y + (player.getPlane().getHeight() * .75f) / 2)
                              - (note.getPosition().y + noteAnim.getFrame().getRegionHeight() / 2),
                          2))
              < 40) {
        // Open textbox
        textCount++;
        textBox.prepare(
            sceneText.get(textCount).get(0),
            (sceneText.get(textCount).size() == 1) ? "" : sceneText.get(textCount).get(1),
            .1f);
        boxInitialized = true;

        // Set bounds
        int w = (int) font.getBounds(sceneText.get(textCount).get(0)).width;
        // int h = (int)(font.getBounds(sceneText.get(textCount).get(0)).height*2.5);
        int h =
            (int)
                (font.getBounds(sceneText.get(textCount).get(0)).height
                    * sceneText.get(textCount).size()
                    * 1.5);
        textBox.setBounds(
            w,
            h,
            (int) (OwlCityTribute.WIDTH * .65) - w / 2,
            (int) (OwlCityTribute.HEIGHT * .875) - h / 2);
        waiting = true;
        shrinking = true;
      } else if (note.getPosition().x < leftEdge - noteAnim.getFrame().getRegionWidth()
          && !waiting
          && textCount < sceneText.size() - 1
          && player.movement > player.maxMovement * .75) {
        note.getPosition().x = player.getPosition().x + cam.viewportWidth;
        note.setyOffset((int) (Math.random() * 100) + 200);
      }

      if (shrinking) {
        noteScale -= 2.5 * dt;
        if (noteScale < 0) {
          shrinking = false;
          noteScale = 1f;
          note.getPosition().x -= cam.viewportWidth;
        }
      }

      if (textBox.readyToUpdate) {
        if (!textBox.update(dt)) waiting = true;
        else {
          waiting = false;
          if (textCount < sceneText.size() - 1 && player.movement > player.maxMovement * .75) {
            note.getPosition().x = player.getPosition().x + cam.viewportWidth;
            note.setyOffset((int) (Math.random() * 100) + 200);
          }
        }
      }

      if (!fallen && boxInitialized && textCount == sceneText.size() - 1 && textBox.finished) {
        readyToFadeWhite = true;
      }

      // clouds
      for (int i = 0; i < clouds.size; i++) {
        clouds.get(i).update(dt);
        if (clouds.get(i).getPosition().x < leftEdge - cloud.getWidth()) {
          int index = (i == 0) ? clouds.size - 1 : i - 1;
          clouds.get(i).getPosition().x =
              (float) (clouds.get(index).getPosition().x + cam.viewportWidth * .8);
          clouds.get(i).yOffset =
              random.nextInt((int) (OwlCityTribute.HEIGHT * .1f))
                  + (int) (OwlCityTribute.HEIGHT * .75f);
        }
      }

      //        if(readyToFadeBlack){
      //            whiteValue  = (whiteValue > 0) ? whiteValue - .2f*dt : 0f;
      //            if(whiteValue == 0f){
      //                if(player.getPosition().y == -OwlCityTribute.HEIGHT*.1f){
      //                    dispose();
      //                    this.gsm.setState(new Sky(this.gsm));
      //                }
      //            }
      //        }
      // else{
      whiteValue = (whiteValue < 1f) ? whiteValue + .4f * dt : 1f;
      // }

      // Shimmer update
      for (int i = 0; i < NUM_SHIMMERS; i++) {
        shimmers.get(i).update(dt);
      }

      // Check brush
      for (int i = 0; i < brushmoving.size; i++) {
        brushmoving.get(i).MOVEMENT = -(player.movement / 5);
        brushmoving.get(i).update(dt);
        if (brushmoving.get(i).getPosition().x < leftEdge - brush.getWidth() * 1.5) {
          int index = (i == 0) ? brushmoving.size - 1 : i - 1;
          brushmoving.get(i).getPosition().x =
              brushmoving.get(index).getPosition().x + brush.getWidth();
          break;
        }
      }

      cam.update();
    }
  }
예제 #10
0
파일: Player.java 프로젝트: Ifdano/SKY-boy
  public void update() {

    if (crush) {
      if (animation.getCurrent() == crushSprites.length - 1) {
        crush = false;
      }
    }

    if (crush) {
      if (leftCrush) {
        dx -= (moveSpeed + 0.3);
        if (dx < -(maxSpeed + 2.0)) dx = -(maxSpeed + 2.0);
      } else {
        if (rightCrush) {
          dx += moveSpeed + 0.3;
          if (dx > maxSpeed + 2.0) dx = maxSpeed + 2.0;
        } else {
          if (dx < 0) {
            dx += stopSpeed;
            if (dx > 0) dx = 0;
          }
          if (dx > 0) {
            dx -= stopSpeed;
            if (dx < 0) dx = 0;
          }
        }
      }
    }

    if (!crush && !blockMove && left) {
      dx -= moveSpeed;
      if (dx < -maxSpeed) dx = -maxSpeed;
    } else {
      if (!crush && !blockMove && right) {
        dx += moveSpeed;
        if (dx > maxSpeed) dx = maxSpeed;
      } else {
        if (dx < 0) {
          dx += stopSpeed;
          if (dx > 0) dx = 0;
        }
        if (dx > 0) {
          dx -= stopSpeed;
          if (dx < 0) dx = 0;
        }
      }
    }

    if (jumping) {
      sfx.get("jumping").play();

      falling = true;
      jumping = false;
      dy = startJumping;
      upCrush = false;
    }

    if (falling) {
      if (reverse) {
        if (gravity > 0) {
          gravity *= -1;
          startJumping *= -1;
        }

        dy += gravity;
        if (dy < -maxFallingSpeed) dy = -maxFallingSpeed;

      } else {
        if (gravity < 0) {
          gravity *= -1;
          startJumping *= -1;
        }

        dy += gravity;
        if (dy > maxFallingSpeed) dy = maxFallingSpeed;
      }
    } else {
      dy = 0;
    }

    curRow = mp.getRowMap((int) y);
    curCol = mp.getColMap((int) x);

    toX = x + dx;
    toY = y + dy;

    tempX = x;
    tempY = y;

    calculateCorners(x, toY);
    if (dy < 0) {
      if (reverse) {
        if (bottomLeft || bottomRight) {
          dy = 0;
          falling = false;
          tempY = curRow * mp.getMapSize() + height1 / 2;
        } else {
          tempY += dy;
        }
      } else {
        if (topLeft || topRight) {
          dy = 0;
          tempY = curRow * mp.getMapSize() + height1 / 2;
        } else {
          tempY += dy;
        }
      }
    }
    if (dy > 0) {
      if (reverse) {
        if (topLeft || topRight) {
          dy = 0;
          tempY = (curRow + 1) * mp.getMapSize() - height1 / 2;
        } else {
          tempY += dy;
        }
      } else {
        if (bottomLeft || bottomRight) {
          dy = 0;
          falling = false;
          tempY = (curRow + 1) * mp.getMapSize() - height1 / 2;
        } else {
          tempY += dy;
        }
      }
    }

    calculateCorners(toX, y);
    if (dx < 0) {
      if (topLeft || bottomLeft) {
        dx = 0;
        tempX = curCol * mp.getMapSize() + width1 / 2;
      } else {
        tempX += dx;
      }
    }
    if (dx > 0) {
      if (topRight || bottomRight) {
        dx = 0;
        tempX = (curCol + 1) * mp.getMapSize() - width1 / 2;
      } else {
        tempX += dx;
      }
    }

    if (!falling) {
      if (reverse) {
        calculateCorners(x, y - 1);
      } else {
        calculateCorners(x, y + 1);
      }

      if (!bottomRight && !bottomLeft) falling = true;
    }

    x = tempX;
    y = tempY;

    if (!blockMove) {
      mp.setX((int) (GamePanel.WIDTH / 2 - x));
      mp.setY((int) (GamePanel.HEIGHT / 2 - y));
    }

    if (crush) {
      animation.setFrame(crushSprites);
      animation.setDelay(400);
      animation.setSpeed(10);
    } else {
      if (left || right) {
        animation.setFrame(walkSprites);
        animation.setDelay(100);
        animation.setSpeed(15);
      } else {
        if (telekinesTo || telekinesFrom) {
          animation.setFrame(telekinesSprites);
          animation.setDelay(400);
          animation.setSpeed(8);
        } else {
          animation.setFrame(idSprites);
          animation.setDelay(400);
          animation.setSpeed(5);
        }
      }
    }

    if (dy < 0) {
      if (!reverse) {
        animation.setFrame(jumpSprites);
        animation.setDelay(100);
        animation.setSpeed(10);
      } else {
        animation.setFrame(fallSprites);
        animation.setDelay(100);
        animation.setSpeed(10);
      }
    }
    if (dy > 0) {
      if (reverse) {
        animation.setFrame(jumpSprites);
        animation.setDelay(100);
        animation.setSpeed(10);
      } else {
        animation.setFrame(fallSprites);
        animation.setDelay(100);
        animation.setSpeed(10);
      }
    }

    animation.update();

    if (left) {
      factingRight = false;
    } else {
      if (right) {
        factingRight = true;
      }
    }
  }
예제 #11
0
파일: Sprite.java 프로젝트: ufaith/javaxyq
 public void update(long elapsedTime) {
     // update animation
     currAnimation.update(elapsedTime);
 }
예제 #12
0
  @Override
  public void update(float elapsed) {
    if (!isInNetwork && health.isDead()) {
      terminate();
      return;
    }

    regenerate();
    spellManager.update(elapsed);

    ElementalShield curShield = spellManager.getCurrentShield();
    if (curShield != null && curShield.getElementType() == ElementType.Fire)
      manager.handleAreaOfEffectSpell(
          this, curShield.getDamage(), ElementType.Fire, curShield.getAOErect());

    if (state == DynamicObjectState.Attacking) {
      curAnim.update(elapsed);
      return;
    }

    if (state == DynamicObjectState.Hit) {
      curAnim.update(elapsed);
      curHitDuration -= 1;
      if (curHitDuration <= 0) {
        setState(DynamicObjectState.Idle);
        curHitDuration = maxHitDuration;
        health.setInvul(false);
      }

      return;
    }

    if (controllerActive) handleControllerInput(elapsed);

    // DEBUG PURPOSE
    if (controllerActive) {
      if (controller.isPressed(KeyEvent.VK_SHIFT)) supressEnemyCollision = true;
      else supressEnemyCollision = false;
    }
    // -------------

    if (velocity.x > 0.01f || velocity.x < -0.01f || velocity.y > 0.01f || velocity.y < -0.01f) {
      collisionRect.x += velocity.x;
      collisionRect.y += velocity.y;

      boolean collidingStatic = collision.isCollidingStatic(this);
      boolean collidingDynamic = false;
      if (!supressEnemyCollision) collidingDynamic = collision.isCollidingDynamic(this);

      if (collidingStatic || collidingDynamic) {
        collisionRect.x -= velocity.x;
        collisionRect.y -= velocity.y;
        stopMovement();
      } else {
        collision.checkTriggers(this);
        screenPosition.x += velocity.x;
        screenPosition.y += velocity.y;
        curAnim.update(elapsed);
      }
    }

    if (isInNetwork && controllerActive) {
      sendPositionMessage();
    }
  }
  @Override
  public void update(float deltaTime) {
    Graphics g = game.getGraphics();
    menu.update(14);
    List<TouchEvent> touchEvents = game.getInput().getTouchEvents();

    // WEIRD ANDROID GLITCH: plays halfsec of theme on boot unless I do this:

    if (loaded) {
      Assets.theme.play();
    }
    if (menu.getImage() == Assets.menu1) loaded = true;

    int len = touchEvents.size();
    //		System.out.println(idle);
    //		System.out.println(instr);
    for (int i = 0; i < len; i++) {
      TouchEvent event = touchEvents.get(i);

      if (event.x < game.getLoadWidth() / 2
          && event.y > game.getLoadHeight() * .87
          && instr == 0
          && event.type == TouchEvent.TOUCH_UP
          && loaded) {
        // START GAME
        Assets.click.play(100);
        Assets.theme.stop();
        Assets.coug1 = g.newImage("coug1b.png", ImageFormat.RGB565);
        Assets.coug2 = g.newImage("coug2b.png", ImageFormat.RGB565);
        Assets.coug3 = g.newImage("coug3b.png", ImageFormat.RGB565);
        Assets.coug4 = g.newImage("coug4b.png", ImageFormat.RGB565);
        Assets.coug5 = g.newImage("coug5b.png", ImageFormat.RGB565);
        Assets.mFace = g.newImage("face2PIXX.gif", ImageFormat.RGB565);
        Assets.mFaced = g.newImage("facedeathPIX3.gif", ImageFormat.RGB565);
        Assets.hadronOne = g.newImage("hadron.png", ImageFormat.RGB565);
        game.setScreen(new GameScreen(game));
      }
      if (event.x > game.getLoadWidth() / 2
          && event.y > game.getLoadHeight() * .79
          && event.y < game.getLoadHeight() * .9
          && instr == 0
          && event.type == TouchEvent.TOUCH_UP
          && loaded) {
        Assets.click2.play(100);
        Assets.coug1 = g.newImage("coug1b.png", ImageFormat.RGB565);
        Assets.coug2 = g.newImage("coug2b.png", ImageFormat.RGB565);
        Assets.coug3 = g.newImage("coug3b.png", ImageFormat.RGB565);
        Assets.coug4 = g.newImage("coug4b.png", ImageFormat.RGB565);
        Assets.coug5 = g.newImage("coug5b.png", ImageFormat.RGB565);
        Assets.mFace = g.newImage("face2PIXX.gif", ImageFormat.RGB565);
        Assets.mFaced = g.newImage("facedeathPIX3.gif", ImageFormat.RGB565);
        game.setScreen(new Tutorial(game));
      }

      if (event.x > game.getLoadWidth() * .69
          && event.y < game.getLoadHeight() * .21
          && event.type == TouchEvent.TOUCH_UP
          && instr != 0
          && loaded) {
        Assets.click2.play(100);
        instr++;
      }

      if (event.x > game.getLoadWidth() * .53
          && event.y > game.getLoadHeight() * .91
          && instr == 0
          && event.type == TouchEvent.TOUCH_UP
          && loaded) {
        android.os.Process.killProcess(android.os.Process.myPid());
      }
    }
  }
예제 #14
0
 @Override
 public void update(long gameTime) {
   super.update(gameTime);
   anim.update(gameTime);
 }