Rev 217 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 210 | chris | 1 | package com.gebauz.Bauzoid.app; |
| 2 | |||
| 3 | import com.badlogic.gdx.ApplicationListener; |
||
| 4 | import com.badlogic.gdx.Gdx; |
||
| 5 | import com.badlogic.gdx.graphics.GL20; |
||
| 6 | |||
| 7 | /** Base class for applications using Bauzoid engine. */ |
||
| 211 | chris | 8 | public abstract class BauzoidApp implements ApplicationListener |
| 210 | chris | 9 | { |
| 214 | chris | 10 | protected Game mGame = null; |
| 217 | chris | 11 | private long mSystemTimeMs = System.currentTimeMillis(); |
| 210 | chris | 12 | |
| 13 | public BauzoidApp() |
||
| 14 | { |
||
| 15 | } |
||
| 16 | |||
| 17 | @Override |
||
| 18 | public void create() |
||
| 19 | { |
||
| 20 | mGame = new Game(); |
||
| 21 | mGame.init(); |
||
| 211 | chris | 22 | |
| 23 | initGame(); |
||
| 217 | chris | 24 | |
| 25 | mSystemTimeMs = System.currentTimeMillis(); |
||
| 210 | chris | 26 | } |
| 27 | |||
| 28 | @Override |
||
| 29 | public void dispose() |
||
| 30 | { |
||
| 211 | chris | 31 | exitGame(); |
| 32 | |||
| 210 | chris | 33 | mGame.exit(); |
| 34 | mGame = null; |
||
| 35 | } |
||
| 36 | |||
| 37 | @Override |
||
| 38 | public void pause() |
||
| 39 | { |
||
| 213 | chris | 40 | mGame.pause(); |
| 210 | chris | 41 | } |
| 42 | |||
| 43 | @Override |
||
| 44 | public void resume() |
||
| 45 | { |
||
| 219 | chris | 46 | mGame.resume(); |
| 210 | chris | 47 | } |
| 48 | |||
| 49 | @Override |
||
| 50 | public void resize(int w, int h) |
||
| 51 | { |
||
| 213 | chris | 52 | mGame.resize(w, h); |
| 210 | chris | 53 | } |
| 54 | |||
| 55 | @Override |
||
| 56 | public void render() |
||
| 57 | { |
||
| 217 | chris | 58 | long currentTimeMs = System.currentTimeMillis(); |
| 59 | long deltaTimeMs = currentTimeMs - mSystemTimeMs; |
||
| 60 | mSystemTimeMs = currentTimeMs; |
||
| 212 | chris | 61 | |
| 217 | chris | 62 | mGame.update((float)deltaTimeMs / 1000.0f); |
| 212 | chris | 63 | |
| 64 | mGame.render(); |
||
| 210 | chris | 65 | } |
| 66 | |||
| 211 | chris | 67 | /** Called after the engine internals have been initialized - this is the point to kick off the initial game state. */ |
| 68 | public abstract void initGame(); |
||
| 69 | |||
| 70 | /** Called before the engine internals are cleaned up. */ |
||
| 71 | public abstract void exitGame(); |
||
| 214 | chris | 72 | |
| 73 | /** Get the instance of the game. */ |
||
| 74 | public Game getGame() |
||
| 75 | { |
||
| 76 | return mGame; |
||
| 77 | } |
||
| 210 | chris | 78 | |
| 79 | } |