Subversion Repositories AndroidProjects

Rev

Rev 101 | 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.Vector4;
import com.gebauz.pingK.R;
import com.gebauz.pingK.gamestates.GameStateManager;

public class CrystalHitCounter
{
        private GameLogic mGameLogic = null;
       
        private float mCurrentDisplay = -1.0f;
        private int mCurrentHits = 0;
       
        private float x;
        private float y;
       
        public CrystalHitCounter(GameLogic gameLogic)
        {
                mGameLogic = gameLogic;
        }
       
        public void update(float deltaTime)
        {
                mCurrentDisplay -= deltaTime;          
        }
       
        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);
                       
                        float w = str.length() * scale * Font.CHARACTER_SIZE;
                        float h = Font.CHARACTER_SIZE * scale;
                       
                        mGameLogic.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 = " " + GameStateManager.getInstance().getContext().getResources().getString(R.string.hit_combo);
                        float scale2 = GameConsts.CRYSTAL_HITCOUNTER_SCALE2;
                        float w2 = str2.length() * scale2 * Font.CHARACTER_SIZE;
                        float h2 = Font.CHARACTER_SIZE * scale2;
                       
                        mGameLogic.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));
                }
        }
       
        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;              
        }
}