Click here to Skip to main content
15,891,136 members
Articles / Mobile Apps / Android

Terminal Velocity Android

Rate me:
Please Sign up or sign in to vote.
4.47/5 (9 votes)
23 May 2013Apache9 min read 42.7K   976   30  
An android game using NDK JNI and Java.
/*
 * engine.h
 *
 *  Created on: 24-Oct-2012
 *      Author: Praveen
 */


#ifndef ENGINE_H_
#define ENGINE_H_
#ifndef Null
#define Null "\0"
#include "inc.h"
//////////////////////////////////////////class  to call java function//////////////////////////////////////////////////////////
class engine
{
 public:
 static jobject Glgame,Batcher,GuiCam,GameScreen,Set,Aud,Asset;
 static jclass assets,javaBatcher,setting,audio;
 static void drawnumber(JNIEnv *env,int n, int x,int y,int stepx);
 //static const char * const  names[];
 //static const char * const  batch[];

static void setcolor(GLfloat r,GLfloat g,GLfloat b,GLfloat a)
{
	glColor4f(r,g,b,a);
}
////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////Draw Call functions////////////////////////////////////////////


static void beginBatch(JNIEnv *g_env,int i)//const char * path)
{
  	jmethodID  mid= g_env->GetMethodID(javaBatcher,"beignBatch","(I)I");
 	//jstring name = g_env->NewStringUTF(path);
    int l=g_env->CallIntMethod(Batcher, mid,i);
	return ;

}

static  void endBatch(JNIEnv *g_env)
{
	jmethodID mid= g_env->GetMethodID(javaBatcher,"endBatch","()I");
	int l=g_env->CallIntMethod(Batcher, mid);
    return;

}

static void spriteDraw(JNIEnv *g_env,float x,float y,float width,float height,float angle,float pinx,float piny,int index)
{
jmethodID mid= g_env->GetMethodID(javaBatcher,"drawSprite","(FFFFFFFI)I");
//jstring name = g_env->NewStringUTF(path);
int l=g_env->CallIntMethod(Batcher, mid, x, y, width,height,angle,pinx,piny,index);
return;
}


static void scoreDraw(JNIEnv *g_env,float x,float y,float width,float height,float angle,float pinx,float piny,int index)
{
jmethodID mid= g_env->GetMethodID(javaBatcher,"scoreDraw","(FFFFFFFI)I");
//jstring name = g_env->NewStringUTF(path);
int l=g_env->CallIntMethod(Batcher, mid, x, y, width,height,angle,pinx,piny,index);
return;
}




static void textDraw(JNIEnv *g_env,float x, float y, float width, float height,int font, const char * text,float sx,float sy ,float tx,float ty ,const char * path)
 { jmethodID mid= g_env->GetMethodID(javaBatcher,"drawText","(FFFFILjava/lang/String;FFFFLjava/lang/String;)I");
   jstring name = g_env->NewStringUTF(path);
   jstring _text = g_env->NewStringUTF(text);
   int l=g_env->CallIntMethod(Batcher, mid,x,y,width,height,font,_text,sx,sy,tx,ty,name);
  return;}
///////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////


 /////////////////////////////////Audio functions binding///////////////////////////////////////


  static   void playsound(JNIEnv *g_env,const char * path)
  {

  /////	jmethodID  mid= g_env->GetMethodID(audio,"playsound","(Ljava/lang/String;)I");
  ///// 	jstring name = g_env->NewStringUTF(path);
  //// 	int l=g_env->CallIntMethod(Aud, mid,name);
  	return ;
  }

  static   void playsound(JNIEnv *g_env,int i)
  {
	  jmethodID mid= g_env->GetMethodID(javaBatcher,"playsound","(I)I");
	  int l=g_env->CallIntMethod(Batcher, mid,i);
	  return;

  }
//////////////////////////////////////////////////////////////////////////////////////////
///////////////////off or on tells to off on play music 1/0///////////////////////////////
  static  void music(JNIEnv *g_env,int offoron,const char * path)
  {
   	jmethodID  mid= g_env->GetMethodID(javaBatcher,"music","(ILjava/lang/String;)I");
   	jstring name = g_env->NewStringUTF(path);
    int l=g_env->CallIntMethod(Batcher, mid,offoron,name);
  	return ;

  }
///////////////////////////////////////////////////////////////////////////////////////////////
////////////////////Channel tells about adjusting  volume of sound effect or music////////////
     static void adjustVolume(JNIEnv *g_env,jfloat vol,int channel,const char * path)
  {
  	jmethodID mid= g_env->GetMethodID(javaBatcher,"adjustvolume","(FILjava/lang/String;)I");
  	jstring name = g_env->NewStringUTF(path);
  	int l=g_env->CallIntMethod(Batcher, mid,vol,channel,name);
      return;

  }

     static void vibration(JNIEnv *g_env,int t)
  {
  	jmethodID mid= g_env->GetMethodID(audio,"vibration","(I)I");
  	int l=g_env->CallIntMethod(Aud, mid,t);
      return;

  }

///////////////////////////////////////////////////////////////////////////////////////
//////////////perform android tasks like finishing app ,calling any context ,etc///////
///////////////////////////////////////////////////////////////////////////////////////
  static void performtask(JNIEnv *g_env,int t)
  {
  	jmethodID mid= g_env->GetMethodID(audio,"performtask","(I)I");
  	int l=g_env->CallIntMethod(Aud, mid,t);
      return;

  }

///////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////File function bindings/////////////////////////////////////////////

