Android Open Source - SevenWonders Seven Wonders G L Surface View






From Project

Back to project page SevenWonders.

License

The source code is released under:

Apache License

If you think the Android project SevenWonders 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 skylight1.sevenwonders.view;
/*from  w ww. j  a v a  2  s  .c  o m*/
import skylight1.sevenwonders.GameState;
import skylight1.sevenwonders.levels.GameLevel;
import android.content.Context;
import android.opengl.GLSurfaceView;
import android.os.Build;
import android.os.Handler;
import android.view.KeyEvent;

public class SevenWondersGLSurfaceView extends GLSurfaceView {
  
  protected static final String TAG = SevenWondersGLSurfaceView.class.getName();
  
  private SevenWondersGLRenderer renderer;
  
  private TiltControl tiltControl;
  
  private int controlMode;
  static final int CONTROL_MODE_DEFAULT = 0;
  // 0: default accelerometer / D-Pad
  static final int CONTROL_MODE_XPERIA_PLAY = 1;
  // 1: Sony Ericsson Xperia Play  

  private final GameState gameState;
  
  public SevenWondersGLSurfaceView(final Context context, final GameState aGameState) {
    super(context);
    gameState = aGameState;
  }

  public void loadLevel(final Handler aUpdateUiHandler, final GameLevel aLevel) {
    renderer = new SevenWondersGLRenderer(getContext(), aUpdateUiHandler, aLevel, gameState);
    setRenderer(renderer);
  }

  public void initialize() {
    //setDebugFlags(DEBUG_CHECK_GL_ERROR);
  
    if(Build.MODEL.contains("R800a")) {
      controlMode = 1;
    } else {
      controlMode = 0;
      tiltControl = new TiltControl(getContext(), renderer);
    }
    
    setClickable(true);
    setFocusable(true);
    setFocusableInTouchMode(true);
    requestFocus();
  
    setKeepScreenOn(true);
  }
  
  @Override
  public void onPause() {
    if(controlMode == 0)
      tiltControl.stop();
    super.onPause();
  }

  @Override
  public void onResume() {
    super.onResume();
    if(controlMode == 0)
      tiltControl.start();
  }

  @Override
  public boolean onKeyDown(final int aKeyCode, final KeyEvent aEvent) {
    
    if(controlMode == CONTROL_MODE_XPERIA_PLAY) {
      switch(aKeyCode) {
        // left
        case KeyEvent.KEYCODE_DPAD_LEFT:
          renderer.turn(-5f);
          return true;
          
        // right  
        case KeyEvent.KEYCODE_DPAD_RIGHT:
          renderer.turn(5f);
          return true;
          
        // accelerate
        case KeyEvent.KEYCODE_DPAD_CENTER:
          renderer.changeVelocity(SevenWondersGLRenderer.MAXIMUM_VELOCITY / 10f);
          return true;
          
        case KeyEvent.KEYCODE_BACK:
          if(aEvent.isAltPressed()) {
            renderer.changeVelocity(-SevenWondersGLRenderer.MAXIMUM_VELOCITY / 10f);
            return true;
          } else {
            // pass regular back button event to system
            return super.onKeyDown(aKeyCode, aEvent);
          }
          
        case 99:
        case 100:
          // API 9 introduced KEYCODE_BUTTON_X, KEYCODE_BUTTON_Y
          renderer.setPlayerVelocity(0);
          return true;
      }
    } else {
      switch (aKeyCode) {
        case KeyEvent.KEYCODE_DPAD_CENTER:
        case KeyEvent.KEYCODE_SPACE:
          renderer.setPlayerVelocity(0);
          return true;

          // left/q -> left
        case KeyEvent.KEYCODE_DPAD_LEFT:
        case KeyEvent.KEYCODE_Q:
          renderer.turn(-5f);
          return true;

          // right/w -> right
        case KeyEvent.KEYCODE_DPAD_RIGHT:
        case KeyEvent.KEYCODE_W:
          renderer.turn(+5f);
          return true;

        case KeyEvent.KEYCODE_DPAD_UP:
          renderer.changeVelocity(SevenWondersGLRenderer.MAXIMUM_VELOCITY / 10f);
          return true;

        case KeyEvent.KEYCODE_DPAD_DOWN:
          renderer.changeVelocity(-SevenWondersGLRenderer.MAXIMUM_VELOCITY / 10f);
          return true;
      }
    }

    return false;
  }

