Rev 84 |
Blame |
Compare with Previous |
Last modification |
View Log
| RSS feed
package com.gebauz.pingK.game;
import com.gebauz.framework.util.MathUtil;
import com.gebauz.framework.util.Sprite2D;
import com.gebauz.pingK.R;
public class ScoreDisplay
{
public static final int MODE_SCORE = 0;
public static final int MODE_OWNGOAL = 1;
public static final float SCORE_DISPLAY_TIME = 2.0f;
private GameLogic mGameLogic;
private int mMode = -1;
private int mLastPlayerScored = 0;
private boolean mIsDone = false;
private float mTargetAngle = 0.0f;
private float mCurrentAngle = 0.0f;
private float mTargetSize = 1.0f;
private float mCurrentSize = 1.0f;
private Sprite2D mScoreSprite = new Sprite2D();
private Sprite2D mOwnGoalSprite = new Sprite2D();
private float mScoreCountdown = 0.0f;
public ScoreDisplay(GameLogic gameLogic)
{
mGameLogic = gameLogic;
mScoreSprite.init(R.drawable.score);
mOwnGoalSprite.init(R.drawable.owngoal);
mScoreSprite.setColor(GameConsts.PINGK_COLOR);
mScoreSprite.x = GameConsts.VIRTUAL_SCREEN_WIDTH / 2.0f;
mScoreSprite.y = mGameLogic.getVirtualPlayFieldHeight() / 2.0f;
mOwnGoalSprite.setColor(GameConsts.PINGK_COLOR);
mOwnGoalSprite.x = GameConsts.VIRTUAL_SCREEN_WIDTH / 2.0f;
mOwnGoalSprite.y = mGameLogic.getVirtualPlayFieldHeight() / 2.0f;
mIsDone = false;
}
public void startDisplay(int playerIndex, int mode)
{
mMode = mode;
mScoreCountdown = SCORE_DISPLAY_TIME;
mLastPlayerScored = playerIndex;
mIsDone = false;
mTargetSize = GameConsts.SCORE_DISPLAY_SIZE_END;
mCurrentSize = GameConsts.SCORE_DISPLAY_SIZE_BEGIN;
mScoreSprite.setColor(GameConsts.PINGK_COLOR);
mOwnGoalSprite.setColor(GameConsts.PINGK_COLOR);
if (((mLastPlayerScored == 0) && (mMode != MODE_OWNGOAL)) ||
((mLastPlayerScored == 1) && (mMode == MODE_OWNGOAL)))
{
mTargetAngle = 90;
mCurrentAngle = 0.0f;
}
else
{
mTargetAngle = 270;
mCurrentAngle = 360.0f;
}
mGameLogic.playSound(R.raw.score);
}
public boolean isDone()
{
return mIsDone;
}
public int getLastPlayerScored()
{
return mLastPlayerScored;
}
public void update(float deltaTime)
{
mScoreCountdown -= deltaTime;
if (mScoreCountdown < 0.0f)
{
mIsDone = true;
return;
}
float alpha = MathUtil.clamp(mScoreCountdown, 0.0f, 1.0f);
mScoreSprite.setColor(GameConsts.PINGK_COLOR.x, GameConsts.PINGK_COLOR.y, GameConsts.PINGK_COLOR.z, alpha);
mOwnGoalSprite.setColor(GameConsts.PINGK_COLOR.x, GameConsts.PINGK_COLOR.y, GameConsts.PINGK_COLOR.z, alpha);
float diff = mTargetAngle - mCurrentAngle;
mCurrentAngle += (diff * deltaTime * GameConsts.SCORE_DISPLAY_ACCEL);
diff = mTargetSize - mCurrentSize;
mCurrentSize += (diff * deltaTime * GameConsts.SCORE_DISPLAY_ACCEL);
}
public void render()
{
if (!mIsDone)
{
if (mMode == MODE_SCORE)
{
mScoreSprite.w = mCurrentSize;
mScoreSprite.h = mCurrentSize;
mScoreSprite.pivotX = mScoreSprite.w/2.0f;
mScoreSprite.pivotY = mScoreSprite.h/2.0f;
mScoreSprite.angle = mCurrentAngle;
mScoreSprite.render();
}
else
{
mOwnGoalSprite.w = mCurrentSize;
mOwnGoalSprite.h = mCurrentSize;
mOwnGoalSprite.pivotX = mOwnGoalSprite.w/2.0f;
mOwnGoalSprite.pivotY = mOwnGoalSprite.h/2.0f;
mOwnGoalSprite.angle = mCurrentAngle;
mOwnGoalSprite.render();
}
}
}
}