Android Open Source - SimpleGame Menu Screen






From Project

Back to project page SimpleGame.

License

The source code is released under:

GNU General Public License

If you think the Android project SimpleGame listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package ru.rs.screens;
//  w ww  . ja  v a 2 s  .  c om
import java.util.List;

import ru.rs.interfaces.Game;
import ru.rs.interfaces.Graphics;
import ru.rs.interfaces.Input;
import ru.rs.interfaces.Input.TouchEvent;
import ru.rs.objects.Screen;
import android.graphics.Color;
import android.graphics.Paint;

public class MenuScreen extends Screen {
  private Input input;
  private List<TouchEvent> events;
  private Graphics graphics;

  public MenuScreen(Game g) {
    super(g);
    input = game.getInput();
    graphics = game.getGraphics();
  }

  @Override
  public void update(float delta) {
    events = input.getTouchEvents();
    for (TouchEvent event : events) {
      if (event.type == TouchEvent.TOUCH_UP) {
        checkTouch(event);
      }
    }

  }

  @Override
  public void render(float delta) {
    Paint paint = new Paint();
    paint.setTextSize(24);
    paint.setColor(Color.GREEN);

    graphics.drawText("Play", graphics.getWidth() / 2 - 5,
        graphics.getHeight() / 2, paint);

    paint.setColor(Color.RED);
    graphics.drawText("Exit", graphics.getWidth() / 2 - 5,
        graphics.getHeight(), paint);
  }

  private void checkTouch(TouchEvent event) {
    if (inBounds(event, graphics.getWidth() / 2 - 10, graphics.getHeight(),
        15, 5)) {
      game.exit();
    } else if (inBounds(event, graphics.getWidth() / 2,
        graphics.getHeight() / 2, 30, 15)) {
      game.setScreen(new CollisionScreen(game));
    }

  }
}




Java Source Code List

ru.rs.Resources.java
ru.rs.SimpleGame.java
ru.rs.gameobjects.Castle.java
ru.rs.gameobjects.DynamicObject.java
ru.rs.gameobjects.GeneralGrid.java
ru.rs.gameobjects.Side.java
ru.rs.gameobjects.SimpleGameWorld.java
ru.rs.gameobjects.SimpleObject.java
ru.rs.gameobjects.Unit.java
ru.rs.screens.CollisionScreen.java
ru.rs.screens.LoadingScreen.java
ru.rs.screens.MenuScreen.java