Android Open Source - Freebloks-Android Stone Roll Effect






From Project

Back to project page Freebloks-Android.

License

The source code is released under:

GNU General Public License

If you think the Android project Freebloks-Android 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 de.saschahlusiak.freebloks.view.effects;
//from   w  w w .j a v  a 2s .  c  o  m
import javax.microedition.khronos.opengles.GL10;

import de.saschahlusiak.freebloks.model.Stone;
import de.saschahlusiak.freebloks.view.BoardRenderer;
import de.saschahlusiak.freebloks.view.model.ViewModel;

public class StoneRollEffect extends AbsStoneEffect {
  float z, vz;
  float r, vr;
  float ax, ay, az;
  boolean done = false;
  static final float GRAVITY = 61.0f;

  public StoneRollEffect(ViewModel model, Stone stone, int color, int x, int y, float z, float vz) {
    super(model, stone, color, x, y);

    this.z = z;
    this.vz = vz;
    r = 8.0f;

    final float angx=(float)(Math.random() * 2.0 *Math.PI);
    final float angy=(float)(Math.random() * 2.0 *Math.PI);
    ax=(float)(Math.sin(angx)*Math.cos(angy));
    ay=(float)(Math.sin(angy));
    az=(float)(Math.cos(angx)*Math.cos(angy));

    final float p = vz / GRAVITY;
    final float q = 2.0f * -z / GRAVITY;
    if (p * p - q > 0.0) {
      final float time = -p + (float)Math.sqrt(p * p - q);
      vr = -r / time;
    } else vr = r = 0.0f;
  }

  @Override
  public boolean isDone() {
    return done;
  }

  @Override
  public boolean execute(float elapsed) {
    final float EPSILON = 0.10f;
    if (z > EPSILON || (vz > EPSILON || vz < -EPSILON)) {
      z -= vz * elapsed;
      vz += elapsed * GRAVITY;
      if (z < 0.0f) {
        /* impact */
        vz *= -0.55f;
        z = 0.0f;
        /* reset rotation */
        r = 0.0f;
        vr = 0.0f;
        float volume = (float)Math.pow(-vz / 16.0f, 2.0f);
        if (vz > -6.0f)
          vz = 0.0f;

        model.soundPool.play(model.soundPool.SOUND_CLICK1, volume, 0.90f + (float)Math.random() * 0.2f);
      }
    } else {
      r = vr = 0.0f;
      z = 0.0f;
      done = true;
    }
    r += vr * elapsed;

    super.execute(elapsed);
    return true;
  }

  @Override
  public void renderShadow(GL10 gl, BoardRenderer renderer) {
    gl.glPushMatrix();

      gl.glTranslatef(
          -BoardRenderer.stone_size * (float)(model.spiel.m_field_size_x - 1) + BoardRenderer.stone_size * 2.0f * x,
          0,
          -BoardRenderer.stone_size * (float)(model.spiel.m_field_size_y - 1) + BoardRenderer.stone_size * 2.0f * y);

    renderer.renderShadow(gl,
        stone, color,
        z,
        r, ax, ay, az,
        90 * model.board.centerPlayer,
        1.0f, 1.0f);

    gl.glPopMatrix();
  }

  @Override
  public void render(GL10 gl, BoardRenderer renderer) {
    gl.glPushMatrix();

    float offset = (float)(stone.get_stone_size()) - 1.0f;

      gl.glTranslatef(
          -BoardRenderer.stone_size * (float)(model.spiel.m_field_size_x - 1) + BoardRenderer.stone_size * 2.0f * (float)x,
          z,
          -BoardRenderer.stone_size * (float)(model.spiel.m_field_size_y - 1) + BoardRenderer.stone_size * 2.0f * (float)y);
      gl.glTranslatef(
          BoardRenderer.stone_size * offset,
          0,
          BoardRenderer.stone_size * offset);
      gl.glRotatef(r, ax, ay, az);
      gl.glTranslatef(
          -BoardRenderer.stone_size * offset,
          0,
          -BoardRenderer.stone_size * offset);
    renderer.renderPlayerStone(gl, color, stone, BoardRenderer.DEFAULT_ALPHA);

    gl.glPopMatrix();
  }
}




Java Source Code List

