예제 #1
0
 /**
  * Handles collision with walls and opposing players bullets.
  *
  * @param hardBlocks The walls.
  * @param spawnPoint The spawnpoint on which this player will be transfered.
  * @param opponent The opposing player.
  */
 public void checkForCollision(Array<Rectangle> hardBlocks, Vector2 spawnPoint, Player opponent) {
   for (Rectangle rect : hardBlocks) {
     if (bounds.overlaps(rect)) {
       die(spawnPoint);
     }
     // check if bullets collided with walls
     for (int i = 0; i < bullets.size; i++) {
       if (bullets.get(i).getBounds().overlaps(rect)) {
         if (Settings.reversedBullets) {
           bullets.get(i).setMovementReversed(true);
         } else {
           bullets.get(i).dispose();
           bullets.removeIndex(i);
         }
       }
     }
   }
   if (gameMode == GameMode.MULTI_PLAYER) {
     for (Bullet bullet : bullets) {
       if (bullet.getBounds().overlaps(opponent.getBounds())) {
         opponent.die(spawnPoint);
         bullet.dispose();
         bullets.removeValue(bullet, true);
         score++;
       }
     }
   }
 }
예제 #2
0
  @Override
  public void tick(float delta) {
    super.tick(delta);

    body.applyForceToCenter(movement, true);
    if (gasPressed) {
      if (!exhaustSoundPlaying && !isCrashed()) {
        exhaustSound.play();
        exhaustSoundPlaying = true;
      }
      accelerate();
    }
    if (leftPressed) {
      body.applyAngularImpulse(
          isReversedSteering ? MathUtils.radDeg * -MAX_TURN_DEG : MathUtils.radDeg * MAX_TURN_DEG,
          true);
    }
    if (rightPressed) {
      body.applyAngularImpulse(
          isReversedSteering ? MathUtils.radDeg * MAX_TURN_DEG : MathUtils.radDeg * -MAX_TURN_DEG,
          true);
    }
    if (!gasPressed) {
      exhaustSound.stop();
      exhaustSoundPlaying = false;
    }

    if (Gdx.app.getType() == ApplicationType.Android) {
      handleTouchPadInput();
      touchPadStage.act(delta);
    }

    sprite.setPosition(
        getPosition().x - sprite.getWidth() / 2, getPosition().y - sprite.getHeight() / 2);
    sprite.setRotation(body.getAngle() * MathUtils.radiansToDegrees);

    // update exhaust
    exhaust.setPosition(getPosition().x, getPosition().y);
    exhaust.update(delta);
    explosion.update(delta);

    for (Bullet bullet : bullets) {
      bullet.tick(delta);
    }

    if (crashed) {
      timePassed += delta;
      ableToShoot = false;
      playExplosion();
    }
  }
예제 #3
0
  @Override
  public void render(SpriteBatch batch) {
    // draw bullets
    for (Bullet bullet : bullets) {
      bullet.render(batch);
    }
    if (!crashed) {
      exhaust.draw(batch);
      sprite.draw(batch);
    }
    explosion.draw(batch);

    if (Gdx.app.getType() == ApplicationType.Android) {
      touchPadStage.draw();
    }
  }