Rev 145 | Details | Compare with Previous | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 137 | chris | 1 | package com.gebauz.pingK.common.game.gamestates; |
| 2 | |||
| 140 | chris | 3 | import java.util.Vector; |
| 4 | |||
| 137 | chris | 5 | import javax.microedition.khronos.opengles.GL10; |
| 6 | |||
| 140 | chris | 7 | import com.gebauz.pingK.common.R; |
| 137 | chris | 8 | import com.gebauz.pingK.common.framework.GLUtil; |
| 140 | chris | 9 | import com.gebauz.pingK.common.framework.ResourceManager; |
| 10 | import com.gebauz.pingK.common.game.Font; |
||
| 137 | chris | 11 | import com.gebauz.pingK.common.game.GameConsts; |
| 140 | chris | 12 | import com.gebauz.pingK.common.game.GameServices; |
| 145 | chris | 13 | import com.gebauz.pingK.common.game.MultitouchInput; |
| 14 | import com.gebauz.pingK.common.game.MultitouchInput.Finger; |
||
| 137 | chris | 15 | |
| 16 | public class CreditsState extends BaseGameState |
||
| 17 | { |
||
| 140 | chris | 18 | static public final float ITEM_FADE_TIME = 3.0f; |
| 19 | static public final float ITEM_DISPLAY_TIME = 5.0f; |
||
| 20 | |||
| 21 | public class CreditsItem |
||
| 22 | { |
||
| 23 | private String mText; |
||
| 24 | private float mSize; |
||
| 25 | private float mPosX; |
||
| 26 | private final float mTargetX; |
||
| 27 | private final float mEndTargetX; |
||
| 28 | private final float mWidth; |
||
| 29 | private float mPosY; |
||
| 30 | private float mLifeTime = 0.0f; |
||
| 31 | |||
| 32 | public CreditsItem(String text, float size, float startPosX, float positionY) |
||
| 33 | { |
||
| 34 | mText = text; |
||
| 35 | mSize = size; |
||
| 36 | mPosY = positionY; |
||
| 37 | mPosX = startPosX; |
||
| 38 | mWidth = (Font.CHARACTER_SIZE * text.length() * mSize); |
||
| 39 | mTargetX = (GameConsts.VIRTUAL_SCREEN_WIDTH - mWidth) / 2.0f; |
||
| 40 | mEndTargetX = (GameConsts.VIRTUAL_SCREEN_WIDTH + mWidth); |
||
| 41 | } |
||
| 42 | |||
| 43 | public void update(float deltaTime) |
||
| 44 | { |
||
| 45 | mLifeTime += deltaTime; |
||
| 46 | |||
| 47 | if (mLifeTime < ITEM_FADE_TIME) |
||
| 48 | { |
||
| 49 | float diff = mTargetX - mPosX; |
||
| 50 | mPosX += diff * deltaTime * 3.0f; |
||
| 51 | } |
||
| 52 | else |
||
| 53 | { |
||
| 54 | if (mPosX < mEndTargetX) |
||
| 55 | mPosX += deltaTime * mLifeTime * GameConsts.VIRTUAL_SCREEN_WIDTH; |
||
| 56 | else |
||
| 57 | mPosX = mEndTargetX; |
||
| 58 | } |
||
| 59 | } |
||
| 60 | |||
| 61 | public void render() |
||
| 62 | { |
||
| 63 | GameServices.getFont().drawText(mText, mPosX, mPosY, mSize); |
||
| 64 | } |
||
| 65 | |||
| 66 | public boolean isDone() |
||
| 67 | { |
||
| 68 | return (mLifeTime > ITEM_DISPLAY_TIME); |
||
| 69 | } |
||
| 70 | } |
||
| 71 | |||
| 72 | public class CreditsPage |
||
| 73 | { |
||
| 74 | private Vector<CreditsItem> mItems = new Vector<CreditsItem>(); |
||
| 75 | |||
| 76 | private boolean mIsDone = false; |
||
| 77 | |||
| 78 | public CreditsPage() |
||
| 79 | { |
||
| 80 | } |
||
| 81 | |||
| 82 | public void update(float deltaTime) |
||
| 83 | { |
||
| 84 | boolean isDone = true; |
||
| 85 | for (int i = 0; i < mItems.size(); i++) |
||
| 86 | { |
||
| 87 | CreditsItem item = mItems.get(i); |
||
| 88 | |||
| 89 | item.update(deltaTime); |
||
| 90 | |||
| 91 | isDone = isDone && item.isDone(); |
||
| 92 | } |
||
| 93 | |||
| 94 | if (isDone) |
||
| 95 | mIsDone = true; |
||
| 96 | } |
||
| 97 | |||
| 98 | public void render() |
||
| 99 | { |
||
| 100 | for (int i = 0; i < mItems.size(); i++) |
||
| 101 | { |
||
| 102 | mItems.get(i).render(); |
||
| 103 | } |
||
| 104 | } |
||
| 105 | |||
| 106 | public void addItem(String text, float size, float initialX, float posY) |
||
| 107 | { |
||
| 108 | mItems.add(new CreditsItem(text, size, initialX, posY)); |
||
| 109 | } |
||
| 110 | |||
| 111 | public boolean isDone() |
||
| 112 | { |
||
| 113 | return mIsDone; |
||
| 114 | } |
||
| 115 | } |
||
| 116 | |||
| 117 | private Vector<CreditsPage> mCredits = new Vector<CreditsPage>(); |
||
| 118 | private int mCurrentPage = 0; |
||
| 119 | |||
| 137 | chris | 120 | public CreditsState() |
| 121 | { |
||
| 122 | } |
||
| 123 | |||
| 124 | @Override |
||
| 125 | public void init() |
||
| 126 | { |
||
| 147 | chris | 127 | GameServices.showAd(false); |
| 128 | |||
| 140 | chris | 129 | startCreditsPage(); |
| 130 | addCreditsItem(R.string.credits1_title, 2.0f, -200.0f, 200.0f); |
||
| 131 | addCreditsItem(R.string.credits1_name1, 3.0f, -300.0f, 250.0f); |
||
| 137 | chris | 132 | |
| 140 | chris | 133 | startCreditsPage(); |
| 134 | addCreditsItem(R.string.credits2_title, 2.0f, -200.0f, 150.0f); |
||
| 135 | addCreditsItem(R.string.credits2_name1, 3.0f, -300.0f, 200.0f); |
||
| 136 | addCreditsItem(R.string.credits2_name2, 3.0f, -400.0f, 240.0f); |
||
| 137 | addCreditsItem(R.string.credits2_name3, 3.0f, -500.0f, 280.0f); |
||
| 138 | |||
| 139 | startCreditsPage(); |
||
| 140 | addCreditsItem(R.string.credits3_title, 2.0f, -200.0f, 200.0f); |
||
| 141 | addCreditsItem(R.string.credits3_name1, 3.0f, -300.0f, 250.0f); |
||
| 142 | |||
| 143 | startCreditsPage(); |
||
| 144 | addCreditsItem(R.string.credits4_title, 2.0f, -200.0f, 200.0f); |
||
| 145 | addCreditsItem(R.string.credits4_name1, 3.0f, -300.0f, 250.0f); |
||
| 146 | |||
| 147 | startCreditsPage(); |
||
| 148 | addCreditsItem(R.string.credits5_title, 2.0f, -200.0f, 150.0f); |
||
| 149 | addCreditsItem(R.string.credits5_name1, 3.0f, -300.0f, 200.0f); |
||
| 150 | addCreditsItem(R.string.credits5_name2, 3.0f, -400.0f, 240.0f); |
||
| 151 | addCreditsItem(R.string.credits5_name3, 3.0f, -500.0f, 280.0f); |
||
| 152 | |||
| 153 | startCreditsPage(); |
||
| 154 | addCreditsItem(R.string.credits6_title, 2.0f, -200.0f, 200.0f); |
||
| 155 | addCreditsItem(R.string.credits6_name1, 3.0f, -300.0f, 250.0f); |
||
| 156 | |||
| 157 | startCreditsPage(); |
||
| 158 | addCreditsItem(R.string.credits7_title, 2.0f, -200.0f, 180.0f); |
||
| 159 | addCreditsItem(R.string.credits7_name1, 3.0f, -300.0f, 230.0f); |
||
| 160 | addCreditsItem(R.string.credits7_name2, 3.0f, -400.0f, 270.0f); |
||
| 161 | |||
| 162 | startCreditsPage(); |
||
| 141 | chris | 163 | addCreditsItem(R.string.credits8_title, 4.0f, -400.0f, 200.0f); |
| 137 | chris | 164 | } |
| 165 | |||
| 166 | @Override |
||
| 167 | public void exit() |
||
| 168 | { |
||
| 140 | chris | 169 | mCredits.clear(); |
| 137 | chris | 170 | } |
| 171 | |||
| 172 | @Override |
||
| 173 | public void onSurfaceChanged(int width, int height) |
||
| 174 | { |
||
| 175 | GLUtil.getGL().glViewport(0, 0, width, height); |
||
| 176 | } |
||
| 177 | |||
| 178 | @Override |
||
| 179 | public void update(float deltaTime) |
||
| 180 | { |
||
| 140 | chris | 181 | //for (int i = 0; i < mCredits.size(); i++) |
| 182 | if (mCurrentPage < mCredits.size()) |
||
| 183 | { |
||
| 184 | CreditsPage page = mCredits.get(mCurrentPage); |
||
| 185 | page.update(deltaTime); |
||
| 186 | |||
| 187 | if (page.isDone()) |
||
| 188 | mCurrentPage++; |
||
| 189 | |||
| 190 | if (mCurrentPage >= mCredits.size()) |
||
| 191 | { |
||
| 192 | GameStateManager.getInstance().switchState("TitleState"); |
||
| 193 | } |
||
| 194 | } |
||
| 145 | chris | 195 | |
| 196 | Finger finger = MultitouchInput.getInstance().getTouchPointInside(0.0f, 0.0f, GameConsts.VIRTUAL_SCREEN_WIDTH, GameConsts.VIRTUAL_SCREEN_HEIGHT); |
||
| 197 | if (finger != null) |
||
| 198 | { |
||
| 199 | // switch state |
||
| 200 | GameStateManager.getInstance().switchState("TitleState"); |
||
| 201 | } |
||
| 137 | chris | 202 | } |
| 203 | |||
| 204 | @Override |
||
| 205 | public void render() |
||
| 206 | { |
||
| 207 | GL10 gl = GLUtil.getGL(); |
||
| 208 | |||
| 140 | chris | 209 | gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f); |
| 137 | chris | 210 | gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT); |
| 211 | |||
| 212 | gl.glMatrixMode(GL10.GL_PROJECTION); |
||
| 213 | gl.glLoadIdentity(); |
||
| 214 | gl.glOrthof(0, GameConsts.VIRTUAL_SCREEN_WIDTH-1.0f, GameConsts.VIRTUAL_SCREEN_HEIGHT-1.0f, 0, 0, 1); |
||
| 215 | |||
| 216 | gl.glMatrixMode(GL10.GL_MODELVIEW); |
||
| 217 | |||
| 140 | chris | 218 | if (mCurrentPage < mCredits.size()) |
| 219 | { |
||
| 220 | mCredits.get(mCurrentPage).render(); |
||
| 221 | } |
||
| 137 | chris | 222 | } |
| 223 | |||
| 224 | @Override |
||
| 225 | public boolean doFadeIn() |
||
| 226 | { |
||
| 227 | return true; |
||
| 228 | } |
||
| 229 | |||
| 230 | @Override |
||
| 231 | public boolean doFadeOut() |
||
| 232 | { |
||
| 233 | return true; |
||
| 234 | } |
||
| 140 | chris | 235 | |
| 236 | public void startCreditsPage() |
||
| 237 | { |
||
| 238 | mCredits.add(new CreditsPage()); |
||
| 239 | } |
||
| 240 | |||
| 241 | public void addCreditsItem(int id, float size, float initialX, float posY) |
||
| 242 | { |
||
| 243 | if (mCredits.size() == 0) |
||
| 244 | return; |
||
| 245 | |||
| 246 | CreditsPage page = mCredits.get(mCredits.size()-1); |
||
| 247 | |||
| 248 | page.addItem(ResourceManager.getResources().getString(id), size, initialX, posY); |
||
| 249 | } |
||
| 137 | chris | 250 | |
| 251 | } |