Details | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 835 | chris | 1 | package com.gebauz.bauzoid.gamestates; |
| 2 | |||
| 3 | import com.badlogic.gdx.Gdx; |
||
| 4 | import com.gebauz.bauzoid.game.Game; |
||
| 5 | import com.gebauz.bauzoid.game.GameObject; |
||
| 6 | import com.gebauz.bauzoid.math.Vector4; |
||
| 7 | |||
| 8 | /** Game state base class. */ |
||
| 9 | public abstract class BaseGameState extends GameObject |
||
| 10 | { |
||
| 11 | // Fields=========================================================================================== |
||
| 12 | |||
| 13 | private Vector4 mFadeInColor = new Vector4(0, 0, 0, 0); |
||
| 14 | private Vector4 mFadeOutColor = new Vector4(0, 0, 0, 0); |
||
| 15 | private boolean mDoFadeIn = false; |
||
| 16 | private boolean mDoFadeOut = false; |
||
| 17 | private boolean mHaveLoadingScreen = false; |
||
| 18 | |||
| 19 | // Methods========================================================================================== |
||
| 20 | |||
| 21 | /** Constructor. */ |
||
| 22 | public BaseGameState(Game game) |
||
| 23 | { |
||
| 24 | super(game); |
||
| 25 | } |
||
| 26 | |||
| 27 | /** Called for any asynchronous loading. Called before init(). |
||
| 28 | * @param param Parameter specified for state switching. Same as in init(). |
||
| 29 | */ |
||
| 30 | public void initAsync(String param) {} |
||
| 31 | |||
| 32 | /** Called when game state is initialized. |
||
| 33 | * @param param Parameter specified for state switching. Same as in initAsync(). |
||
| 34 | */ |
||
| 35 | public abstract void init(String param); |
||
| 36 | |||
| 37 | /** Called when game state is exited and destroyed. */ |
||
| 38 | public abstract void exit(); |
||
| 39 | |||
| 40 | /** Update game logic. */ |
||
| 41 | public abstract void update(float deltaTime); |
||
| 42 | |||
| 43 | /** Update game logic during fading for animations that may continue even during fading. */ |
||
| 44 | public void updateFading(float deltaTime) {} |
||
| 45 | |||
| 46 | /** Render the game. */ |
||
| 47 | public abstract void render(); |
||
| 48 | |||
| 49 | /** Called when the app is paused. */ |
||
| 50 | public void onPause() {} |
||
| 51 | |||
| 52 | /** Called when the app is resumed. */ |
||
| 53 | public void onResume() {} |
||
| 54 | |||
| 55 | /** Called when the surface has been destroyed and recreated. */ |
||
| 56 | public void onSurfaceChanged(int w, int h) |
||
| 57 | { |
||
| 58 | // Standard implementation sets the viewport |
||
| 59 | Gdx.gl.glViewport(0, 0, w, h); |
||
| 60 | } |
||
| 61 | |||
| 62 | public final void switchTo(String nextState, String param) |
||
| 63 | { |
||
| 64 | getGameStateManager().switchTo(nextState, param); |
||
| 65 | } |
||
| 66 | |||
| 67 | public final void switchTo(Class<? extends BaseGameState> nextState, String param) |
||
| 68 | { |
||
| 69 | getGameStateManager().switchTo(nextState, param); |
||
| 70 | } |
||
| 71 | |||
| 72 | // Getters/Setters================================================================================== |
||
| 73 | |||
| 74 | /** Check if the specific game state requires fading in. */ |
||
| 75 | public final boolean doFadeIn() |
||
| 76 | { |
||
| 77 | return mDoFadeIn; |
||
| 78 | } |
||
| 79 | |||
| 80 | /** Check if the specific game state requires fading out. */ |
||
| 81 | public final boolean doFadeOut() |
||
| 82 | { |
||
| 83 | return mDoFadeOut; |
||
| 84 | } |
||
| 85 | |||
| 86 | /** Set fading modes. */ |
||
| 87 | public final void setFading(boolean fadeIn, boolean fadeOut) |
||
| 88 | { |
||
| 89 | mDoFadeIn = fadeIn; |
||
| 90 | mDoFadeOut = fadeOut; |
||
| 91 | } |
||
| 92 | |||
| 93 | /** Set fade in color. */ |
||
| 94 | public final void setFadeInColor(Vector4 fadeInColor) |
||
| 95 | { |
||
| 96 | mFadeInColor = fadeInColor; |
||
| 97 | } |
||
| 98 | |||
| 99 | /** Get fade in color. */ |
||
| 100 | public final Vector4 getFadeInColor() |
||
| 101 | { |
||
| 102 | return mFadeInColor; |
||
| 103 | } |
||
| 104 | |||
| 105 | /** Set fade out color. */ |
||
| 106 | public final void setFadeOutColor(Vector4 fadeOutColor) |
||
| 107 | { |
||
| 108 | mFadeOutColor = fadeOutColor; |
||
| 109 | } |
||
| 110 | |||
| 111 | /** Get fade out color. */ |
||
| 112 | public final Vector4 getFadeOutColor() |
||
| 113 | { |
||
| 114 | return mFadeOutColor; |
||
| 115 | } |
||
| 116 | |||
| 117 | /** Check if the GameState requires a loading screen. */ |
||
| 118 | public final boolean haveLoadingScreen() |
||
| 119 | { |
||
| 120 | return mHaveLoadingScreen; |
||
| 121 | } |
||
| 122 | |||
| 123 | public void enableLoadingScreen(boolean haveLoadingScreen) |
||
| 124 | { |
||
| 125 | mHaveLoadingScreen = haveLoadingScreen; |
||
| 126 | } |
||
| 127 | } |
||
| 128 | |||
| 129 |