     static void write(JNIEnv *g_env,const char * path)
  {
  	jmethodID mid= g_env->GetMethodID(setting,"write","(Ljava/lang/String;)I");
	jstring name = g_env->NewStringUTF(path);
  	int l=g_env->CallIntMethod(Set, mid,name);
    return;

  }
   static void write(JNIEnv *g_env,int score)
  {
  	jmethodID mid= g_env->GetMethodID(javaBatcher,"write","(I)I");
	//jstring name = g_env->NewStringUTF(path);
  	int l=g_env->CallIntMethod(Batcher, mid,score);
    return;

  }

     static jstring read(JNIEnv *g_env,const char * path)
     {
     	jmethodID mid= g_env->GetMethodID(setting,"read","(FILjava/lang/String;)Ljava/lang/String;");
    	jstring name = g_env->NewStringUTF(path);
     	jstring f=(jstring)(g_env->CallObjectMethod(Set, mid,name));
       return f;

     }

////////////////////////////////////////////////////////////////////////////////////////////////////////////////
     static int  assetsize(JNIEnv *g_env,int i )
     {
     	jmethodID mid= g_env->GetMethodID(assets,"assetsize","(I)I");
     	int  f=g_env->CallIntMethod(Asset,mid,i);
        return f;

     }

     static int  assetdatasize(JNIEnv *g_env,int i,int j)
          {
          	jmethodID mid= g_env->GetMethodID(assets,"assetdatasize","(II)I");
          	int  f=g_env->CallIntMethod(Asset,mid,i,j);
             return f;

          }

     static jstring  assetdataname(JNIEnv *g_env,int i,int j)
               {
               	jmethodID mid= g_env->GetMethodID(assets,"assetdatasize","(II)Ljava/lang/String;");
                jstring f=(jstring)(g_env->CallObjectMethod(Asset,mid,i,j));
                return f;
               }
  /////////////////////////////////////////////////////////////////////////////////////////////////////////////

 };
///////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////
jobject engine::Glgame,engine::Batcher,engine::GuiCam,engine::GameScreen,engine::Set,engine::Aud,engine::Asset;
jclass engine::assets,engine::javaBatcher,engine::setting,engine::audio;
///////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////Native function from java to c/cpp////////////////////////////////////////////
 static long k=0;
//////////////////////////////////Game Class all game related update ,Display done here /////////////////////////
 class Game
 {   static bool musci,soundst;

     static RegionData r1,r2,r3;
 public:

     static ViewManager vm;
     static GameData gd;
     Game(JNIEnv *env);
     virtual ~Game();
     static void quit(JNIEnv * env);
     static void genregion(int i);
     static void State(JNIEnv * env,int state);
     static void Draw(JNIEnv * env,float dt);
     static void guiDraw(JNIEnv * env,float dt);
     static void Update(JNIEnv *env);
     static void  Update(JNIEnv *env,float ax,float ay,float az);
     static bool Update(JNIEnv *env,int key,int keycode);
     static void Update(JNIEnv *env,float tx,float ty,int state,int index);
     static void Init(JNIEnv *env);
     static void drawbg(JNIEnv *env,float dt,int x,int y,int index);
     static void drawgui(JNIEnv *env,float dt,int x,int y);
     static void drawwall(JNIEnv *env,float dt,int x,int y,int object,int type,float angle);
     static void drawitems(JNIEnv *env,float dt,int x,int y,int object,int type,float angle);
     static void drawcurrent(JNIEnv *env,float dt,int x,int y,float sx,float sy,int object,int sprite,float angle);
     static void drawhero(JNIEnv *env,float ,int ,int ,int ,int ,float );
     static void drawPattern(JNIEnv *env,float ,int ,int ,int ,int ,float );
     static void draw2(JNIEnv *env,float dt,int x,int y,int object,int type,float angle);
     static void drawstrike(JNIEnv *env,float dt,int x,int y,int object,int type,float angle);
     static void draw4(JNIEnv *env,float dt,int x,int y,int object,int type,float angle);
     static void draw5(JNIEnv *env,float dt,int x,int y,int object,int type,float angle);
     static jstring itoa(JNIEnv *env,int);
     static void  postaudiodata(bool a, bool b)
		{
    	 gd.musicstate=a;
    	 gd.soundstate=b;
    	 //musci=a;
		 //soundst=b;
		}
 };
 bool Game::musci,Game::soundst;
 GameData Game::gd(Game::musci,Game::soundst);RegionData Game::r1,Game::r2,Game::r3;
 ViewManager Game::vm;

#endif
#endif

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Apache License, Version 2.0


Written By
Chief Technology Officer InductionLabs
India India
Currently I am an independent developer usually develops under brand name Induction games sometimes under Induction labs ,Can say that I am professionally developing apps for more than 4 years .

Some links to my apps in different apps stores are ..


Windows Phone
http://www.windowsphone.com/en-US/store/publishers?publisherId=InductionGames

Android
1. https://play.google.com/store/apps/developer?id=Induction+Labs&hl=en
2.https://play.google.com/store/apps/developer?id=Induction%20Games

Blackberry Store
http://appworld.blackberry.com/webstore/vendor/39848/?lang=en

Flash Games :
http://www.mochigames.com/developer/praveenojha/
*my flash portal is no longer active so the quiz game cant be played .

Perceptual computing phase 1 first prize Winner app (air piano)
http://software.intel.com/sites/campaigns/perceptualshowcase/air-piano.htm

My Blog
http://praveenojha.com

Comments and Discussions