Esempio n. 1
0
  @Override
  public void accelerate(float ax, float ay) {

    float maxX = maxSpeedX;
    float maxY = maxSpeedY;
    float maxFall = maxFallVelocity;

    if (m_slip) {
      ax = ax / 2f;
      maxX = (maxX * 2f);
    }

    m_dx += ax;
    m_dy += ay;

    if (m_bounce) {
      maxX = 40;
      maxY = 40;
      maxFall = 40;
    }

    if ((m_inSwamp) && (m_dying == false)) {
      maxX = maxX / 6;
      maxFall = 4;
    }

    if (Math.abs(m_dx) > maxX) {
      if (!m_inSwamp) {
        if (m_slip) {
          m_dx = maxX * (m_dx / Math.abs(m_dx));
        } else if (!m_onGround) {
          if (m_slipTicks > 30) {
            if (m_dx > 0) m_dx = m_dx - 0.5f;

            if (m_dx < 0) m_dx = m_dx + 0.5f;
          } else {
            if (m_dx > 0) {
              m_dx = (maxX * 2f);
            } else {
              m_dx = -(maxX * 2f);
            }
          }
        } else {
          if (m_dx > 0) m_dx = m_dx - 0.5f;

          if (m_dx < 0) m_dx = m_dx + 0.5f;
        }
      } else {
        m_dx = maxX * (m_dx / Math.abs(m_dx));
      }
    }

    if (m_climbing) {
      if (Math.abs(m_dy) > maxY) {
        m_dy = maxY * (m_dy / Math.abs(m_dy));
      }
    } else {
      if (m_dy < -maxFall) {
        m_dy = -maxFall;
      }

      if ((m_inSwamp) && (m_dying == false)) {
        if (m_dy > 3f) m_dy = 3f;
      }

      if ((m_inFloat) && (m_dying == false)) {
        if (m_dy < m_floatMaxYDown) {
          // m_dy += 0.25f;
          m_dy = m_floatMaxYDown;
        }
      }
    }
  }
Esempio n. 2
0
  @Override
  public void update(float deltaTime) {

    if (m_pause) return;

    if ((m_energy != 1) && (m_heartbeatSoundId > 0)) {
      this.stopSound("heartbeat");
      m_heartbeatSoundId = -1;
    }

    if (m_levelEnding) {
      if (m_heartbeatSoundId > 0) {
        this.stopSound("heartbeat");
        m_heartbeatSoundId = -1;
      }

      if (m_levelEndingFading == false) {
        this.translate(m_dx, m_dy);
        float deltaX = Math.abs(m_machineX - this.getX());
        float deltaY = Math.abs(m_machineY - this.getY());
        if ((deltaX < 15) && (deltaY < 15)) {
          m_levelEndingFading = true;
          this.runAnimation(m_levelEndingAnimation);
        }
      } else {
        if (m_levelEndingAnimation.isRunning() == false) {
          this.setVisible(false);
          m_alive = false;
        }
      }
    } else if (m_spawning) {
      if (!m_spawnAnimation.isRunning()) {
        m_spawning = false;
      }
    } else if (m_dying == false) {
      if (m_energy == 1) {
        if (m_heartbeatSoundId < 0) {
          m_heartbeatSoundId = this.loopSound("heartbeat", 0.25f);
        }
      }

      float ex = 0;
      if (m_activePlatform != null) {
        ex = m_activePlatform.getDX();
      }

      if (m_pauseMoveTicks > 0) m_pauseMoveTicks--;

      if (m_inTeleport) {
        if (m_teleportState == 0) {
          if (m_teleportOut.isRunning() == false) {
            m_teleportState = 1;
            this.runAnimation(m_teleportAnimation);
            this.playSound("teleport", 0.75f);
          }
        } else if (m_teleportState == 1) {
          if (m_teleportAnimation.isRunning() == false) {
            m_teleportState = 2;
            this.runAnimation(m_teleportIn);
            this.playSound("teleportOut", 0.75f);
          }
        } else if (m_teleportState == 2) {
          if (m_teleportIn.isRunning() == false) {
            m_teleportState = 0;
            m_inTeleport = false;
            m_pauseMoveTicks = 0;
          }
        }
      } else if (m_pauseMoveTicks < 1) {
        this.move();
        this.translate(m_dx + ex, m_dy);
        if ((m_dx != 0) || (m_dy != 0)) {
          lastMoveX = m_dx;
          lastMoveY = m_dy;
        }
      }
    } else if (m_dying == true) {
      if (m_deadState == 1) {

        if (m_deathAnimation.isRunning() == false) {
          pLight.setActive(false);
          m_deadState = 2;
          if (m_explodeDeath) {
            m_climbing = false;
            m_explodeDeath = false;
            m_deadState = 3;
            m_deadTicks = 0;
            m_dx = 0;
            m_dy = 0;
          } else {
            m_climbing = false;
            m_dy = 0;
            this.accelerate(0, 26f);
            maxFallVelocity = 128.0f;
            m_deadTicks = 0;
            m_dx = 0;
            this.playSound("falling", 0.9f);
          }
        }
      } else if (m_deadState == 2) {
        m_deadTicks++;
        this.accelerate(0, -(m_gravity * 1.5f));
        this.translate(m_dx, m_dy);
        if (m_deadTicks > 90) {
          m_alive = false;
          m_deadState = 1;
          m_dying = false;
          m_explodeDeath = false;
        }
      } else if (m_deadState == 3) {
        m_deadTicks++;
        if (m_deadTicks > 130) {
          m_alive = false;
          m_deadState = 1;
          m_dying = false;
          m_explodeDeath = false;
        }
      }
    }
  }