예제 #1
0
    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);
    }
예제 #2
0
    @Override
    public void present(float deltaTime) {
      gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
      camera.setViewportAndMatrices();

      gl.glColor4f(0, 1, 0, 1);
      targetVertices.bind();
      int len = targets.size();
      for (int i = 0; i < len; i++) {
        GameObject target = targets.get(i);
        gl.glLoadIdentity();
        gl.glTranslatef(target.position.x, target.position.y, 0);
        targetVertices.draw(GL10.GL_TRIANGLES, 0, 6);
      }
      targetVertices.unbind();

      gl.glLoadIdentity();
      gl.glTranslatef(ball.position.x, ball.position.y, 0);
      gl.glColor4f(1, 0, 0, 1);
      ballVertices.bind();
      ballVertices.draw(GL10.GL_TRIANGLES, 0, 6);
      ballVertices.unbind();

      gl.glLoadIdentity();
      gl.glTranslatef(cannon.position.x, cannon.position.y, 0);
      gl.glRotatef(cannon.angle, 0, 0, 1);
      gl.glColor4f(1, 1, 1, 1);
      cannonVertices.bind();
      cannonVertices.draw(GL10.GL_TRIANGLES, 0, 3);
      cannonVertices.unbind();
    }
예제 #3
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();
    }
예제 #4
0
    @Override
    public void present(float deltaTime) {
      GL10 gl = glGraphics.getGL();
      gl.glClearColor(1, 0, 0, 1);
      gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
      gl.glMatrixMode(GL10.GL_PROJECTION);
      gl.glLoadIdentity();
      gl.glOrthof(0, 320, 0, 480, 1, -1);

      gl.glEnable(GL10.GL_TEXTURE_2D);
      bobTexture.bind();

      gl.glMatrixMode(GL10.GL_MODELVIEW);
      for (int i = 0; i < NUM_BOBS; i++) {
        gl.glLoadIdentity();
        gl.glTranslatef(bobs[i].x, bobs[i].y, 0);
        gl.glRotatef(45, 0, 0, 1);
        gl.glScalef(2, 0.5f, 0);
        bobModel.draw(GL10.GL_TRIANGLES, 0, 6);
      }

      fpsCounter.logFrame();
    }