Android Open Source - SevenWonders Level Construction Toolkit






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.levels;
/*w ww  .j  av a2  s. c  o  m*/
import skylight1.sevenwonders.GameState;
import skylight1.sevenwonders.R;
import android.opengl.Matrix;

public class LevelConstructionToolkit {
  // The pyramids are slightly above the ground, this is the amount they have to be moved down.
  private static final int PYRAMID_GROUNDING_ADJUSTMENT = -40;

  private static final ProtectionAction PROTECTION_ACTION = new ProtectionAction();

  private static final float HEIGHT_OF_HAZARDS_FROM_GROUND = 9f;

  private static final float HEIGHT_OF_SPELLS_FROM_GROUND = 11f;

  private static final float HEIGHT_OF_GEMS_FROM_GROUND = 12.5f;

  private static final float HEIGHT_OF_COINS_FROM_GROUND = 12f;

  private static final float HEIGHT_OF_SCARAB_FROM_GROUND = 12f;

  private static final float[] SPELLS_TEXTURE_TRANSFORM = new float[16];
  static {
    // the texture is within the main texture, so it needs a little transformation to map onto the spell
    Matrix.setIdentityM(SPELLS_TEXTURE_TRANSFORM, 0);
    Matrix.translateM(SPELLS_TEXTURE_TRANSFORM, 0, 576f / 1024f, 0, 0);
    Matrix.scaleM(SPELLS_TEXTURE_TRANSFORM, 0, 0.25f, 0.25f, 1f);
  }

  private static final float[] COIN_TEXTURE_TRANSFORM = new float[16];

  static {
    // the texture is within the main texture, so it needs a little transformation to map onto the coin
    Matrix.setIdentityM(COIN_TEXTURE_TRANSFORM, 0);
    Matrix.translateM(COIN_TEXTURE_TRANSFORM, 0, 256f / 512f, 323f / 512f, 0);
    Matrix.scaleM(COIN_TEXTURE_TRANSFORM, 0, 100f / 512f, 189f / 512f, 1f);
  }

  private static final float[] SCARAB_TEXTURE_TRANSFORM = new float[16];
  
  static {
    // the texture is within the main texture, so it needs a little transformation to map onto the scarab
    Matrix.setIdentityM(SCARAB_TEXTURE_TRANSFORM, 0);
    Matrix.translateM(SCARAB_TEXTURE_TRANSFORM, 0, 360f / 512f, 323f / 512f, 0);
    Matrix.scaleM(SCARAB_TEXTURE_TRANSFORM, 0, 85f / 512f, 139f / 512f, 1f);
  }
  
  static void addSpell(final GameLevel aGameLevel, final float anX, final float aZ) {
    final float[] ankhTransformationMatrix = new float[16];
    android.opengl.Matrix.setIdentityM(ankhTransformationMatrix, 0);
    android.opengl.Matrix.translateM(ankhTransformationMatrix, 0, anX, HEIGHT_OF_SPELLS_FROM_GROUND, aZ);
    android.opengl.Matrix.scaleM(ankhTransformationMatrix, 0, 2, 2, 2);

    // And show a column of transparent light on top of them.
    final float[] highlightTransformationMatrix = new float[16];
    final float[] highlightTextureMatrix = new float[16];
    android.opengl.Matrix.setIdentityM(highlightTransformationMatrix, 0);
    android.opengl.Matrix.setIdentityM(highlightTextureMatrix, 0);
    android.opengl.Matrix.translateM(highlightTransformationMatrix, 0, anX, 175, aZ);
    android.opengl.Matrix.scaleM(highlightTransformationMatrix, 0, 8, 4, 8);
    int glowIndex = aGameLevel.glows.size();
    aGameLevel.glows.add(new GameObjectDescriptor(highlightTransformationMatrix, null, R.raw.transparent_white_cyclinder, R.raw.textures));

    final CollisionAction spellsCollisionAction = new SpellCollisionAction(glowIndex);
    aGameLevel.mapOfCollectablesToCollisionActions.put(new GameObjectDescriptor(ankhTransformationMatrix, SPELLS_TEXTURE_TRANSFORM, R.raw.ankh, R.raw.textures), spellsCollisionAction);
    aGameLevel.numberOfSpells++;
  }

  static void addRuby(final GameLevel aGameLevel, final float anX, final float aZ) {
    final float[] transformationMatrix = new float[16];
    android.opengl.Matrix.setIdentityM(transformationMatrix, 0);
    android.opengl.Matrix.translateM(transformationMatrix, 0, anX, HEIGHT_OF_GEMS_FROM_GROUND, aZ);
    android.opengl.Matrix.scaleM(transformationMatrix, 0, 2, 2, 2);
    final CollisionAction rubyCollisionAction = new RubyCollisionAction();
    aGameLevel.mapOfCollectablesToCollisionActions.put(new GameObjectDescriptor(transformationMatrix, null, R.raw.gem, R.raw.textures), rubyCollisionAction);
  }

