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);
    }
    @Override
    public void resume() {
      GL10 gl = glGraphics.getGL();
      gl.glViewport(0, 0, glGraphics.getWidth(), glGraphics.getHeight());
      gl.glClearColor(1, 0, 0, 1);
      gl.glMatrixMode(GL10.GL_PROJECTION);
      gl.glLoadIdentity();
      gl.glOrthof(0, 320, 0, 480, 1, -1);

      gl.glMatrixMode(GL10.GL_MODELVIEW);

      bobTexture.reload();
      gl.glEnable(GL10.GL_TEXTURE_2D);
      bobTexture.bind();
    }
Example #3
0
  private void renderForeground() {
    GL10 gl = glGraphics.getGL();
    gl.glEnable(GL10.GL_BLEND);

    gl.glBlendFunc(GL10.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA);
    batcher.beginBatch(Assets.foregroundItems);

    switch (board.state) {
      case Board.GAME_READY:
        break;

      case Board.GAME_RUNNING:
        renderDebugSquares();
        renderScore();
        renderTimer();
        renderLetters();
        renderLetterTray();
        break;

      case Board.GAME_PAUSED:
        renderDebugSquares();
        renderLetters();
        renderLetterTray();
        renderPausedScreen();
        break;

      case Board.GAME_OVER:
        renderFinalScores();
        break;
    }

    batcher.endBatch();
    gl.glDisable(GL10.GL_BLEND);
  }
Example #4
0
  public void unbind() {
    GL10 gl = glGraphics.getGL();

    if (hasTexCoords) gl.glDisableClientState(GL10.GL_TEXTURE_COORD_ARRAY);

    if (hasColor) gl.glDisableClientState(GL10.GL_COLOR_ARRAY);
  }
Example #5
0
  private void load() {
    GL10 gl = glGraphics.getGL();
    int[] textureIds = new int[1];
    gl.glGenTextures(1, textureIds, 0);
    textureId = textureIds[0];

    InputStream in = null;
    try {
      in = fileIO.readAsset(fileName);
      Bitmap bitmap = BitmapFactory.decodeStream(in);
      if (mipmapped) {
        createMipmaps(gl, bitmap);
      } else {
        gl.glBindTexture(GL10.GL_TEXTURE_2D, textureId);
        GLUtils.texImage2D(GL10.GL_TEXTURE_2D, 0, bitmap, 0);
        setFilters(GL10.GL_NEAREST, GL10.GL_NEAREST);
        gl.glBindTexture(GL10.GL_TEXTURE_2D, 0);
        width = bitmap.getWidth();
        height = bitmap.getHeight();
        bitmap.recycle();
      }
    } catch (IOException e) {
      throw new RuntimeException("Couldn't load texture '" + fileName + "'", e);
    } finally {
      if (in != null)
        try {
          in.close();
        } catch (IOException e) {
        }
    }
  }
Example #6
0
 public void setFilters(int minFilter, int magFilter) {
   this.minFilter = minFilter;
   this.magFilter = magFilter;
   GL10 gl = glGraphics.getGL();
   gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MIN_FILTER, minFilter);
   gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MAG_FILTER, magFilter);
 }
Example #7
0
    @Override
    public void present(float deltaTime) {
      GL10 gl = glGraphics.getGL();
      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();
    }
Example #8
0
  public void draw(int primitiveType, int offset, int numVertices) {
    GL10 gl = glGraphics.getGL();

    if (indices != null) {
      indices.position(offset);
      gl.glDrawElements(primitiveType, numVertices, GL10.GL_UNSIGNED_SHORT, indices);
    } else {
      gl.glDrawArrays(primitiveType, offset, numVertices);
    }
  }
    @Override
    public void present(float deltaTime) {
      GL10 gl = glGraphics.getGL();
      gl.glClear(GL10.GL_COLOR_BUFFER_BIT);

      bobModel.bind();
      for (int i = 0; i < NUM_BOBS; i++) {
        gl.glLoadIdentity();
        gl.glTranslatef((int) bobs[i].x, (int) bobs[i].y, 0);
        bobModel.draw(GL10.GL_TRIANGLES, 0, 6);
      }
      bobModel.unbind();

      fpsCounter.logFrame();
    }
Example #10
0
  public void bind() {
    GL10 gl = glGraphics.getGL();

    gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
    vertices.position(0);
    gl.glVertexPointer(2, GL10.GL_FLOAT, vertexSize, vertices);

    if (hasColor) {
      gl.glEnableClientState(GL10.GL_COLOR_ARRAY);
      vertices.position(2);
      gl.glColorPointer(4, GL10.GL_FLOAT, vertexSize, vertices);
    }

    if (hasTexCoords) {
      gl.glEnableClientState(GL10.GL_TEXTURE_COORD_ARRAY);
      vertices.position(hasColor ? 6 : 2);
      gl.glTexCoordPointer(2, GL10.GL_FLOAT, vertexSize, vertices);
    }
  }
Example #11
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();
    }
Example #12
0
  private void renderBackground() {
    GL10 gl = glGraphics.getGL();
    gl.glEnable(GL10.GL_BLEND);

    gl.glBlendFunc(GL10.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA);
    batcher.beginBatch(Assets.background);
    switch (board.state) {
      case Board.GAME_READY:
        batcher.drawSprite(
            cam.position.x, cam.position.y, FRUSTUM_WIDTH, FRUSTUM_HEIGHT, Assets.backgroundRegion);
        // Overlay the ready screen on the original background
        batcher.drawSprite(
            cam.position.x, cam.position.y, FRUSTUM_WIDTH, FRUSTUM_HEIGHT, Assets.readyScreen);
        break;

      case Board.GAME_RUNNING:
        batcher.drawSprite(
            cam.position.x, cam.position.y, FRUSTUM_WIDTH, FRUSTUM_HEIGHT, Assets.backgroundRegion);
        break;

      case Board.GAME_PAUSED:
        batcher.drawSprite(
            cam.position.x, cam.position.y, FRUSTUM_WIDTH, FRUSTUM_HEIGHT, Assets.backgroundRegion);
        break;

      case Board.GAME_OVER:
        batcher.drawSprite(
            cam.position.x, cam.position.y, FRUSTUM_WIDTH, FRUSTUM_HEIGHT, Assets.backgroundRegion);

        // Overlay the game over on the original background
        batcher.drawSprite(
            cam.position.x, cam.position.y, FRUSTUM_WIDTH, FRUSTUM_HEIGHT, Assets.gameOverScreen);
        break;
    }
    batcher.endBatch();
  }
Example #13
0
 public void reload() {
   load();
   bind();
   setFilters(minFilter, magFilter);
   glGraphics.getGL().glBindTexture(GL10.GL_TEXTURE_2D, 0);
 }
Example #14
0
 public void dispose() {
   GL10 gl = glGraphics.getGL();
   gl.glBindTexture(GL10.GL_TEXTURE_2D, textureId);
   int[] textureIds = {textureId};
   gl.glDeleteTextures(1, textureIds, 0);
 }
Example #15
0
 public void bind() {
   GL10 gl = glGraphics.getGL();
   gl.glBindTexture(GL10.GL_TEXTURE_2D, textureId);
 }