Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.wiagames.pacman;
- import android.app.Activity;
- import android.content.Context;
- import android.opengl.GLSurfaceView;
- import android.os.Bundle;
- import android.util.AttributeSet;
- import android.view.MotionEvent;
- import android.view.View;
- import javax.microedition.khronos.egl.EGLConfig;
- import javax.microedition.khronos.opengles.GL10;
- public class MainActivity extends Activity implements View.OnTouchListener {
- private PacmanGLSurfaceView mPacmanSurfaceView;
- static {
- System.loadLibrary("pacman");
- }
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- mPacmanSurfaceView = (PacmanGLSurfaceView) findViewById(R.id.gl_surface_view);
- final PacmanRenderer renderer = new PacmanRenderer();
- mPacmanSurfaceView.setRenderer(renderer);
- setupControls();
- }
- private void setupControls() {
- View down = findViewById(R.id.down);
- down.setOnTouchListener(this);
- View up = findViewById(R.id.up);
- up.setOnTouchListener(this);
- View left = findViewById(R.id.left);
- left.setOnTouchListener(this);
- View right = findViewById(R.id.right);
- right.setOnTouchListener(this);
- }
- @Override
- protected void onPause() {
- super.onPause();
- mPacmanSurfaceView.onPause();
- }
- @Override
- protected void onResume() {
- super.onResume();
- mPacmanSurfaceView.onResume();
- }
- @Override
- public boolean onTouch(View view, MotionEvent motionEvent) {
- if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) {
- switch (view.getId()) {
- case R.id.down:
- PacmanGLSurfaceView.nativeDown();
- return true;
- case R.id.up:
- PacmanGLSurfaceView.nativeUp();
- return true;
- case R.id.left:
- PacmanGLSurfaceView.nativeLeft();
- return true;
- case R.id.right:
- PacmanGLSurfaceView.nativeRight();
- return true;
- default:
- return false;
- }
- } else {
- return false;
- }
- }
- }
- /**
- * GL Surface View
- *
- * @author rankor777
- */
- class PacmanGLSurfaceView extends GLSurfaceView {
- private PacmanRenderer mRenderer;
- public PacmanGLSurfaceView(Context context, AttributeSet attrs) {
- super(context, attrs);
- mRenderer = new PacmanRenderer();
- }
- private static native void nativePause();
- public static native void nativeDown();
- public static native void nativeUp();
- public static native void nativeLeft();
- public static native void nativeRight();
- }
- /**
- * GL Renderer
- *
- * @author rankor777
- */
- class PacmanRenderer implements GLSurfaceView.Renderer {
- public void onSurfaceCreated(GL10 gl, EGLConfig config) {
- nativeInit();
- }
- public void onSurfaceChanged(GL10 gl, int w, int h) {
- nativeResize(w, h);
- }
- public void onDrawFrame(GL10 gl) {
- nativeRender();
- }
- private static native void nativeInit();
- private static native void nativeResize(int w, int h);
- private static native void nativeRender();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement