package com.gebauz.pingk.entities;
import com.gebauz.Bauzoid.graphics.Font;
import com.gebauz.Bauzoid.math.MathUtil;
import com.gebauz.Bauzoid.math.Vector4;
import com.gebauz.pingk.PingkCustomServices;
import com.gebauz.pingk.game.GameConsts;
import com.gebauz.pingk.game.GameLogic;
public class CrystalHitCounter
extends Entity
{
private Font mFont =
null;
private float mCurrentDisplay = -1.0f
;
private int mCurrentHits =
0;
private float x
;
private float y
;
private Vector4 mColor
;
public CrystalHitCounter
(GameLogic gameLogic
)
{
super(gameLogic
);
}
@
Override
public void init
()
{
PingkCustomServices services =
(PingkCustomServices
)getGameLogic
().
getGame().
getCustomServices();
mFont = services.
getFont();
mColor = GameConsts.
PINGK_COLOR.
copy();
}
@
Override
public void exit
()
{
// release reference
mFont =
null;
mColor =
null;
}
@
Override
public void update
(float deltaTime
)
{
mCurrentDisplay -= deltaTime
;
}
@
Override
public void render
()
{
if ((mCurrentDisplay
> 0.0f
) && (mCurrentHits
> 1))
{
float alpha = MathUtil.
clamp(mCurrentDisplay / GameConsts.
CRYSTAL_HITCOUNTER_DISPLAY_TIME, 0.0f, 1.0f
);
float scale = GameConsts.
CRYSTAL_HITCOUNTER_SCALE + MathUtil.
ease(MathUtil.
clamp((mCurrentDisplay -
(GameConsts.
CRYSTAL_HITCOUNTER_DISPLAY_TIME-0.5f
)) / 0.5f, 0.0f, 1.0f
)) * 1.5f
;
String str =
String.
format("%d", mCurrentHits
);
mColor.
w = alpha
;
float w = mFont.
getTextWidth(str, scale
);
float h = mFont.
getTextHeight(str, scale
);
mFont.
drawText(str, x - w/2.0f, y - h/2.0f, mColor, scale
);
//GameServices.getFont().drawText(str, x - w/2.0f, y - h/2.0f, scale, new Vector4(GameConsts.PINGK_COLOR.x, GameConsts.PINGK_COLOR.y, GameConsts.PINGK_COLOR.z, alpha));
// String str2 = " " + ResourceManager.getInstance().getCurrentContext().getResources().getString(R.string.hit_combo);
// TODO: string resources!
String str2 =
" " +
"HITS!";
float scale2 = GameConsts.
CRYSTAL_HITCOUNTER_SCALE2;
float w2 = mFont.
getTextWidth(str2, scale2
);
float h2 = mFont.
getTextHeight(str2, scale2
);
//GameServices.getFont().drawText(str2, x + w/2.0f, y - h2/2.0f, scale2, new Vector4(GameConsts.PINGK_COLOR.x, GameConsts.PINGK_COLOR.y, GameConsts.PINGK_COLOR.z, alpha));
mFont.
drawText(str2, x + w/2.0f, y - h2/2.0f, mColor, scale2
);
}
}
public void addHit
(float posX,
float posY
)
{
mCurrentDisplay = GameConsts.
CRYSTAL_HITCOUNTER_DISPLAY_TIME;
mCurrentHits++
;
x = posX
;
y = posY
;
}
public void resetHits
()
{
mCurrentDisplay = -1.0f
;
mCurrentHits =
0;
}
public int getCurrentHits
()
{
return mCurrentHits
;
}
}