Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <sys/time.h>
- #include <jni.h>
- #include <android/log.h>
- #include <GLES2/gl2.h>
- #include <GLES2/gl2ext.h>
- #include <GLES/gl.h>
- #include "main.h"
- #include "Pacman.h"
- float enemyRect[18] = {
- 0, 1, 0,
- 0, 0, 0,
- 1, 0, 0,
- 0, 1, 0,
- 1, 0, 0,
- 1, 1, 0
- };
- int pacmanDirection = DIR_Y;
- int pacmanMoveValue = VALUE_POSITIVE;
- Pacman pacman;
- static void printGLString(const char *name, GLenum s) {
- const char *v = (const char *) glGetString(s);
- LOGI("GL %s = %s\n", name, v);
- }
- static void checkGlError(const char* op) {
- for (GLint error = glGetError(); error; error = glGetError()) {
- LOGE("after %s() glError (0x%x)\n", op, error);
- }
- }
- /**
- * Initialize the GL subsystem
- */
- void Java_com_wiagames_pacman_PacmanRenderer_nativeInit(JNIEnv* env) {
- printGLString("Version", GL_VERSION);
- printGLString("Vendor", GL_VENDOR);
- printGLString("Renderer", GL_RENDERER);
- printGLString("Extensions", GL_EXTENSIONS);
- glEnableClientState(GL_VERTEX_ARRAY);
- glEnableClientState(GL_TEXTURE_COORD_ARRAY);
- glEnable(GL_BLEND);
- glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
- glEnable(GL_TEXTURE_2D);
- glClearColor(0,0,0,0);
- glColor4f(1,1,1,1);
- glDisable(GL_DEPTH_TEST);
- glDisable(GL_CULL_FACE);
- LOGE("Native start");
- }
- /**
- * Resize window
- */
- void Java_com_wiagames_pacman_PacmanRenderer_nativeResize(JNIEnv* env,
- jobject thiz, jint w, jint h) {
- LOGI("nativeResize (%i,%i)", w, h);
- if (h == 0) {
- h = 1;
- }
- glViewport(0, 0, w, h);
- checkGlError("glViewport");
- glMatrixMode(GL_PROJECTION);
- const float ratio=w/(float)h;
- glLoadIdentity();
- glOrthof(0, 15, 15/ratio, 0, -1, 1);
- checkGlError("glViewport");
- glMatrixMode(GL_MODELVIEW);
- }
- /**
- * Finalize the graphics state
- */
- void Java_com_wiagames_pacman_PacmanRenderer_nativeDone(JNIEnv* env) {
- // TODO
- }
- /**
- * Pause event from Android activity lifecycle loop
- */
- void Java_com_wiagames_PacmanGLSurfaceView_nativePause(JNIEnv* env) {
- LOGE("Pause");
- }
- /**
- * Move the pacman & the enemy
- */
- //void moveObjects() {
- // struct timeval tv;
- // struct timezone tz;
- //
- // gettimeofday(&tv, &tz);
- //
- // if (tvSet) {
- // if (tv.tv_usec - lastTv.tv_usec < 1000) {
- // return;
- // }
- // } else {
- // tvSet = TRUE;
- // }
- //
- // lastTv = tv;
- //
- // movePlayer(pacmanRect, pacmanDirection, pacmanMoveValue);
- //}
- /**
- * Draw the given object
- */
- void drawObject(const GameObject &object) {
- glVertexPointer(3, GL_FLOAT, 0, object.vertexArray);
- glDrawArrays(GL_TRIANGLES, 0, object.vertexCount);
- }
- /**
- * Draw the objects in the scene
- */
- void drawObjects() {
- drawObject(pacman);
- }
- /**
- * Render the next frame
- */
- void Java_com_wiagames_pacman_PacmanRenderer_nativeRender(JNIEnv* env) {
- glClear(GL_COLOR_BUFFER_BIT);
- glLoadIdentity();
- glPushMatrix();
- drawObjects();
- glPopMatrix();
- }
- /**
- * Move down event
- */
- void Java_com_wiagames_pacman_PacmanGLSurfaceView_nativeDown(JNIEnv* env) {
- LOGE("DOWN");
- pacmanDirection = DIR_Y;
- pacmanMoveValue = VALUE_POSITIVE;
- }
- /**
- * Move up event
- */
- void Java_com_wiagames_pacman_PacmanGLSurfaceView_nativeUp(JNIEnv* env) {
- LOGE("UP");
- pacmanDirection = DIR_Y;
- pacmanMoveValue = VALUE_NEGATIVE;
- }
- /**
- * Move down event
- */
- void Java_com_wiagames_pacman_PacmanGLSurfaceView_nativeLeft(JNIEnv* env) {
- LOGE("LEFT");
- pacmanDirection = DIR_X;
- pacmanMoveValue = VALUE_NEGATIVE;
- }
- /**
- * Move down event
- */
- void Java_com_wiagames_pacman_PacmanGLSurfaceView_nativeRight(JNIEnv* env) {
- LOGE("RIGHT");
- pacmanDirection = DIR_X;
- pacmanMoveValue = VALUE_POSITIVE;
- }
- // Move the player
- void movePlayer(float *player, int direction, int value) {
- for (int i = 0; i < 18; i++) {
- if (direction == DIR_Y) {
- if (i != 1 && i != 4 && i != 7 && i != 10 && i != 13 && i != 16) {
- LOGE("Skipping x or z coordinate");
- continue;
- }
- } else if (direction == DIR_X) {
- if (i != 0 && i != 3 && i != 6 && i != 9 && i != 12 && i != 15) {
- LOGE("Skipping y or z coordinate");
- continue;
- }
- }
- player[i] += value;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement