Пример #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;
    }
  }
Пример #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);
    }
  }
Пример #3
0
  public void init(GameContainer container) throws SlickException {
    if (container instanceof AppGameContainer) {
      app = (AppGameContainer) container;
    }

    over = false;

    input = container.getInput();

    Vec2 gravity = new Vec2(0.0f, 0.0f);
    world = new World(gravity, true);

    player1 = new ShipBuild(player1Ship, world, tr);
    player2 = new ShipCPU(player2Ship, world, tr, level); // thats the time in ms for shooting

    float jX = tr.width / tr.xscale;
    float jY = tr.height / tr.yscale;

    float max = jY / 2 - 15;
    float min = -jY / 2 + 15;

    asteroids = new AsteroidSpawner(world, tr);
    asteroids.genAsteroids(jX / 2 - 40, max - 25);

    float p1Y = (float) (Math.random() * (max - min) + min);
    float p2Y = (float) (Math.random() * (max - min) + min);
    player1.player.setTransform(new Vec2(-jX / 2 + 15, p1Y), 3 * (float) Math.PI / 2);
    player2.player.setTransform(new Vec2(jX / 2 - 15, p2Y), (float) Math.PI / 2);

    player1.inputForward = Input.KEY_W; // E;
    player1.inputLeft = Input.KEY_A; // W;
    player1.inputRight = Input.KEY_D; // R;
    player1.inputShoot = Input.KEY_SPACE; // A;
    player1.inputBackward = Input.KEY_S;

    cDetect = new CollideTest(player1, player2, world);

    world.setContactListener(cDetect);
  }