com.google.example.games.basegameutils.BaseGameActivity.java
com.google.example.games.basegameutils.GameHelperUtils.java
com.google.example.games.basegameutils.GameHelper.java
de.saschahlusiak.freebloks.AboutActivity.java
de.saschahlusiak.freebloks.Global.java
de.saschahlusiak.freebloks.backup.FreebloksBackupAgent.java
de.saschahlusiak.freebloks.controller.GameMode.java
de.saschahlusiak.freebloks.controller.JNIServer.java
de.saschahlusiak.freebloks.controller.PlayerData.java
de.saschahlusiak.freebloks.controller.SpielClientInterface.java
de.saschahlusiak.freebloks.controller.SpielClient.java
de.saschahlusiak.freebloks.controller.Spielleiter.java
de.saschahlusiak.freebloks.database.FreebloksDBOpenHandler.java
de.saschahlusiak.freebloks.database.FreebloksDB.java
de.saschahlusiak.freebloks.database.HighscoreDB.java
de.saschahlusiak.freebloks.donate.DonateActivity.java
de.saschahlusiak.freebloks.game.ActivityInterface.java
de.saschahlusiak.freebloks.game.AddScoreTask.java
de.saschahlusiak.freebloks.game.CustomGameDialog.java
de.saschahlusiak.freebloks.game.FreebloksActivity.java
de.saschahlusiak.freebloks.game.GameFinishActivity.java
de.saschahlusiak.freebloks.game.GameMenu.java
de.saschahlusiak.freebloks.game.RateAppDialog.java
de.saschahlusiak.freebloks.game.RetainedConfig.java
de.saschahlusiak.freebloks.game.SpielClientThread.java
de.saschahlusiak.freebloks.lobby.ChatEntry.java
de.saschahlusiak.freebloks.lobby.ChatListAdapter.java
de.saschahlusiak.freebloks.lobby.ColorAdapter.java
de.saschahlusiak.freebloks.lobby.LobbyDialog.java
de.saschahlusiak.freebloks.model.Player.java
de.saschahlusiak.freebloks.model.Spiel.java
de.saschahlusiak.freebloks.model.Stone.java
de.saschahlusiak.freebloks.model.Turn.java
de.saschahlusiak.freebloks.model.Turnpool.java
de.saschahlusiak.freebloks.network.NET_CHAT.java
de.saschahlusiak.freebloks.network.NET_CURRENT_PLAYER.java
de.saschahlusiak.freebloks.network.NET_GAME_FINISH.java
de.saschahlusiak.freebloks.network.NET_GRANT_PLAYER.java
de.saschahlusiak.freebloks.network.NET_HEADER.java
de.saschahlusiak.freebloks.network.NET_REQUEST_GAME_MODE.java
de.saschahlusiak.freebloks.network.NET_REQUEST_HINT.java
de.saschahlusiak.freebloks.network.NET_REQUEST_PLAYER.java
de.saschahlusiak.freebloks.network.NET_REQUEST_UNDO.java
de.saschahlusiak.freebloks.network.NET_REVOKE_PLAYER.java
de.saschahlusiak.freebloks.network.NET_SERVER_STATUS.java
de.saschahlusiak.freebloks.network.NET_SET_STONE.java
de.saschahlusiak.freebloks.network.NET_START_GAME.java
de.saschahlusiak.freebloks.network.NET_UNDO_STONE.java
de.saschahlusiak.freebloks.network.Network.java
de.saschahlusiak.freebloks.preferences.AboutFragment.java
de.saschahlusiak.freebloks.preferences.DisplayFragment.java
de.saschahlusiak.freebloks.preferences.FreebloksPreferences.java
de.saschahlusiak.freebloks.preferences.InterfaceFragment.java
de.saschahlusiak.freebloks.preferences.MiscFragment.java
de.saschahlusiak.freebloks.preferences.StatisticsFragment.java
de.saschahlusiak.freebloks.preferences.ThemePreference.java
de.saschahlusiak.freebloks.stats.StatisticsActivity.java
de.saschahlusiak.freebloks.stats.StatisticsAdapter.java
de.saschahlusiak.freebloks.view.BackgroundRenderer.java
de.saschahlusiak.freebloks.view.BoardRenderer.java
de.saschahlusiak.freebloks.view.Freebloks3DView.java
de.saschahlusiak.freebloks.view.FreebloksRenderer.java
de.saschahlusiak.freebloks.view.SimpleModel.java
de.saschahlusiak.freebloks.view.effects.AbsEffect.java
de.saschahlusiak.freebloks.view.effects.AbsStoneEffect.java
de.saschahlusiak.freebloks.view.effects.BoardStoneGlowEffect.java
de.saschahlusiak.freebloks.view.effects.EffectSet.java
de.saschahlusiak.freebloks.view.effects.Effect.java
de.saschahlusiak.freebloks.view.effects.PhysicalStoneEffect.java
de.saschahlusiak.freebloks.view.effects.StoneFadeEffect.java
de.saschahlusiak.freebloks.view.effects.StoneRollEffect.java
de.saschahlusiak.freebloks.view.effects.StoneUndoEffect.java
de.saschahlusiak.freebloks.view.model.Board.java
de.saschahlusiak.freebloks.view.model.CurrentStone.java
de.saschahlusiak.freebloks.view.model.Intro.java
de.saschahlusiak.freebloks.view.model.Sounds.java
de.saschahlusiak.freebloks.view.model.Theme.java
de.saschahlusiak.freebloks.view.model.ViewElement.java
de.saschahlusiak.freebloks.view.model.ViewModel.java
de.saschahlusiak.freebloks.view.model.Wheel.java