  static void addProtection(final GameLevel aGameLevel, final float anX, final float aZ) {
    final float[] transformationMatrix = new float[16];
    android.opengl.Matrix.setIdentityM(transformationMatrix, 0);
    android.opengl.Matrix.translateM(transformationMatrix, 0, anX, HEIGHT_OF_GEMS_FROM_GROUND, aZ);
    android.opengl.Matrix.scaleM(transformationMatrix, 0, 0.5f, 0.5f, 0.5f);
    aGameLevel.mapOfCollectablesToCollisionActions.put(new GameObjectDescriptor(transformationMatrix, null, R.raw.shield, R.raw.textures), PROTECTION_ACTION);
  }

  static void addCoin(final GameLevel aGameLevel, final float anX, final float aZ) {
    final float[] transformationMatrix = new float[16];
    android.opengl.Matrix.setIdentityM(transformationMatrix, 0);
    android.opengl.Matrix.translateM(transformationMatrix, 0, anX, HEIGHT_OF_COINS_FROM_GROUND, aZ);
    android.opengl.Matrix.scaleM(transformationMatrix, 0, 2, 2, 2);
    final CollisionAction coinCollisionAction = new CoinCollisionAction();
    aGameLevel.mapOfCollectablesToCollisionActions.put(new GameObjectDescriptor(transformationMatrix, COIN_TEXTURE_TRANSFORM, R.raw.coin, R.raw.textures), coinCollisionAction);
    aGameLevel.numberOfCoins++;
  }
  
  static void addTime(final GameLevel aGameLevel, final float anX, final float aZ) {
    final float[] transformationMatrix = new float[16];
    android.opengl.Matrix.setIdentityM(transformationMatrix, 0);
    android.opengl.Matrix.translateM(transformationMatrix, 0, anX, HEIGHT_OF_SCARAB_FROM_GROUND, aZ);
    android.opengl.Matrix.scaleM(transformationMatrix, 0, 2f, 2f, 2f);
    final CollisionAction scarabCollisionAction = new ExtraTimeAction();
    aGameLevel.mapOfCollectablesToCollisionActions.put(new GameObjectDescriptor(transformationMatrix, SCARAB_TEXTURE_TRANSFORM, R.raw.scarab, R.raw.textures), scarabCollisionAction);
  }

  static void addHazard(final GameLevel aGameLevel, final float anX, final float aZ) {
    final float[] transformationMatrix = new float[16];
    android.opengl.Matrix.setIdentityM(transformationMatrix, 0);
    android.opengl.Matrix.translateM(transformationMatrix, 0, anX, HEIGHT_OF_HAZARDS_FROM_GROUND, aZ);
    final CollisionAction hazardCollisionAction = new HazardCollisionAction();
    aGameLevel.mapOfHazardsToCollisionActions.put(new GameObjectDescriptor(transformationMatrix, null, R.raw.textured_sword, R.raw.textures), hazardCollisionAction);
  }

  static float[] createNewIdentityMatrix() {
    float[] matrix = new float[16];
    Matrix.setIdentityM(matrix, 0);
    return matrix;
  }

  static float[] createBoundingSphere(final float anX, final float aY, final float aZ, final float aRadius) {
    return new float[] { anX, aY, aZ, aRadius };
  }

  /**
   * 
   * @param aGameLevel
   * @param aRotation
   * @param anX
   * @param aY float how high the pyramid sticks out of the ground
   * @param aZ
   */
  static void addPyramid(final GameLevel aGameLevel, final float anX, final float aZ) {
    final float[] coordinateTransform = new float[16];
    Matrix.setIdentityM(coordinateTransform, 0);
    Matrix.translateM(coordinateTransform, 0, anX, PYRAMID_GROUNDING_ADJUSTMENT, aZ);
    aGameLevel.decorations.add(new GameObjectDescriptor(coordinateTransform, null, R.raw.pyramid, R.raw.textures));

    aGameLevel.obstacles.add(new float[] { anX, GameState.HEIGHT_OF_CARPET_FROM_GROUND, aZ, 80 });
  }

  static void addSphynx(final GameLevel aGameLevel, final float anX, final float aZ) {
    final int aRotation = 90;
    final int aY = -30;
    
    final float[] coordinateTransform = new float[16];
    Matrix.setIdentityM(coordinateTransform, 0);
    Matrix.translateM(coordinateTransform, 0, anX, aY, aZ);
    Matrix.rotateM(coordinateTransform, 0, aRotation, 0, 1, 0);
    final float[] textureTransform = new float[16];
    Matrix.setIdentityM(textureTransform, 0);
    aGameLevel.decorations.add(new GameObjectDescriptor(coordinateTransform, null, R.raw.sphinx_scaled, R.raw.sphinx));
  }
}




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