  public void togglePaused() {
    if(renderer != null) {
      renderer.togglePaused();
    }
  }
  
}




Java Source Code List

com.facebook.android.AsyncFacebookRunner.java
com.facebook.android.DialogError.java
com.facebook.android.FacebookError.java
com.facebook.android.Facebook.java
com.facebook.android.FbDialog.java
com.facebook.android.Util.java
skylight1.sevenwonders.AboutActivity.java
skylight1.sevenwonders.Adverts.java
skylight1.sevenwonders.Analytics.java
skylight1.sevenwonders.GameState.java
skylight1.sevenwonders.LevelChooserActivity.java
skylight1.sevenwonders.MenuActivity.java
skylight1.sevenwonders.PlayActivity.java
skylight1.sevenwonders.ScoreActivity.java
skylight1.sevenwonders.SettingsActivity.java
skylight1.sevenwonders.Settings.java
skylight1.sevenwonders.SevenWondersApplication.java
skylight1.sevenwonders.SoundTracksStoppingExceptionHandler.java
skylight1.sevenwonders.SplashActivity.java
skylight1.sevenwonders.StoryActivity.java
skylight1.sevenwonders.levels.CoinCollisionAction.java
skylight1.sevenwonders.levels.CollisionAction.java
skylight1.sevenwonders.levels.ExtraTimeAction.java
skylight1.sevenwonders.levels.GameLevel.java
skylight1.sevenwonders.levels.GameObjectDescriptor.java
skylight1.sevenwonders.levels.HazardCollisionAction.java
skylight1.sevenwonders.levels.LevelConstructionToolkit.java
skylight1.sevenwonders.levels.ProtectionAction.java
skylight1.sevenwonders.levels.RubyCollisionAction.java
skylight1.sevenwonders.levels.SpellCollisionAction.java
skylight1.sevenwonders.services.SoundTracks.java
skylight1.sevenwonders.social.DialogUtil.java
skylight1.sevenwonders.social.NoNPEWebView.java
skylight1.sevenwonders.social.facebook.FacebookApplicationPost.java
skylight1.sevenwonders.social.facebook.FacebookConfig.java
skylight1.sevenwonders.social.facebook.FacebookScoreActivity.java
skylight1.sevenwonders.social.facebook.FacebookUtil.java
skylight1.sevenwonders.social.facebook.LoginAndGetPermissions.java
skylight1.sevenwonders.social.facebook.SessionStore.java
skylight1.sevenwonders.social.facebook.WallPost.java
skylight1.sevenwonders.social.twitter.AuthRequest.java
skylight1.sevenwonders.social.twitter.AuthStore.java
skylight1.sevenwonders.social.twitter.TwitterUpdater.java
skylight1.sevenwonders.view.Carpet.java
skylight1.sevenwonders.view.CubeBounds.java
skylight1.sevenwonders.view.GameMessagesDisplay.java
skylight1.sevenwonders.view.GameTexture.java
skylight1.sevenwonders.view.Position.java
skylight1.sevenwonders.view.SevenWondersGLRenderer.java
skylight1.sevenwonders.view.SevenWondersGLSurfaceView.java
skylight1.sevenwonders.view.StoryPagesController.java
skylight1.sevenwonders.view.StyledSpannableStringBuilder.java
skylight1.sevenwonders.view.TextStyles.java
skylight1.sevenwonders.view.TiltControl.java
wave.Constants.java
wave.CreateWave.java
wave.RectangleWave.java
wave.TriangleWave.java
wave.UtilsWave.java
wave.VertexWave.java