Ejemplo n.º 1
0
  public void update(GameContainer arg0, int arg1) throws SlickException {
    world.step(timeStep, velocityIterations, positionIterations);

    Fixture fa = cDetect.fa;
    Fixture fb = cDetect.fb;

    if (fa != null && fb != null) {

      player1.checkDeleteFixture(fa, fb);
      player2.checkDeleteFixture(fa, fb);

      asteroids.damageAsteroid(fa);
      asteroids.damageAsteroid(fb);
    }

    player1.batteryLeft = 100f;

    player1.calcForce(input, arg1, player2.player.getPosition());
    player2.calcForceCPU(
        player1.player.getPosition(), asteroids.asteroids, new ArrayList<Vec2>(), arg1);

    player1.checkDeath();
    player2.checkDeath();

    if (player1.dead) {
      over = true;
    }
    if (player2.dead) {
      winner += 1; // In this case, winner will be used to determine score
      world.destroyBody(player2.player);
      player2 = new ShipCPU(player2Ship, world, tr, level);
      float jX = tr.width / tr.xscale;
      float jY = tr.height / tr.yscale;

      float max = jY / 2 - 15;
      float min = -jY / 2 + 15;
      float p2Y = (float) (Math.random() * (max - min) + min);

      player2.player.setTransform(new Vec2(jX / 2 - 15, p2Y), (float) Math.PI / 2);
    }

    if (input.isKeyDown(Input.KEY_ESCAPE)) {
      over = true;
    }
  }
Ejemplo n.º 2
0
  public void render(GameContainer arg0, Graphics arg1) throws SlickException {
    arg1.setBackground(Color.black);

    asteroids.drawAsteroids(arg1);

    if (!player1.dead) {
      player1.drawShip(arg1);
    }
    if (!player2.dead) {
      player2.drawShip(arg1);
    }
  }