Rev 68 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 32 | chris | 1 | package com.gebauz.pingK; |
| 2 | |||
| 3 | import com.gebauz.framework.util.GLUtil; |
||
| 4 | import com.gebauz.framework.util.ResourceManager; |
||
| 42 | chris | 5 | import com.gebauz.pingK.game.GameConsts; |
| 32 | chris | 6 | import com.gebauz.pingK.gamestates.GameStateManager; |
| 7 | |||
| 8 | import android.app.Activity; |
||
| 9 | import android.content.pm.ActivityInfo; |
||
| 10 | import android.graphics.PixelFormat; |
||
| 11 | import android.opengl.GLSurfaceView; |
||
| 12 | import android.os.Bundle; |
||
| 13 | import android.os.Handler; |
||
| 14 | import android.view.MotionEvent; |
||
| 15 | import android.view.View; |
||
| 16 | import android.view.Window; |
||
| 17 | import android.view.WindowManager; |
||
| 18 | import android.view.View.OnTouchListener; |
||
| 19 | import android.widget.TextView; |
||
| 20 | |||
| 21 | public class GameActivity extends Activity implements OnTouchListener |
||
| 22 | { |
||
| 23 | private GLSurfaceView mGameView = null; |
||
| 24 | |||
| 25 | final Handler mHandler = new Handler(); |
||
| 26 | |||
| 27 | // Create runnable for posting |
||
| 28 | final Runnable mUpdateResults = new Runnable() { |
||
| 29 | public void run() { |
||
| 71 | chris | 30 | //TextView text = (TextView)findViewById(R.id.debug_text); |
| 31 | //text.setText(MultitouchInput.getInstance().getDebugText()); |
||
| 32 | chris | 32 | } |
| 33 | }; |
||
| 34 | |||
| 35 | /** Called when the activity is first created. */ |
||
| 36 | @Override |
||
| 37 | public void onCreate(Bundle savedInstanceState) |
||
| 38 | { |
||
| 39 | super.onCreate(savedInstanceState); |
||
| 40 | |||
| 41 | getWindow().setFormat(PixelFormat.TRANSLUCENT); |
||
| 42 | getWindow().setWindowAnimations(0); |
||
| 43 | requestWindowFeature(Window.FEATURE_NO_TITLE); |
||
| 44 | getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); |
||
| 45 | |||
| 46 | setContentView(R.layout.main); |
||
| 47 | /* |
||
| 48 | mGameView = new GLSurfaceView(this); |
||
| 49 | mGameView.setRenderer(new GameRenderer(this)); |
||
| 50 | mGameView.setOnTouchListener(this); |
||
| 51 | setContentView(mGameView); |
||
| 52 | */ |
||
| 53 | |||
| 54 | mGameView = (GLSurfaceView)findViewById(R.id.glsurfaceview); |
||
| 41 | chris | 55 | mGameView.setEGLConfigChooser(8, 8, 8, 8, 16, 0); |
| 32 | chris | 56 | mGameView.setRenderer(new GameRenderer(this)); |
| 57 | mGameView.setOnTouchListener(this); |
||
| 58 | |||
| 59 | // set landscape mode |
||
| 60 | setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); |
||
| 61 | |||
| 62 | // set the current context |
||
| 63 | ResourceManager.getInstance().setCurrentContext(this); |
||
| 64 | |||
| 65 | // queue initial game state |
||
| 68 | chris | 66 | GameStateManager.getInstance().setContext(this); |
| 32 | chris | 67 | GameStateManager.getInstance().switchState(getResources().getString(R.string.initial_state)); |
| 68 | |||
| 69 | //Log.v("TEST", "i: " + R.integer.integer_name); |
||
| 70 | } |
||
| 71 | |||
| 72 | protected void onResume() |
||
| 73 | { |
||
| 74 | super.onResume(); |
||
| 75 | |||
| 76 | mGameView.onResume(); |
||
| 77 | } |
||
| 78 | |||
| 79 | protected void onPause() |
||
| 80 | { |
||
| 81 | super.onPause(); |
||
| 82 | |||
| 83 | mGameView.onPause(); |
||
| 84 | } |
||
| 85 | |||
| 86 | public boolean onTouch(View v, MotionEvent event) |
||
| 87 | { |
||
| 88 | MultitouchInput.getInstance().handleInput(event); |
||
| 89 | return true; |
||
| 90 | } |
||
| 91 | |||
| 92 | public void onSurfaceChanged(int w, int h) |
||
| 93 | { |
||
| 94 | GLUtil.getInstance().setWidth(w); |
||
| 95 | GLUtil.getInstance().setHeight(h); |
||
| 42 | chris | 96 | |
| 97 | MultitouchInput.getInstance().setVirtualScreenRatio(GameConsts.VIRTUAL_SCREEN_WIDTH / (float)w, GameConsts.VIRTUAL_SCREEN_HEIGHT / (float)h); |
||
| 32 | chris | 98 | |
| 99 | GameStateManager.getInstance().onSurfaceChanged(w, h); |
||
| 100 | } |
||
| 101 | |||
| 45 | chris | 102 | public void update(float deltaTime) |
| 32 | chris | 103 | { |
| 104 | // Fire off a thread to do some work that we shouldn't do directly in the UI thread |
||
| 37 | chris | 105 | Thread t = new Thread() |
| 106 | { |
||
| 107 | public void run() |
||
| 108 | { |
||
| 32 | chris | 109 | mHandler.post(mUpdateResults); |
| 110 | } |
||
| 111 | }; |
||
| 112 | t.start(); |
||
| 113 | |||
| 45 | chris | 114 | GameStateManager.getInstance().update(deltaTime); |
| 115 | MultitouchInput.getInstance().update(deltaTime); |
||
| 32 | chris | 116 | } |
| 117 | |||
| 118 | public void render() |
||
| 119 | { |
||
| 120 | GameStateManager.getInstance().render(); |
||
| 121 | MultitouchInput.getInstance().render(); |
||
| 122 | } |
||
| 123 | |||
| 124 | } |
||
| 125 | |||
| 126 | |||
| 127 | |||
| 128 |