Subversion Repositories AndroidProjects

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
101 chris 1
package com.gebauz.pingK.game;
2
 
3
import com.gebauz.framework.util.MathUtil;
4
import com.gebauz.framework.util.Vector4;
5
import com.gebauz.pingK.R;
6
import com.gebauz.pingK.gamestates.GameStateManager;
7
 
8
public class CrystalHitCounter
9
{
10
        private GameLogic mGameLogic = null;
11
 
12
        private float mCurrentDisplay = -1.0f;
13
        private int mCurrentHits = 0;
14
 
15
        private float x;
16
        private float y;
17
 
18
        public CrystalHitCounter(GameLogic gameLogic)
19
        {
20
                mGameLogic = gameLogic;
21
        }
22
 
23
        public void update(float deltaTime)
24
        {
25
                mCurrentDisplay -= deltaTime;          
26
        }
27
 
28
        public void render()
29
        {
30
                if ((mCurrentDisplay > 0.0f) && (mCurrentHits > 1))
31
                {
32
                        float alpha = MathUtil.clamp(mCurrentDisplay / GameConsts.CRYSTAL_HITCOUNTER_DISPLAY_TIME, 0.0f, 1.0f);
33
 
34
                        float scale = GameConsts.CRYSTAL_HITCOUNTER_SCALE + MathUtil.ease(MathUtil.clamp((mCurrentDisplay - 1.0f) / 0.5f, 0.0f, 1.0f)) * 1.5f;
35
 
36
                        String str = String.format("%d", mCurrentHits);
37
 
38
                        float w = str.length() * scale * Font.CHARACTER_SIZE;
39
                        float h = Font.CHARACTER_SIZE * scale;
40
 
41
                        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));
42
 
43
                        String str2 = " " + GameStateManager.getInstance().getContext().getResources().getString(R.string.hit_combo);
44
                        float scale2 = GameConsts.CRYSTAL_HITCOUNTER_SCALE2;
45
                        float w2 = str2.length() * scale2 * Font.CHARACTER_SIZE;
46
                        float h2 = Font.CHARACTER_SIZE * scale2;
47
 
48
                        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));
49
                }
50
        }
51
 
52
        public void addHit(float posX, float posY)
53
        {
54
                mCurrentDisplay = GameConsts.CRYSTAL_HITCOUNTER_DISPLAY_TIME;
55
                mCurrentHits++;
56
 
57
                x = posX;
58
                y = posY;
59
        }
60
 
61
        public void resetHits()
62
        {
63
                mCurrentDisplay = -1.0f;
64
                mCurrentHits = 0;              
65
        }
66
}
67
 
68