public Camera2DScreen(Game game) {
      super(game);
      GLGraphics glGraphics = ((GLGame) game).getGLGraphics();
      gl = glGraphics.getGL();

      camera = new Camera2D(glGraphics, WORLD_WIDTH, WORLD_HEIGHT);
      cannon = new Cannon(0, 0, 1, 1);
      ball = new DynamicGameObject(0, 0, 0.2f, 0.2f);
      targets = new ArrayList<GameObject>(NUM_TARGETS);
      grid = new SpatialHashGrid(WORLD_WIDTH, WORLD_HEIGHT, 2.5f);
      for (int i = 0; i < NUM_TARGETS; i++) {
        GameObject target =
            new GameObject(
                (float) Math.random() * WORLD_WIDTH,
                (float) Math.random() * WORLD_HEIGHT,
                0.5f,
                0.5f);
        grid.insertStaticObject(target);
        targets.add(target);
      }

      cannonVertices = new Vertices(gl, 3, 0, false, false);
      cannonVertices.setVertices(new float[] {-0.5f, -0.5f, 0.5f, 0.0f, -0.5f, 0.5f}, 0, 6);

      ballVertices = new Vertices(gl, 4, 6, false, false);
      ballVertices.setVertices(
          new float[] {-0.1f, -0.1f, 0.1f, -0.1f, 0.1f, 0.1f, -0.1f, 0.1f}, 0, 8);
      ballVertices.setIndices(new short[] {0, 1, 2, 2, 3, 0}, 0, 6);

      targetVertices = new Vertices(gl, 4, 6, false, false);
      targetVertices.setVertices(
          new float[] {-0.25f, -0.25f, 0.25f, -0.25f, 0.25f, 0.25f, -0.25f, 0.25f}, 0, 8);
      targetVertices.setIndices(new short[] {0, 1, 2, 2, 3, 0}, 0, 6);
    }
Beispiel #2
0
    public BobScreen(Game game) {
      super(game);
      glGraphics = ((GLGame) game).getGLGraphics();

      bobTexture = new Texture((GLGame) game, "bobrgb888.png");

      bobModel = new Vertices(glGraphics, 4, 12, false, true);
      bobModel.setVertices(
          new float[] {
            -16, -16, 0, 1, 16, -16, 1, 1, 16, 16, 1, 0, -16, 16, 0, 0,
          },
          0,
          16);
      bobModel.setIndices(new short[] {0, 1, 2, 2, 3, 0}, 0, 6);

      bobs = new Bob[100];
      for (int i = 0; i < 100; i++) {
        bobs[i] = new Bob();
      }

      fpsCounter = new FPSCounter();
    }