package com.gebauz.pingk.entities;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.audio.Sound;
import com.badlogic.gdx.graphics.Texture;
import com.gebauz.Bauzoid.graphics.sprite.Sprite;
import com.gebauz.Bauzoid.math.MathUtil;
import com.gebauz.Bauzoid.math.Vector4;
import com.gebauz.pingk.game.GameConsts;
import com.gebauz.pingk.game.GameLogic;
public class ScoreDisplay
extends Entity
{
public static final int MODE_SCORE =
0;
public static final int MODE_OWNGOAL =
1;
public static final float SCORE_DISPLAY_TIME = 2.0f
;
private Sprite mScoreSprite =
null;
private Sprite mOwnGoalSprite =
null;
private int mMode = -
1;
private int mLastPlayerScored =
1;
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 float mScoreCountdown = 0.0f
;
private int mScoreGained =
0;
private Sound mScore =
null;
public ScoreDisplay
(GameLogic gameLogic
)
{
super(gameLogic
);
}
public void init
()
{
mScoreSprite =
new Sprite
(getGameLogic
().
getGraphics(),
new Texture
(Gdx.
files.
internal("data/textures/score.png")));
mScoreSprite.
x = GameConsts.
VIRTUAL_SCREEN_WIDTH / 2.0f
;
mScoreSprite.
y = getGameLogic
().
getPlayField().
getVirtualHeight() / 2.0f
;
mScoreSprite.
centerPivot();
mScoreSprite.
color = GameConsts.
PINGK_COLOR;
mOwnGoalSprite =
new Sprite
(getGameLogic
().
getGraphics(),
new Texture
(Gdx.
files.
internal("data/textures/owngoal.png")));
mOwnGoalSprite.
x = GameConsts.
VIRTUAL_SCREEN_WIDTH / 2.0f
;
mOwnGoalSprite.
y = getGameLogic
().
getPlayField().
getVirtualHeight() / 2.0f
;
mOwnGoalSprite.
centerPivot();
mOwnGoalSprite.
color = GameConsts.
PINGK_COLOR;
mScore = getAudio
().
newManagedSound("data/sounds/score.wav");
}
public void exit
()
{
if (mScoreSprite
!=
null)
{
mScoreSprite.
dispose();
mScoreSprite =
null;
}
if (mOwnGoalSprite
!=
null)
{
mOwnGoalSprite.
dispose();
mOwnGoalSprite =
null;
}
getAudio
().
removeManagedSound(mScore
);
mScore =
null;
}
public void update
(float deltaTime
)
{
mScoreCountdown -= deltaTime
;
if (mScoreCountdown
< 0.0f
)
{
mIsDone =
true;
return;
}
float alpha = MathUtil.
clamp(mScoreCountdown, 0.0f, 1.0f
);
mScoreSprite.
color =
new Vector4
(GameConsts.
PINGK_COLOR.
x, GameConsts.
PINGK_COLOR.
y, GameConsts.
PINGK_COLOR.
z, alpha
);
mOwnGoalSprite.
color =
new Vector4
(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.
centerPivot();
mScoreSprite.
angle = mCurrentAngle
;
mScoreSprite.
render();
}
else
{
mOwnGoalSprite.
w = mCurrentSize
;
mOwnGoalSprite.
h = mCurrentSize
;
mOwnGoalSprite.
centerPivot();
mOwnGoalSprite.
angle = mCurrentAngle
;
mOwnGoalSprite.
render();
}
}
}
public final void startDisplay
(int playerIndex,
int mode,
int scoreGained
)
{
mMode = mode
;
mScoreCountdown = SCORE_DISPLAY_TIME
;
mLastPlayerScored = playerIndex
;
mScoreGained = scoreGained
;
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
;
}
getAudio
().
playSound(mScore
);
}
public final boolean isDone
()
{
return mIsDone
;
}
public int getLastPlayerScored
()
{
return mLastPlayerScored
;
}
}