Android Open Source - Castle-Invaders Main Menu Screen






From Project

Back to project page Castle-Invaders.

License

The source code is released under:

GNU General Public License

If you think the Android project Castle-Invaders 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 com.noobygames.castleinvaders.screens;
// www  .j  av  a  2 s  .c  o  m
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Screen;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.math.Rectangle;
import com.badlogic.gdx.math.Vector3;
import com.noobygames.castleinvaders.Assets;
import com.noobygames.castleinvaders.CastleInvaders;
import com.noobygames.castleinvaders.Player;
import com.noobygames.utils.OverlapTester;
import com.noobygames.utils.exceptions.OutOfBoundingException;

public class MainMenuScreen implements Screen {

  final CastleInvaders game;

  OrthographicCamera camera;
  Rectangle playBounds;
  Rectangle exitBounds;
  Vector3 touchPoint;

  private Rectangle storeBounds;

  private Rectangle settingBounds;

  private Player player;

  public MainMenuScreen(final CastleInvaders gam, Player player) {
    game = gam;
    this.player = player;
    //Assets.load(game);
    touchPoint = new Vector3();
    camera = new OrthographicCamera();
    camera.setToOrtho(false, 1280, 768);
    playBounds = new Rectangle(80, 494, 150, 150);
    storeBounds = new Rectangle(80, 344, 150, 150);
    settingBounds = new Rectangle(80, 194, 150, 150);
    exitBounds = new Rectangle(80, 34, 150, 150);

  }

  @Override
  public void render(float delta) {
    // TODO Auto-generated method stub
    Gdx.gl.glClearColor(0, 0, 0.2f, 1);
    Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
    Gdx.gl.glEnable(GL20.GL_TEXTURE_2D);

    camera.update();
    game.batch.setProjectionMatrix(camera.combined);

    game.batch.begin();
    game.batch.draw(Assets.menuBackground, 0, 0);
    game.batch.draw(Assets.exitRegion, 80, 34, 150, 150);
    game.batch.draw(Assets.settingsRegion, 80, 194, 150, 150);
    game.batch.draw(Assets.storeRegion, 80, 344, 150, 150);
    game.batch.draw(Assets.playRegion, 80, 494, 150, 150);
    game.batch.end();

    if(Gdx.input.justTouched()) {
      camera.unproject(touchPoint.set(Gdx.input.getX(), Gdx.input.getY(),
          0));
      if(OverlapTester.pointInRectangle(playBounds, touchPoint.x,touchPoint.y))
        try {
          game.setScreen(new GameScreen(game));
        } catch (OutOfBoundingException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
        }
        this.dispose();
      
      if(OverlapTester.pointInRectangle(exitBounds, touchPoint.x, touchPoint.y)){
        System.exit(0);
        this.dispose();
        }  
      
      if(OverlapTester.pointInRectangle(storeBounds, touchPoint.x, touchPoint.y)){
        game.setScreen(new StoreScreen(game, camera, player));
        this.dispose();
      }
    }

  }

  @Override
  public void resize(int width, int height) {
    // TODO Auto-generated method stub

  }

  @Override
  public void show() {
    // TODO Auto-generated method stub

  }

  @Override
  public void hide() {

  }

  @Override
  public void pause() {
    // TODO Auto-generated method stub

  }

  @Override
  public void resume() {
    // TODO Auto-generated method stub
    
  }

  @Override
  public void dispose() {
    // TODO Auto-generated method stub
    
  }
}




Java Source Code List

com.noobgygames.castleinvaders.ui.DragonUltiButton.java
com.noobgygames.castleinvaders.ui.ElementSwitcherButton.java
com.noobgygames.castleinvaders.ui.StoreElement.java
com.noobgygames.castleinvaders.ui.TextureElement.java
com.noobygames.castleinvaders.Assets.java
com.noobygames.castleinvaders.CastleInvaders.java
com.noobygames.castleinvaders.DynamicGameObject.java
com.noobygames.castleinvaders.GameLiving.java
com.noobygames.castleinvaders.GameObject.java
com.noobygames.castleinvaders.MainActivity.java
com.noobygames.castleinvaders.Main.java
com.noobygames.castleinvaders.Player.java
com.noobygames.castleinvaders.Projectile.java
com.noobygames.castleinvaders.Settings.java
com.noobygames.castleinvaders.WorldRenderer.java
com.noobygames.castleinvaders.World.java
com.noobygames.castleinvaders.mobs.Croco.java
com.noobygames.castleinvaders.mobs.EarthDragon.java
com.noobygames.castleinvaders.mobs.FireDragon.java
com.noobygames.castleinvaders.mobs.FireTroll.java
com.noobygames.castleinvaders.mobs.GameScreen.java
com.noobygames.castleinvaders.mobs.GreyTroll.java
com.noobygames.castleinvaders.mobs.IceDragon.java
com.noobygames.castleinvaders.mobs.IceTroll.java
com.noobygames.castleinvaders.mobs.Murloc.java
com.noobygames.castleinvaders.mobs.Orc.java
com.noobygames.castleinvaders.mobs.Skeleton.java
com.noobygames.castleinvaders.screens.GameScreen.java
com.noobygames.castleinvaders.screens.MainMenuScreen.java
com.noobygames.castleinvaders.screens.ScoreScreen.java
com.noobygames.castleinvaders.screens.SplashScreen.java
com.noobygames.castleinvaders.screens.StoreScreen.java
com.noobygames.castleinvaders.store.StoreObject.java
com.noobygames.castleinvaders.store.Store.java
com.noobygames.nerzal.castleinvaders.spells.Burning.java
com.noobygames.nerzal.castleinvaders.spells.Freeze.java
com.noobygames.nerzal.castleinvaders.spells.SpellEffect.java
com.noobygames.nerzal.castleinvaders.spells.Spells.java
com.noobygames.utils.ArrayListUtils.java
com.noobygames.utils.ObjectSelectionContainer.java
com.noobygames.utils.OverlapTester.java
com.noobygames.utils.exceptions.OutOfBoundingException.java
com.noobygames.utils.exceptions.SliderOutOfBoundingsException.java
com.noobygames.utils.ui.Button.java
com.noobygames.utils.ui.ClickableElement.java
com.noobygames.utils.ui.DropDownMenu.java
com.noobygames.utils.ui.Element.java
com.noobygames.utils.ui.RadioButton.java
com.noobygames.utils.ui.RadioGroupButton.java
com.noobygames.utils.ui.ScrollableElement.java
com.noobygames.utils.ui.SimpleElement.java
com.noobygames.utils.ui.Slider.java
com.noobygames.utils.ui.Table.java
com.noobygames.utils.ui.TextBox.java
com.noobygames.utils.ui.Text.java
com.noobygames.utils.ui.Window.java