Android Open Source - Freebloks-Android Physical Stone 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;
// ww w  .  j  av a  2  s . 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 PhysicalStoneEffect extends AbsStoneEffect {
  public static final float GRAVITY = 17.0f;
  /* Aktuelle Position des Steins in Welt-Koordinaten. */
  float x,y,z;
  /* Aktuellen Winkel */
  float ang;
  /* Rotationsgeschwindigkeit, sowie Rotationsachsen. */
  float angspeed,ax,ay,az;
  /* Geschwindigkeit des Steins in Einheiten/sek */
  float speedx,speedy,speedz;
  /* Angestrebte Position auf dem Feld. Bei Landung wird die Position daran ausgerichtet,
     um kleine Rechenungenauigkeiten waehrend der Animation auszugleichen. */
  float dx,dy,dz;

  public PhysicalStoneEffect(ViewModel model, Stone stone, int color) {
    super(model, stone, color, 0, 0);
    this.x = this.y = this.z = 0.0f;
    ang = 0.0f;
    angspeed = 0.0f;
    ax = az = speedx = speedy = speedz = 0.0f;
    ay = 1.0f;
  }

  @Override
  public void renderShadow(GL10 gl, BoardRenderer renderer) {
    gl.glPushMatrix();
    gl.glScalef(1, 0.01f, 1);
    gl.glTranslatef(x, 0, z);

    float m_alpha = 0.60f - y / 20.0f;
      gl.glTranslatef(-2.5f * y * 0.11f, 0, 2.0f * y * 0.11f);

    gl.glRotatef(ang, ax, ay, az);
    gl.glScalef(1.0f + y / 18.0f, 1, 1.0f + y / 18.0f);


      gl.glTranslatef(
         +BoardRenderer.stone_size-(float)stone.get_stone_size()/2.0f*BoardRenderer.stone_size*2.0f,
         0.0f,
          +BoardRenderer.stone_size-(float)stone.get_stone_size()/2.0f*BoardRenderer.stone_size*2.0f);
    renderer.renderStoneShadow(gl, color, stone, m_alpha);
    gl.glPopMatrix();
  }

  @Override
  public void render(GL10 gl, BoardRenderer renderer) {
    gl.glPushMatrix();
    gl.glTranslatef(x, y, z);
    gl.glRotatef(ang, ax, ay, az);

    gl.glTranslatef(
         +BoardRenderer.stone_size-(float)stone.get_stone_size()/2.0f*BoardRenderer.stone_size*2.0f,
         0.0f,
          +BoardRenderer.stone_size-(float)stone.get_stone_size()/2.0f*BoardRenderer.stone_size*2.0f);

    renderer.renderPlayerStone(gl, color, stone, BoardRenderer.DEFAULT_ALPHA);
    gl.glPopMatrix();
  }

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

  public void setPos(float sx, float sy, float sz) {
    this.x=sx;
    this.y=sy;
    this.z=sz;
  }

  public void setRotationSpeed(float angs,float ax,float ay,float az) {
    angspeed=angs;
    this.ax=ax;
    this.ay=ay;
    this.az=az;
  }

  public void setSpeed(float sx,float sy,float sz) {
    speedx=sx;
    speedy=sy;
    speedz=sz;
  }

  public void setDestination(float destx,float desty,float destz) {
    dx=destx;
    dy=desty;
    dz=destz;
  }

  @Override
  public boolean execute(float elapsed) {
    super.execute(elapsed);

    /* Gradlinige Bewegung, einfach zu animieren. */
    x+=speedx*elapsed;
    y-=speedy*elapsed;
    z+=speedz*elapsed;
    /* Konstante Winkelgeschwindigkeit bei Rotation. Linear animieren. */
    ang+=elapsed*angspeed;
    /* wenn y unterhalb von dy gefallen ist, Stein auf dx/dy/dz setzen. */
    if (y<dy && dy>-100.0)
    {
      /* Stein soll wieder nach oben huepfen, aber mit gedaempfter vertikaler Geschw. */
      if (speedy>0.5)speedy=-speedy*0.32f;else speedy=0.0f;
      /* Soll nicht mehr rotieren, und soll genau parallel zur Erde sein. */
      angspeed=0.0f;
      ang=0.0f;
      /* x und y Geschw. auf 0 setzen. */
      speedx=0.0f;
      speedz=0.0f;
      /* Position auf Ziel setzen. */
      x=dx;
      y=dy;
      z=dz;
    }
    /* Stein vertikal beschleunigen (Gravitation). */
    speedy+=elapsed*GRAVITY;
    /* Der Stein will nie entfernt werden, verschwindet nie automatisch. */
    return false;
  }

  public final float getX() { return x;}
  public final float getY() { return y;}
  public final float getZ() { return z;}
  public final void unsetDestination() { dy=-200.0f; }
}




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