Details | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 71 | chris | 1 | package com.gebauz.pingK.game; |
| 2 | |||
| 3 | import java.util.Vector; |
||
| 4 | |||
| 5 | import com.gebauz.framework.util.MathUtil; |
||
| 6 | import com.gebauz.framework.util.Sprite2D; |
||
| 7 | import com.gebauz.framework.util.Vector4; |
||
| 8 | import com.gebauz.pingK.R; |
||
| 9 | |||
| 10 | public class PaddleImpact |
||
| 11 | { |
||
| 12 | public class ImpactElement |
||
| 13 | { |
||
| 14 | private Sprite2D mImpactSprite = null; |
||
| 15 | private float x; |
||
| 16 | private float y; |
||
| 17 | private float mRotation; |
||
| 18 | private float mLifeTime; |
||
| 19 | |||
| 20 | public ImpactElement(Sprite2D sprite, float posX, float posY, float rotation) |
||
| 21 | { |
||
| 22 | mImpactSprite = sprite; |
||
| 23 | x = posX; |
||
| 24 | y = posY; |
||
| 25 | mRotation = rotation; |
||
| 26 | mLifeTime = 0.0f; |
||
| 27 | } |
||
| 28 | |||
| 29 | public void update(float deltaTime) |
||
| 30 | { |
||
| 31 | mLifeTime += deltaTime; |
||
| 32 | } |
||
| 33 | |||
| 34 | public void render() |
||
| 35 | { |
||
| 36 | mImpactSprite.x = x; |
||
| 37 | mImpactSprite.y = y; |
||
| 38 | mImpactSprite.angle = mRotation; |
||
| 39 | |||
| 40 | float alpha = 1.0f - MathUtil.clamp(mLifeTime / GameConsts.PADDLE_IMPACT_LIFETIME, 0.0f, 1.0f); |
||
| 41 | |||
| 42 | mImpactSprite.setColor(new Vector4(1.0f, 1.0f, 1.0f, alpha)); |
||
| 43 | mImpactSprite.render(); |
||
| 44 | } |
||
| 45 | |||
| 46 | public boolean isDone() |
||
| 47 | { |
||
| 48 | return (mLifeTime > GameConsts.PADDLE_IMPACT_LIFETIME); |
||
| 49 | } |
||
| 50 | } |
||
| 51 | |||
| 52 | private GameLogic mGameLogic = null; |
||
| 53 | private Sprite2D mImpactSprite = new Sprite2D(); |
||
| 54 | |||
| 55 | private Vector<ImpactElement> mImpacts = new Vector<ImpactElement>(); |
||
| 56 | |||
| 57 | public PaddleImpact(GameLogic gameLogic) |
||
| 58 | { |
||
| 59 | mGameLogic = gameLogic; |
||
| 60 | |||
| 61 | mImpactSprite.init(R.drawable.paddleimpact, 0, 0, GameConsts.PADDLE_IMPACT_WIDTH, GameConsts.PADDLE_IMPACT_HEIGHT); |
||
| 62 | } |
||
| 63 | |||
| 64 | public void update(float deltaTime) |
||
| 65 | { |
||
| 66 | int i = 0; |
||
| 67 | while (i < mImpacts.size()) |
||
| 68 | { |
||
| 69 | ImpactElement element = mImpacts.get(i); |
||
| 70 | element.update(deltaTime); |
||
| 71 | |||
| 72 | if (element.isDone()) |
||
| 73 | { |
||
| 74 | mImpacts.remove(i); |
||
| 75 | continue; |
||
| 76 | } |
||
| 77 | |||
| 78 | i++; |
||
| 79 | } |
||
| 80 | } |
||
| 81 | |||
| 82 | public void render() |
||
| 83 | { |
||
| 84 | for (int i = 0; i < mImpacts.size(); i++) |
||
| 85 | { |
||
| 86 | mImpacts.get(i).render(); |
||
| 87 | } |
||
| 88 | } |
||
| 89 | |||
| 90 | public void addImpact(float x, float y, float rot) |
||
| 91 | { |
||
| 92 | mImpacts.add(new ImpactElement(mImpactSprite, x, y, rot)); |
||
| 93 | } |
||
| 94 | } |
||
| 95 | |||
| 96 |