Zoo Photo Attack

Zoo Photo Attack - Project Pilihan

===

9.6 Zoo Photo Attack

9.6.1 Konsep

Pada program ini, cara bekerjanya dengan membandingkan 2 buah photo hewan yang nampak sama namun memiliki perbedaan. Terdapat 3 level yaitu Easy,Medium,Hard dan pada tiap level tersebut memiliki 10 photo dan tiap level memiliki tingkat kesulitan yang berbeda. Pada Tiap-Tiap levelnya terdapat limit waktu yang berbeda serta jumlah perbedaan yang lebih banyak.

9.6.2 Nilai-Nilai Edukasi

 Melatih Kejelian Mata.  Berpikir secara teliti,cepat dan sigap.  Pengetahuan tentang foto-foto hewan yang disajikan.  Otak dapat dilatih untuk menyelesaikan masalah dengan ba-

tas waktu tertentu.

9.6.3 Fitur Yang Digunakan

 Soundtrack yang bervariasi sesuai dengan limit waktu, Jika limit waktu mendekati 0 soundtrack akan memicu player untuk berpikir lebih cepat.

 Memiliki fitur hint, untuk membantu player mencari perbedaan yang ada pada foto yang disajikan.

 Soundtrack Off/Mute , ditujukan pada player yang ingin ber- main dengan tenang.

9.6.4 Tampilan Implementasi

Gambar 9.28 Tampilan Awal Untuk Memulai Game

Gambar 9.29 Tampilan Bentuk Quiz

Gambar 9.3 Tampilan Score

9.6.5 Source Code

Source Code 9.6 Code Guess The Animal

/*Main Activity.java*/

package com.modelloading;

import android.opengl.GLSurfaceView; import android.os.Bundle; import android.app.Activity; import android.content.pm.ActivityInfo; import android.view.Menu; import android.view.View; import android.view.Window; import android.view.WindowManager;

public class MainActivity extends Activity {

/** The OpenGL view */ private GLSurfaceView glSurfaceView;

@Override protected void onCreate(Bundle

savedInstanceState) { super.onCreate(savedInstanceState); //setContentView(R.layout.activity_main);

// requesting to turn the title OFF

requestWindowFeature(Window.FEATURE_NO_TITLE); // making it full screen

getWindow().setFlags(WindowManager.LayoutParams.F

LAG_FULLSCREEN,

WindowManager.LayoutParams.FLAG_FULLSCREEN);

// Initiate the Open GL view and // create an instance with this activity glSurfaceView = new ESSurfaceView(this);

// set our renderer to be the main renderer with // the current activity context //glSurfaceView.setRenderer(new ESRender()); //setContentView(glSurfaceView); setContentView(R.layout.activity_main);

setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATI ON_LANDSCAPE);

/** * Remember to resume the glSurface */

@Override protected void onResume() {

super.onResume(); Music.play(this, R.raw.lagunyahago); glSurfaceView.onResume();

/** * Also pause the glSurface */

@Override protected void onPause() {

super.onPause(); //Music.stop(this); Music.pauseSong(this); glSurfaceView.onPause();

@Override public boolean onCreateOptionsMenu(Menu menu) {

// Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.main, menu); return true; } public void startGame(View view){

glSurfaceView = new ESSurfaceView(this);

// set our renderer to be the main renderer with // the current activity context //glSurfaceView.setRenderer(new ESRender()); setContentView(glSurfaceView);

} public void aboutGame(View view){

setContentView(R.layout.activity_about); setContentView(R.layout.activity_about);

/*Objectball.java*/

package com.modelloading;

import java.nio.ByteBuffer; import java.nio.ByteOrder; import java.nio.FloatBuffer;

import javax.microedition.khronos.opengles.GL10;

import android.content.Context; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.opengl.GLES20; import android.opengl.GLUtils;

public class ObjectBall {

//koor texture private float textCoord_Triagle[]={

0.0f, 0.0f, 0.0f, //

V3

// V2 1.0f, 1.0f, 0.0f, 1.0f, 0.0f, 0.0f,

}; private float vertices[] = { -5f, -5f, 0.0f, //

V1 - first vertex // (x,y,z) -5f, 5f, 0.0f, // V2 5f, 5f, 0.0f, // V3 5f, -5f, 0.0f, // V4 -5f, -5f, 0.0f // V5

private int[] imageFileIDs = { // Image file IDs R.drawable.e1_true, R.drawable.e1_false, R.drawable.joystick, R.drawable.joystick_bg,

R.drawable.heart,R.drawable.e2_true, R.drawable.e2_false,R.drawable.e3_true, R.drawable.e3_false,

R.drawable.e4_true, R.drawable.e4_false,R.drawable.e5_true,

R.drawable.e5_false,R.drawable.gameover};

private float vertices_circle[]={0.0f,0.0f,0.0f}; private float verti-

ces_circle_color[]={0.0f,0.0f,0.0f,0.5f}; private float textCoord[]; private float vertices_circle1[];

int[] textures_indek = new int[1];

private int batas_sudut=360; float jari_jari; float a,b; float x,y; float step=3.0f,step_line=0.2f; float x1,y1; float x2,y2; float teta; private int loop,loop_color;

public ObjectBall() {

// ============ start to generate stetch texture coordinat ========================== //Inisialisasi jari_jari=0.5f;

// Titik Pusat

a = 0.5f; b = 0.5f ; //x=a+jari_jari; y=b; teta = 0;

// generate stretch texture coordinat teta=0; textCoord = new float[batas_sudut * 3]; for (int ii = 0; ii < batas_sudut * 3; ii

+= 3) { // membentuk textCoord textCoord[ii] =

(jari_jari*((float) Math.cos(-teta)))+a; textCoord[ii + 1] = (jari_jari*((float) Math.sin(-teta)))+b; textCoord[ii + 2] = 0.0f;

teta += Math.PI / 90;

// ============ start to generate verti- ces to circle (Cara 1) ========================== //Inisialisasi jari_jari=50.0f;

// Titik Pusat

a = 50.0f; b = 50.0f ;

vertices_circle1 = new float[batas_sudut * 3]; vertices_circle1 = new float[batas_sudut * 3];

(jari_jari*((float) Math.cos(teta)))+a; vertices_circle1[ii + 1] = (jari_jari*((float) Math.sin(teta)))+b; vertices_circle1[ii + 2] = 0.0f;

teta += Math.PI / 90;

// ============ start to generate verti- ces to circle (Cara 2) ========================== //Inisialisasi jari_jari=50.0f;

// Titik Pusat

a = 50.0f; b = 50.0f ; x=a+jari_jari; y=b;

loop=0; loop_color=0; vertices_circle=new

float[(int)(3*batas_sudut/step)*3]; vertices_circle_color=new float[(int)(3*batas_sudut/step)*4]; for(teta=0;teta<=2*batas_sudut;teta+=step){ vertices_circle[loop] = (float) ((x- a)*Math.cos((teta/180)*(22/7)) - ((y- b)*Math.sin((teta/180)*(22/7))) + a);

vertices_circle[loop+1] = (float) ((x- a)*Math.sin((teta/180)*(22/7)) - ((y- b)*Math.cos((teta/180)*(22/7))) + b);

vertices_circle[loop+2]=0; loop+=3;

//mengenerate warna untuk setiap vertex //vertices_circle_color[loop_color]=(float) ((x-

a)*Math.cos((teta/180)*(22/7)) - ((y- b)*Math.sin((teta/180)*(22/7))) + a);

//vertices_circle_color[loop_color+1]=(float) ((x-a)*Math.sin((teta/180)*(22/7)) - ((y- b)*Math.cos((teta/180)*(22/7))) + b);

vertices_circle_color[loop_color]=(float) (Math.cos((teta/180)*(22/7)) );

vertices_circle_color[loop_color+1]=(float) (Math.sin((teta/180)*(22/7)));

vertices_circle_color[loop_color+2]=0.5f; vertices_circle_color[loop_color+3]=0.5f; loop_color+=4;

} // ============= end for generate vertices to circle ====================

// Point to our vertex buffer, return buffer holding the vertices public static FloatBuffer makeFloatBuffer(float[] arr){ ByteBuffer bb = ByteBuff- er.allocateDirect(arr.length * 4); bb.order(ByteOrder.nativeOrder()); FloatBuffer fb = bb.asFloatBuffer(); fb.put(arr); fb.position(0); return fb;

// Setup index-array buffer. Indices in byte. public static ByteBuffer makeByteBuffer(byte[]

arr){ ByteBuffer bb = ByteBuff- er.allocateDirect(arr.length); bb.put(arr); bb.position(0); return bb;

/** The draw method for the primitive object with the GL context */ public void draw_circle(GL10 gl) {

gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);

gl.glEnableClientState(GL10.GL_COLOR_ARRAY);

// set the colour for the object circle //gl.glColor4f(0.0f, 0.0f, 1.0f, 1.0f);

//create VBO from buffer with glBuffer- Data() gl.glVertexPointer(3, GL10.GL_FLOAT, 0, make- FloatBuffer(vertices_circle));

//memetakan warna untuk setiap vertex gl.glColorPointer(4, GL10.GL_FLOAT, 0, make-

FloatBuffer(vertices_circle_color));

//draw circle as filled shape //gl.glDrawArrays(GL10.GL_TRIANGLE_FAN, 1,

(int) ((int) 2*batas_sudut/step));

//draw circle contours //gl.glDrawArrays(GL10.GL_LINES, 1, (int)

((int) 2*batas_sudut/step)); // membuat garis putus- putus pada tepi lingkaran

//gl.glDrawArrays(GL10.GL_LINES, 1, (int) ((int) 2*batas_sudut/step)); gl.glDrawArrays(GL10.GL_LINE_STRIP, 1, (int) ((int) 2*batas_sudut/step)); //gl.glDrawArrays(GL10.GL_POINTS, 1, (int)

((int) 2*batas_sudut/step));

//Disable the client state before leaving

gl.glDisableClientState(GL10.GL_VERTEX_ARRAY);

gl.glDisableClientState(GL10.GL_COLOR_ARRAY); }

public void draw_circle_color(GL10 gl) {

gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);

//gl.glEnableClientState(GL10.GL_COLOR_ARRAY);

// set the colour edge for the object circle //gl.glColor4f(0.0f, 0.0f, 1.0f, 1.0f);

//create VBO from buffer with glBuffer- Data() gl.glVertexPointer(3, GL10.GL_FLOAT, 0, make- FloatBuffer(vertices_circle1));

//memetakan warna untuk setiap vertex //gl.glColorPointer(4, GL10.GL_FLOAT, 0,

makeFloatBuffer(vertices_circle_color));

//menempelkan tekstur ke objek gl.glEnable(GL10.GL_TEXTURE_2D);

gl.glEnable(GL10.GL_BLEND); gl.glBlendFunc(GL10.GL_SRC_ALPHA,

GL10.GL_ONE_MINUS_SRC_ALPHA);

gl.glBindTexture(GL10.GL_TEXTURE_2D, tex- tures_indek[0]); // 4 //gl.glTexCoordPointer(3, GL10.GL_FLOAT,

1, makeFloatBuffer(vertices_circle)); // 5 gl.glTexCoordPointer(3, GL10.GL_FLOAT, 0, makeFloatBuffer(textCoord)); // 5

gl.glEnableClientState(GL10.GL_TEXTURE_COORD_ARRA Y);

//GL11ExtensionPack gl_ = (GL11ExtensionPack) gl; //GL11 gl11 = (GL11) gl; //gl.glBindTexture(GL10.GL_TEXTURE_2D, tex-

tures_indek[0]);

// Set the face rotation //gl.glFrontFace(GL10.GL_CW);

//draw circle as filled shape //gl.glDrawArrays(GL10.GL_TRIANGLE_FAN, 0,

(int) ((int) 2*batas_sudut/step)); //gl.glDrawArrays(GL10.GL_TRIANGLE_FAN, 0, (int) ((int) 2*batas_sudut/step)); gl.glDrawArrays(GL10.GL_TRIANGLE_FAN, 0, ba- tas_sudut); //gl.glDrawArrays(GL10.GL_LINE_STRIP, 0, (int) ((int) 2*batas_sudut/step)); //gl.glDrawArrays(GL10.GL_TRIANGLE_FAN, 1, 120);

//Log.i("Nilai 2*batas_sudut/step : ", ""+2*batas_sudut/step);

//gl.glDrawArrays(GL10.GL_LINE_STRIP, 1, (int) ((int) 2*batas_sudut/step)); //gl.glDrawElements(GL10.GL_TRIANGLES, (int) ((int) 2*batas_sudut/step), // GL10.GL_UNSIGNED_SHORT, makeFloat- Buffer(vertices_circle));

//draw circle contours //gl.glDrawArrays(GL10.GL_LINES, 1, (int)

((int) 2*batas_sudut/step)); // membuat garis putus- putus pada tepi lingkaran

//gl.glDrawArrays(GL10.GL_LINE_STRIP, 1, (int) ((int) 2*batas_sudut/step)); //gl.glDrawArrays(GL10.GL_POINTS, 1, (int) ((int) 2*batas_sudut/step));

//Disable the client state before leaving

gl.glDisableClientState(GL10.GL_VERTEX_ARRAY);

//gl.glDisableClientState(GL10.GL_COLOR_ARRAY);

gl.glDisable( GL10.GL_BLEND );

// Disable Alpha Blend

gl.glDisable( GL10.GL_TEXTURE_2D ); // Disable Texture Mapping }

public void draw_circle_color(GL10 gl,float red_in, float green_in,float blue_in, float alpha_in) {

gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);

//gl.glEnableClientState(GL10.GL_COLOR_ARRAY);

// set the colour edge for the object circle gl.glColor4f(red_in, green_in, blue_in, 0.33f); //gl.glColor4f(red_in, green_in, blue_in, alpha_in);

//create VBO from buffer with glBuffer- Data() gl.glVertexPointer(3, GL10.GL_FLOAT, 0, make-

FloatBuffer(vertices_circle1));

//memetakan warna untuk setiap vertex //gl.glColorPointer(4, GL10.GL_FLOAT, 0,

makeFloatBuffer(vertices_circle_color));

//menempelkan tekstur ke objek //gl.glEnable(GL10.GL_TEXTURE_2D);

//gl.glEnable(GL10.GL_BLEND); //gl.glBlendFunc(GL10.GL_SRC_ALPHA,

GL10.GL_ONE_MINUS_SRC_ALPHA);

//gl.glBindTexture(GL10.GL_TEXTURE_2D, textures_indek[0]); // 4 //gl.glTexCoordPointer(3, GL10.GL_FLOAT,

1, makeFloatBuffer(vertices_circle)); // 5 //gl.glTexCoordPointer(3, GL10.GL_FLOAT,

0, makeFloatBuffer(textCoord)); // 5

//gl.glEnableClientState(GL10.GL_TEXTURE_COORD_AR RAY);

//GL11ExtensionPack gl_ = (GL11ExtensionPack) gl; //GL11 gl11 = (GL11) gl; //gl.glBindTexture(GL10.GL_TEXTURE_2D, tex-

tures_indek[0]);

// Set the face rotation //gl.glFrontFace(GL10.GL_CW);

gl.glEnable(GL10.GL_BLEND); gl.glBlendFunc(GL10.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA);

//draw circle as filled shape //gl.glDrawArrays(GL10.GL_TRIANGLE_FAN, 0,

(int) ((int) 2*batas_sudut/step));

gl.glDrawArrays(GL10.GL_TRIANGLE_FAN, 0, batas_sudut); //gl.glDrawArrays(GL10.GL_TRIANGLE_FAN, 0, (int) ((int) 2*batas_sudut/step)); //gl.glDrawArrays(GL10.GL_TRIANGLE_FAN, 0, batas_sudut); //gl.glDrawArrays(GL10.GL_LINE_STRIP, 0, (int) ((int) 2*batas_sudut/step)); //gl.glDrawArrays(GL10.GL_TRIANGLE_FAN, 1, 120);

//Log.i("Nilai 2*batas_sudut/step : ", ""+2*batas_sudut/step);

//gl.glDrawArrays(GL10.GL_LINE_STRIP, 1, (int) ((int) 2*batas_sudut/step));

//gl.glDrawElements(GL10.GL_TRIANGLES, (int) ((int) 2*batas_sudut/step), // GL10.GL_UNSIGNED_SHORT, makeFloat- Buffer(vertices_circle));

//draw circle contours //gl.glDrawArrays(GL10.GL_LINES, 1, (int)

((int) 2*batas_sudut/step)); // membuat garis putus- putus pada tepi lingkaran

//gl.glDrawArrays(GL10.GL_LINE_STRIP, 1, (int) ((int) 2*batas_sudut/step)); //gl.glDrawArrays(GL10.GL_POINTS, 1, (int) ((int) 2*batas_sudut/step));

//Disable the client state before leaving

gl.glDisableClientState(GL10.GL_VERTEX_ARRAY);

//gl.glDisableClientState(GL10.GL_COLOR_ARRAY);

gl.glDisable( GL10.GL_BLEND );

// Disable Alpha Blend

//gl.glDisable( GL10.GL_TEXTURE_2D ); // Disable Texture Mapping }

public void draw_segitiga(GL10 gl) { gl.glFrontFace(GL10.GL_CCW); // Front face in counter-clockwise

gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);

//gl.glEnableClientState(GL10.GL_COLOR_ARRAY);

// set the colour for the triangle //gl.glColor4f(1.0f, 0.0f, 0.0f, 1.0f);

gl.glVertexPointer(3, GL10.GL_FLOAT, 0, makeFloatBuffer(new float [] {

1.0f, 1.0f, 0.0f, // V3 0.0f, 1.0f, 0.0f, // V2 0.5f, 0.0f, 0.0f,

// V1 - first vertex (x,y,z) }));

// Draw the vertices as triangle //gl.glColorPointer(4, GL10.GL_FLOAT, 0,

makeFloatBuffer(vertices_color));

//menempelkan tekstur ke objek //gl.glEnable(GL10.GL_TEXTURE_2D);

gl.glEnable(GL10.GL_BLEND); gl.glBlendFunc(GL10.GL_SRC_ALPHA,

GL10.GL_ONE_MINUS_SRC_ALPHA);

//gl.glEnableClientState(GL10.GL_TEXTURE_COORD_AR RAY);

gl.glDrawArrays(GLES20.GL_TRIANGLE_STRIP,

//Disable the client state before leaving

gl.glDisableClientState(GL10.GL_VERTEX_ARRAY);

//gl.glDisableClientState(GL10.GL_COLOR_ARRAY);

gl.glDisable( GL10.GL_BLEND );

// Disable Alpha Blend

public void draw_segitiga_texture(GL10 gl) {

gl.glFrontFace(GL10.GL_CCW); // Front face in counter-clockwise

gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);

//gl.glEnableClientState(GL10.GL_COLOR_ARRAY);

// set the colour for the triangle (menghilangkan effect dari warna objek sebelumnya) gl.glColor4f(1.0f, 1.0f, 1.0f, 1.0f);

gl.glVertexPointer(4, GL10.GL_FLOAT, 0, makeFloatBuffer(new float [] { 0.0f, 0.0f, 0.0f, // V3 // V2 1.0f, 0.0f, 0.0f, 1.0f, 1.0f, 0.0f, 0.0f, 0.1f, 0.0f,

// Draw the vertices as triangle //gl.glColorPointer(4, GL10.GL_FLOAT, 0,

makeFloatBuffer(vertices_color));

//menempelkan tekstur ke objek gl.glEnable(GL10.GL_TEXTURE_2D);

gl.glEnable(GL10.GL_BLEND); gl.glBlendFunc(GL10.GL_SRC_ALPHA,

GL10.GL_ONE_MINUS_SRC_ALPHA);

gl.glBindTexture(GL10.GL_TEXTURE_2D, tex- tures_indek[0]); // //gl.glTexCoordPointer(3, GL10.GL_FLOAT,

0, makeFloatBuffer(textCoord_Triagle)); // 0, makeFloatBuffer(textCoord_Triagle)); //

gl.glDrawArrays(GLES20.GL_POINTS, 0, 4);

//Disable the client state before leaving

gl.glDisableClientState(GL10.GL_VERTEX_ARRAY);

//gl.glDisableClientState(GL10.GL_COLOR_ARRAY);

gl.glDisable( GL10.GL_BLEND );

// Disable Alpha Blend

gl.glDisable( GL10.GL_TEXTURE_2D ); // Disable Texture Mapping

} public void draw_kotak(GL10 gl) {

gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);

gl.glEnableClientState(GL10.GL_COLOR_ARRAY);

// Point to our vertex buffer gl.glVertexPointer(3, GL10.GL_FLOAT, 0,

makeFloatBuffer(vertices));

// Draw the vertices as square

//gl.glColorPointer(4, GL10.GL_FLOAT, 0, makeFloatBuffer(vertices_color)); gl.glDrawArrays(GL10.GL_TRIANGLES, 0, 3);

//gl.glColorPointer(4, GL10.GL_FLOAT, 0, makeFloatBuffer(vertices_color)); gl.glDrawArrays(GL10.GL_TRIANGLES, 2, 3);

// Disable the client state before leav- ing

gl.glDisableClientState(GL10.GL_VERTEX_ARRAY);

gl.glDisableClientState(GL10.GL_COLOR_ARRAY);

gl.glEnable(GL10.GL_TEXTURE_2D);

gl.glEnable(GL10.GL_BLEND); gl.glBlendFunc(GL10.GL_SRC_ALPHA,

GL10.GL_ONE_MINUS_SRC_ALPHA);

gl.glBindTexture(GL10.GL_TEXTURE_2D, tex- tures_indek[0]); // 4 //gl.glTexCoordPointer(3, GL10.GL_FLOAT, 1, makeFloatBuffer(vertices_circle)); // 5

gl.glTexCoordPointer(3, GL10.GL_FLOAT, 0, makeFloatBuffer(textCoord)); // 5 gl.glTexCoordPointer(3, GL10.GL_FLOAT, 0, makeFloatBuffer(textCoord)); // 5

public void loadBallTexture(GL10 gl, Context con- text) {

// Bitmap bitmap = BitmapFacto-

ry.decodeResource(context.getResources(), // resource);

Bitmap bitmap = BitmapFacto-

ry.decodeStream(context.getResources()

.openRawResource(R.drawable.nature));

gl.glGenTextures(1, textures_indek, 0); gl.glBindTexture(GL10.GL_TEXTURE_2D, tex-

tures_indek[0]);

/*gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MIN_FILTER, GL10.GL_LINEAR); gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MAG_FILTER, GL10.GL_LINEAR); */

//gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_S, GL10.GL_CLAMP_TO_EDGE ); //gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_T, GL10.GL_CLAMP_TO_EDGE );

gl.glTexParameterf(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_NEAREST); gl.glTexParameterf(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_NEAREST);

//gl.glTexParameterf(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_WRAP_S, GLES20.GL_REPEAT );

//gl.glTexParameterf(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_WRAP_T, GLES20.GL_REPEAT );

///gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MIN_FILTER, //GL10.GL_NEAREST); //gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MAG_FILTER, //GL10.GL_LINEAR);

GLUtils.texImage2D(GLES20.GL_TEXTURE_2D,

0, bitmap, 0);

bitmap.recycle(); }

public void loadBallTexture(GL10 gl, Context con- public void loadBallTexture(GL10 gl, Context con-

/*Bitmap bitmap = BitmapFacto- ry.decodeStream(context.getResources()

.openRawResource(R.drawable.nature));*/

Bitmap bitmap = BitmapFacto- ry.decodeStream(context.getResources()

.openRawResource(imageFileIDs[index_Texture])); gl.glGenTextures(1, textures_indek, 0); gl.glBindTexture(GL10.GL_TEXTURE_2D, tex-

tures_indek[0]);

/*gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MIN_FILTER, GL10.GL_LINEAR); gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MAG_FILTER, GL10.GL_LINEAR); */

//gl.glTexParameterf(GL10.GL_TEXTURE_2D,

GL10.GL_TEXTURE_WRAP_S, GL10.GL_CLAMP_TO_EDGE );

//gl.glTexParameterf(GL10.GL_TEXTURE_2D,

GL10.GL_TEXTURE_WRAP_T, GL10.GL_CLAMP_TO_EDGE );

gl.glTexParameterf(GLES20.GL_TEXTURE_2D,

GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_NEAREST);

gl.glTexParameterf(GLES20.GL_TEXTURE_2D,

GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_NEAREST);

//gl.glTexParameterf(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_WRAP_S, GLES20.GL_REPEAT );

//gl.glTexParameterf(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_WRAP_T, GLES20.GL_REPEAT );

///gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MIN_FILTER, //GL10.GL_NEAREST); //gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MAG_FILTER, //GL10.GL_LINEAR);

GLUtils.texImage2D(GLES20.GL_TEXTURE_2D,

0, bitmap, 0); bitmap.recycle(); } }

/*SplashScreen.java*/

package com.modelloading;

import android.app.Activity; import android.content.Intent; import android.content.pm.ActivityInfo; import android.os.Bundle; import android.os.Handler; import android.view.Window; import android.view.WindowManager;

public class SplashScreen extends Activity {

// Splash screen timer private static int SPLASH_TIME_OUT = 300;

@Override protected void onCreate(Bundle savedInstanceS-

tate) {

super.onCreate(savedInstanceState);

// requesting to turn the title OFF requestWindowFea- ture(Window.FEATURE_NO_TITLE); // making it full screen getWin- dow().setFlags(WindowManager.LayoutParams.FLAG_FULLSC REEN,

WindowManag- er.LayoutParams.FLAG_FULLSCREEN);

setRequestedOrienta- tion(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);

setContentView(R.layout.activity_splash);

new Handler().postDelayed(new Runnable() {

/* * Showing splash screen with a timer. This will be useful when you * want to show case your app logo / com- pany */

@Override public void run() {

// This method will be executed once the timer is over // Start your app main activity Intent i = new In-

tent(SplashScreen.this, MainActivity.class );

i.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);

startActivity(i);

// close this activity finish();

} }, SPLASH_TIME_OUT); }

/*ESSurfaceView.java*/

package com.modelloading;

import android.content.Context; import android.graphics.Point; import android.opengl.GLSurfaceView; import android.util.Log; import android.view.KeyEvent; import android.view.MotionEvent;

/** * A view container where OpenGL ES graphics can be drawn on screen. This view * can also be used to capture touch events, such as

a user interacting with * drawn objects. */

public class ESSurfaceView extends GLSurfaceView {

private final ESRender esRender; private float previousX; private float previousY; private int stage; int ldif1x,ldif1y,ldif2x,ldif2y,ldif3x,ldif3y; /*

* public float initx_stick = 425; public float inity_stick = 267; public * Point _touchingPoint = new Point(425,267); public Point _pointerPosition * = new Point(220,150); */

public float initx_stick = 1013; public float inity_stick = 500; public Point _touchingPoint = new Point(1013,

500); public Point _pointerPosition = new Point(220,150); private Boolean _dragging = false; private int flag_first=0;

private float mypointer_awal_x=0; private float mypointer_awal_y=0; private float mypointer_awal_x=0; private float mypointer_awal_y=0;

// Set the Renderer for drawing on the GLSurfaceView esRender = new ESRender(context); setRenderer(esRender);

// To enable keypad this.setFocusable(true); this.requestFocus();

// To enable touch mode this.setFocusableInTouchMode(true);

// Render the view only when there is a change in the drawing data // merender hanya ketika ada perubahan/ event // setRender- Mode(GLSurfaceView.RENDERMODE_WHEN_DIRTY); }

@Override public boolean onTouchEvent(MotionEvent v) {

// MotionEvent reports input details from the touch screen // and other input controls. In this case, we are only // interested in events where the touch position changed.

/* * initx_stick = esRen- der.getWidthObject()-esRender.getRadius(); * inity_stick = 0.0f; _touchingPoint.x = (int) initx_stick; * _touchingPoint.y= (int) inity_stick; * * _pointerPosition.x = (int) in-

itx_stick; _pointerPosition.y= (int) * inity_stick; */

update(v);

float currentX = v.getX(); float currentY = v.getY(); float deltaX, deltaY;

// float scalingFactor = 0.50f / ((esRen- der.xMax > esRender.yMax) ? // esRender.yMax // : esRender.xMax);

switch (v.getAction()) { case MotionEvent.ACTION_DOWN:

Log.v("Test Action Down", "action Log.v("Test Action Down", "action

esRen- der.setspeedX(esRender.getspeedX() + deltaX / 100); esRen- der.setspeedY(esRender.getspeedY() + deltaY / 100);

requestRender();

// Save current x, y previousX = currentX; previousY = currentY; return true; // Event handled // break;

private MotionEvent lastEvent;

public void update(MotionEvent event) {

//initx_stick = 1066.0f- 1.5f*esRender.getRadius(); //inity_stick =0.5f*esRender.getRadius();

if (event == null && lastEvent == null) { return; } else if (event == null && lastEvent != null) { event = lastEvent; } else { lastEvent = event; } // drag drop if (event.getAction() == Motion-

Event.ACTION_DOWN) { _dragging = true; flag_first=0;

} else if (event.getAction() == Motion- Event.ACTION_UP) { _dragging = false; }

// penanda untuk menyimpan koordinat yang pertama kali diklik

if (_dragging) {

// get the pos _touchingPoint.x = (int)

event.getX(); _touchingPoint.y = (int) event.getY();

esRen- der.setX_touch(_touchingPoint.x); esRen- esRen- der.setX_touch(_touchingPoint.x); esRen-

esRender.setJarak_center((float) ((Math.pow(_touchingPoint.x-(esRender.getMywidth()- 2*esRender.getRadius()), 2))+

(Math.pow(esRender.getMyheight()- _touchingPoint.y-2*esRender.getRadius(), 2))));

if(esRender.getJarak_center()<=Math.pow(25, 2)){ esRen- der.setX_graf(esRender.getX_graf()-10); } else { esRen- der.setY_graf(esRender.getY_graf()-10); }

if(((Math.pow(_touchingPoint.x- esRender.ldif1x(), 2)+Math.pow(_touchingPoint.y- esRender.ldif1y(), 2))<Math.pow(25, 2))||

((Math.pow(_touchingPoint.x-esRender.ldif2x(), 2)+Math.pow(_touchingPoint.y-esRender.ldif2y(), 2))

((Math.pow(_touchingPoint.x-esRender.ldif3x(), 2)+Math.pow(_touchingPoint.y-esRender.ldif3y(), 2))

//dif1 if ((Math.pow(_touchingPoint.x-

esRender.ldif1x(), 2)+Math.pow(_touchingPoint.y- esRender.ldif1y(), 2))<Math.pow(25, 2)) {

Mu-

sic.playOnce(esRender.context, R.raw.alarm); esRender.setdif1(true);

//esRender.setrBallX(esRender.getrBallX()-5.0f); } //dif2 if ((Math.pow(_touchingPoint.x-

esRender.ldif2x(), 2)+Math.pow(_touchingPoint.y- esRender.ldif2y(), 2))<Math.pow(25, 2)) {

Mu-

sic.playOnce(esRender.context, R.raw.alarm); esRender.setdif2(true);

//esRender.setrBallX(esRender.getrBallX()-5.0f); } //dif3 if ((Math.pow(_touchingPoint.x-

esRender.ldif3x(), 2)+Math.pow(_touchingPoint.y- esRender.ldif3y(), 2))<Math.pow(25, 2)) {

Mu-

sic.playOnce(esRender.context, R.raw.alarm); esRender.setdif3(true);

//esRender.setrBallX(esRender.getrBallX()-5.0f); } } else if(esRender.getlife()==0){

esRender.setlose(true); if((Math.pow(_touchingPoint.x-

esRender.ldif1x(), 2)+Math.pow(_touchingPoint.y- esRender.ldif1y(), 2))<Math.pow(25, 2)){

} else{

esRender.reset(); }

} else {

Music.playOnce(esRender.context, R.raw.aw); esRender.setlife();

} if(esRender.getlife()==0){

esRender.setlose(true); if((Math.pow(_touchingPoint.x-

ldif1x, 2)+Math.pow(_touchingPoint.y-ldif1y, 2))<Math.pow(25, 2)){

esRender.reset(); }

} // bound to a box if (_touchingPoint.x < 400) {

_touchingPoint.x = 400; } if (_touchingPoint.x > 450) {

_touchingPoint.x = 450; } if (_touchingPoint.y < 240) {

_touchingPoint.y = 240; } if (_touchingPoint.y > 290) {

_touchingPoint.y = 290; }

// get the angle double angle =

Math.atan2(_touchingPoint.y - inity_stick, _touchingPoint.x - initx_stick) / (Math.PI / 180);

// Move the beetle in proportion to how far // the joystick is dragged from its center _pointerPosition.y += Math.sin(angle * (Math.PI / 180)) * (_touchingPoint.x / 70);

_pointerPosition.x += Math.cos(angle * (Math.PI / 180)) * (_touchingPoint.x / 70);

//esRender.setX_anim_stick(_touchingPoint.x);

//esRender.setY_anim_stick(_touchingPoint.y);

// make the pointer go thru if (_pointerPosition.x > 480) {

_pointerPosition.x = 0; }

if (_pointerPosition.x < 0) { _pointerPosition.x = 480; }

if (_pointerPosition.y > 320) { _pointerPosition.y = 0; } if (_pointerPosition.y < 0) {

_pointerPosition.y = 320; }

} else if (!_dragging) {

flag_first=0;

// Snap back to center when the joystick is released _touchingPoint.x = (int) in- itx_stick; _touchingPoint.y = (int) ini- ty_stick;

esRender.setX_anim_stick(0.0f); esRender.setY_anim_stick(0.0f);

// shaft.alpha = 0; } }

// Key-up event handler @Override public boolean onKeyUp(int keyCode, KeyEvent

event) { switch (keyCode) { case KeyEvent.KEYCODE_A: // mengurangi

kecepatan object if ((esRender.getspeedX() - 0.05f > 0)) { esRen- der.setspeedX(esRender.getspeedX() - 0.05f); } if ((esRender.getspeedX() - 0.05f

>= 0)) { esRen- der.setspeedY(esRender.getspeedY() - 0.05f); } if ((esRender.getspeedY() - 0.05f

< 0)) { esRender.setspeedY(0.0f); } Log.v("Test Action KEYCODE_A",

"action working"); break; case KeyEvent.KEYCODE_T: // up

if (esRender.getNavigate() == 0 && esRender.goForward()) esRen- der.setPositionRow(esRender.getPositionRow() - 1); else if (esRender.getNavigate() ==

1 && esRender.goForward()) esRen- der.setPositionCol(esRender.getPositionCol() + 1); else if (esRender.getNavigate() ==

2 && esRender.goForward()) esRen- der.setPositionRow(esRender.getPositionRow() + 1); else if (esRender.getNavigate() ==

3 && esRender.goForward()) esRen- der.setPositionCol(esRender.getPositionCol() - 1); Log.v("Test Action KEYCODE_T", "action working");

esRen- der.setX_player((esRender.getPositionCol() * esRender .getWidthObject()) + (esRender.getWidthObject() / 2)); esRen- der.setY_player(((esRender.getNumberRow() - esRen- der.getPositionRow() - 1) * esRender

.getWidthObject()) + (esRender.getWidthObject() / 2)); break; case KeyEvent.KEYCODE_G: Log.v("Test Action KEYCODE_G", "action working"); break; case KeyEvent.KEYCODE_H: // right esRen- der.setNavigate(esRender.getNavigate() + 1); Log.v("Test Action KEYCODE_H", "action working"); break; case KeyEvent.KEYCODE_F: // left esRen- der.setNavigate(esRender.getNavigate() - 1);

Log.v("Test Action KEYCODE_F", "action working");

break;

if (esRender.getNavigate() < 0) esRender.setNavigate(3); esRen- der.setNavigate(esRender.getNavigate() % 4);

return true; // Event handled } }

/*ESRender.java*/

package com.modelloading;

import java.util.Random;

import javax.microedition.khronos.egl.EGLConfig; import javax.microedition.khronos.opengles.GL10;

import android.content.Context; import android.content.Intent; import android.opengl.GLSurfaceView; import android.opengl.GLSurfaceView.Renderer; import android.util.Log;

public class ESRender implements Renderer { private ESText glText; private GLSurfaceView glSurfaceView2; private PrimitivesObject primob1; private PrimitivesObject primob3; private ObjectBall objectball2; //private ObjectBall objectball3; private ObjectBall satu; private ObjectBall dua; private ObjectBall tiga; private ObjectBall lifer; private ObjectBall primob; private ObjectBall gambara; private ObjectBall gambarb; private ObjectBall loser; private TextureKubus kotak; private TransObject transobject; private final MySphere mEarth,mEarth2,mEarth3;

float scaleX = 25.0f; public float getScaleX() {

return scaleX; return scaleX;

float scaleY = 25.0f; public float getScaleY() {

return scaleY; }

public void setScaleY(float scaleY) { this.scaleY = scaleY; }

float scaleZ = 25.0f; int life = 3;

public float getScaleZ() { return scaleZ; }

public void setScaleZ(float scaleZ) { this.scaleZ = scaleZ; }

Context context; int Run_Mode=0; float CurrentAngle = 0.0f;

// Angle in degrees float CurrentAngle2 = 0.0f;

// Angle in degrees float AnimateStep = 2.0f;

// Rotation step per update float AnimateStep2 = 0.2f;

// Rotation step per update float ScaleStep = 1.0f;

float CurrentScale =1.0f;

float radius = 50.0f; // Ball's radius float x = radius; // Ball's center (x,y) float y = radius; float speedX = 5f; // Ball's speed (x,y) float speedY = 3f;

float rBallX = 0.0f; float rBallZ= 0.0f; int dif1x,dif1y,dif2x,dif2y,dif3x,dif3y; int ldif1x,ldif1y,ldif2x,ldif2y,ldif3x,ldif3y; int score; public float getrBallZ() {

return rBallZ; } return rBallZ; }

public float getrBallX() { return rBallX; }

public void setrBallX(float rBallX) { this.rBallX = rBallX; }

float rBallY = 0.0f;

public float getrBallY() { return rBallY; }

public void setrBallY(float rBallY) { this.rBallY = rBallY; }

int xMin, xMax, yMin, yMax;

private int mywidth = 0; private int myheight = 0; private int jumlah_pantulan=0;

private float x_player = 0; private float y_player = 0; private float x_player_end = 0; private float y_player_end = 0; private int Navigate = 0; private int positionRow = 0; private int positionCol = 0; private int hori[][] = new int[1000][1000]; private int verti[][] = new int[1000][1000]; private int numberCol =0; private int numberRow =0; private float WidthObject =0;

private float x_anim_stick = 0; private float y_anim_stick = 0;

private float x_touch = 0; private float y_touch = 0;

private float x_pointer = 0; private float y_pointer = 0;

private float x_pointer_awal = 0; private float y_pointer_awal = 0;

private float x_lebar_layar = 0; private float y_tinggi_layar = 0; private float x_lebar_layar = 0; private float y_tinggi_layar = 0;

private float jarak_center = 0;

private String arah_joystick="";

float ballX = 550.0f; public float getBallX() {

return ballX; }

public void setBallX(float ballX) { this.ballX = ballX; }

float ballY = 300.0f;

public float getBallY() { return ballY; }

public void setBallY(float ballY) { this.ballY = ballY; }

boolean get_size_screen=true;

private float x_graf=0; public float getX_graf() {

return x_graf; }

public void setX_graf(float x_graf) { this.x_graf = x_graf; }

private float y_graf=0;

public float getY_graf() { return y_graf; }

public void setY_graf(float y_graf) { this.y_graf = y_graf; }

float black[] = new float[] { 0.0f, 0.0f, 0.0f, 1.0f }; float yellow[] = new float[] { 1.0f, 1.0f, 0.0f, 1.0f }; float cyan[] = new float[] { 0.0f, 1.0f, 1.0f, 1.0f }; float white[] = new float[] { 1.0f, 1.0f, 1.0f, 1.0f }; float black[] = new float[] { 0.0f, 0.0f, 0.0f, 1.0f }; float yellow[] = new float[] { 1.0f, 1.0f, 0.0f, 1.0f }; float cyan[] = new float[] { 0.0f, 1.0f, 1.0f, 1.0f }; float white[] = new float[] { 1.0f, 1.0f, 1.0f, 1.0f };

float diffuseMaterial2[] = new float[] { 0.5f, 0.5f, 0.5f, 1.0f }; // set cahaya warna ungu float lightAmbient[] = new float[] { 0.2f, 0.3f, 0.6f, 1.0f };

float mat_specular[] = { 1.0f, 1.0f, 1.0f, 1.0f }; float light_position[] = { 0.0f, 0.0f, 1.0f, 0.0f };

float light_position2[] = { 0.0f, 0.0f, 1.0f, 0.0f }; boolean dif1=false; boolean dif2=false; boolean dif3=false; int stage=1; boolean lose=false; boolean finish=false; /** Constructor to set the handed over context */ public ESRender(Context context) {

// super(); this.context = context; this.primob1 = new PrimitivesObject(); this.primob3 = new PrimitivesObject(); this.objectball2 = new ObjectBall(); this.gambara = new ObjectBall(); this.gambarb = new ObjectBall(); this.lifer = new ObjectBall(); this.loser = new ObjectBall();

//this.objectball3 = new ObjectBall(); this.satu = new ObjectBall(); this.dua = new ObjectBall(); this.tiga = new ObjectBall(); this.primob = new ObjectBall(); this.kotak = new TextureKubus(); this.mEarth = new MySphere(5, 3); this.mEarth2 = new MySphere(5, 3); this.mEarth3 = new MySphere(5, 3); this.transobject = new TransObject();

//mengambil nilai xyx (posisi awal) labi- rin player } public void setlife(int life){ this.life=life; } public void setlife(){

this.life-=1; } public void setlose(boolean lose){

this.lose=lose; } public void setdif1(boolean dif){

this.dif1=dif; } public void setdif2(boolean dif){

this.dif2=dif;

} public void setdif3(boolean dif){

this.dif3=dif; } //ngabil stage public int getstage(){

return stage; } public int ldif1x(){

return ldif1x; } public int ldif1y(){

return ldif1y; } public int ldif2x(){

return ldif2x; } public int ldif2y(){

return ldif2y; } public int ldif3x(){

return ldif3x; } public int ldif3y(){

return ldif3y; } public void reset(){

this.stage=1; this.lose=false; this.dif1=false; this.dif2=false; this.dif3=false; this.life=3;

} //ngambil life public int getlife(){

return life; } @Override public void onDrawFrame(GL10 gl) {

// menangkap ukuran layar if(get_size_screen){

this.x_lebar_layar = mywidth; this.y_tinggi_layar = myheight; get_size_screen=false;

// Draw background color gl.glClear(GL10.GL_COLOR_BUFFER_BIT |

GL10.GL_DEPTH_BUFFER_BIT); // gl.glClear(GL10.GL_COLOR_BUFFER_BIT); gl.glEnable(GL10.GL_DEPTH_TEST); gl.glEnable(GL10.GL_NORMALIZE);

//gl.glMaterialfv(GL10.GL_FRONT, GL10.GL_AMBIENT_AND_DIFFUSE, makeFloatBuffer(cyan)); //gl.glMaterialfv(GL10.GL_FRONT, GL10.GL_AMBIENT_AND_DIFFUSE, makeFloatBuffer(cyan));

if(getstage()==1){

score=0; } else if(getstage()==2){

score=30; } else if(getstage()==3){

score=50; } else if(getstage()==4){

score=80; } else if(getstage()==5){

score=100; } //buat kordinat sentuh

if(getstage()==1){

ldif1x=785; ldif1y=240; ldif2x=765; ldif2y=60; ldif3x=700; ldif3y=385;

} else if(getstage()==2){

ldif1x=630; ldif1y=240; ldif2x=615; ldif2y=400; ldif3x=740; ldif3y=370;

} else if(getstage()==3){

ldif1x=690; ldif1y=220; ldif2x=640; ldif2y=355; ldif3x=950; ldif3y=360;

} else if(getstage()==4){

ldif1x=840; ldif1y=150; ldif2x=645; ldif2y=400; ldif3x=765; ldif3y=300;

} else if(getstage()==5){

ldif1x=695; ldif1y=50; ldif2x=765; ldif1x=695; ldif1y=50; ldif2x=765;

} //akhir buat kordinat sentuh //membuat stage

if(dif1==true&&dif2==true&&dif3==true){

this.stage=this.stage+1; this.dif1=false; this.dif2=false; this.dif3=false;

} if(stage==6){

this.lose=true;//akhir dari membuat stage

} //gambar 1 gl.glPushMatrix(); gl.glDisable

(GL10.GL_LIGHTING);

gl.glLineWidth(1.0f);

gl.glEnable(GL10.GL_LINE_SMOOTH); //gl.glTranslatef(- x, -y, 0.0f); gl.glTranslatef(25,

30, 0.0f); gl.glScalef(5f, 5f, 1.0f); gamba- ra.draw_circle_color(gl); gl.glEnable (GL10.GL_LIGHTING); gl.glPopMatrix();

//gambar 2 gl.glPushMatrix(); gl.glDisable

(GL10.GL_LIGHTING);

gl.glLineWidth(1.0f);

gl.glEnable(GL10.GL_LINE_SMOOTH); //gl.glTranslatef(- x, -y, 0.0f);

gl.glTranslatef(525, 30, 0.0f); gl.glScalef(5f, 5f, 1.0f); gam- barb.draw_circle_color(gl); gl.glEnable (GL10.GL_LIGHTING); gl.glPopMatrix();

//setkordinatperbedaan if(stage==1){

dif1x=770; dif1y=295; dif2x=755; dif2y=470; dif3x=675; dif3y=130;

} else if(stage==2){

dif1x=615; dif1y=295; dif2x=610; dif2y=135; dif3x=720; dif3y=170;

} else if(stage==3){

dif1x=666; dif1y=305; dif2x=630; dif2y=195; dif3x=930; dif3y=175;

} else if(stage==4){

dif1x=825; dif1y=400; dif2x=640; dif2y=140; dif3x=750; dif3y=220;

} else if(stage==5){

dif1x=680; dif1y=470; dif2x=750; dif2y=50; dif3x=830; dif3y=205;

}//akhir dari kordinat perbedaan

//mulai perbedaan if(dif1==true){ //satu gl.glPushMatrix(); gl.glDisable (GL10.GL_LIGHTING);

gl.glLineWidth(1.0f); gl.glEnable(GL10.GL_LINE_SMOOTH); //gl.glTranslatef(-x, -y, 0.0f); gl.glTranslatef(dif1x, dif1y,

0.0f); gl.glScalef(0.4f, 0.4f, 1.0f); satu.draw_circle_color(gl);

gl.glEnable (GL10.GL_LIGHTING); gl.glPopMatrix(); } if(dif2==true){

//dua //dua

gl.glLineWidth(1.0f); gl.glEnable(GL10.GL_LINE_SMOOTH); //gl.glTranslatef(-x, -y, 0.0f); gl.glTranslatef(dif2x, dif2y,

0.0f); gl.glScalef(0.4f, 0.4f, 1.0f); dua.draw_circle_color(gl);

gl.glEnable (GL10.GL_LIGHTING); gl.glPopMatrix(); } //dif3 if(dif3==true){

//tiga gl.glPushMatrix(); gl.glDisable (GL10.GL_LIGHTING);

gl.glLineWidth(1.0f); gl.glEnable(GL10.GL_LINE_SMOOTH); //gl.glTranslatef(-x, -y, 0.0f); gl.glTranslatef(dif3x, dif3y,

0.0f); gl.glScalef(0.4f, 0.4f, 1.0f); dua.draw_circle_color(gl);

gl.glEnable (GL10.GL_LIGHTING); gl.glPopMatrix(); } //akhir perbedaan

//mencetak hati if(life==3){ //life1 gl.glPushMatrix(); gl.glDisable (GL10.GL_LIGHTING);

gl.glLineWidth(1.0f); gl.glEnable(GL10.GL_LINE_SMOOTH); //gl.glTranslatef(-x, -y, 0.0f); gl.glTranslatef(435, 470, 0.0f); gl.glScalef(0.5f, 0.5f, 1.0f); lifer.draw_circle_color(gl);

gl.glEnable (GL10.GL_LIGHTING); gl.glPopMatrix(); //life2 gl.glPushMatrix(); gl.glDisable (GL10.GL_LIGHTING);

gl.glLineWidth(1.0f); gl.glEnable(GL10.GL_LINE_SMOOTH); //gl.glTranslatef(-x, -y, 0.0f); gl.glTranslatef(495, 470, 0.0f); gl.glScalef(0.5f, 0.5f, 1.0f); lifer.draw_circle_color(gl);

gl.glEnable (GL10.GL_LIGHTING); gl.glPopMatrix(); //life3 gl.glPushMatrix(); gl.glDisable (GL10.GL_LIGHTING);

gl.glLineWidth(1.0f); gl.glEnable(GL10.GL_LINE_SMOOTH); //gl.glTranslatef(-x, -y, 0.0f); gl.glLineWidth(1.0f); gl.glEnable(GL10.GL_LINE_SMOOTH); //gl.glTranslatef(-x, -y, 0.0f);

gl.glEnable (GL10.GL_LIGHTING); gl.glPopMatrix(); } if(life==2){ //life1 gl.glPushMatrix(); gl.glDisable (GL10.GL_LIGHTING);

gl.glLineWidth(1.0f); gl.glEnable(GL10.GL_LINE_SMOOTH); //gl.glTranslatef(-x, -y, 0.0f); gl.glTranslatef(435, 470, 0.0f); gl.glScalef(0.5f, 0.5f, 1.0f); lifer.draw_circle_color(gl);

gl.glEnable (GL10.GL_LIGHTING); gl.glPopMatrix(); //life2 gl.glPushMatrix(); gl.glDisable (GL10.GL_LIGHTING);

gl.glLineWidth(1.0f); gl.glEnable(GL10.GL_LINE_SMOOTH); //gl.glTranslatef(-x, -y, 0.0f); gl.glTranslatef(495, 470, 0.0f); gl.glScalef(0.5f, 0.5f, 1.0f); lifer.draw_circle_color(gl);

gl.glEnable (GL10.GL_LIGHTING); gl.glPopMatrix();

} if(life==1){ //life1 gl.glPushMatrix(); gl.glDisable (GL10.GL_LIGHTING);

gl.glLineWidth(1.0f); gl.glEnable(GL10.GL_LINE_SMOOTH); //gl.glTranslatef(-x, -y, 0.0f); gl.glTranslatef(435, 470, 0.0f); gl.glScalef(0.5f, 0.5f, 1.0f); lifer.draw_circle_color(gl);

gl.glEnable (GL10.GL_LIGHTING);

gl.glPopMatrix(); }//akhir dari mencetak hati

if(lose==true){ //gambar 1 gl.glPushMatrix(); gl.glDisable (GL10.GL_LIGHTING);

gl.glLineWidth(1.0f);

gl.glEnable(GL10.GL_LINE_SMOOTH); //gl.glTranslatef(-x, -y, 0.0f); gl.glTranslatef(270, 30, 0.0f); gl.glScalef(5f, 5f, 1.0f); gl.glEnable(GL10.GL_LINE_SMOOTH); //gl.glTranslatef(-x, -y, 0.0f); gl.glTranslatef(270, 30, 0.0f); gl.glScalef(5f, 5f, 1.0f);

er.draw_circle_color(gl); gl.glEnable (GL10.GL_LIGHTING); gl.glPopMatrix(); gl.glPushMatrix(); gl.glDisable (GL10.GL_LIGHTING);

gl.glEnable(GL10.GL_TEXTURE_2D); // Enable Texture Mapping gl.glEnable(GL10.GL_BLEND); // En- able Alpha Blend gl.glDisable(GL10.GL_DEPTH_TEST); // Turn depth testing off (NEW) gl.glBlendFunc(GL10.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA); // Set glText.begin(1.0f, 1.0f, 1.0f, 1.0f); // Begin Text Rendering gl.glTranslatef(345.f, 200.f, 0.f); //gl.glRotatef(-30, 0.0f, 0.0f, 1.0f);

gl.glScalef(2f, 2f, 0f); gl.glTranslatef(110, 10, 0.f); //gl.glRotatef(CurrentAngle, 0.1f,

1.0f, 0.2f); // Rotate gl.glTranslatef(8f, 5f, 0.f); glText.draw("" + score + "", 0,

0); // Draw Test String glText.end(); // End Text Rendering gl.glPopMatrix();

} if(stage==1){

gambara.loadBallTexture(gl, con- text,0); gambarb.loadBallTexture(gl, con- text,1); } else if(stage==2){ gambara.loadBallTexture(gl, con-

text,5); gambarb.loadBallTexture(gl, con- text,6); } else if(stage==3){ gambara.loadBallTexture(gl, con-

text,7); gambarb.loadBallTexture(gl, con- text,8); } else if(stage==4){ gambara.loadBallTexture(gl, con-

text,9); gambarb.loadBallTexture(gl, con- text,10); } else if(stage==5){ text,9); gambarb.loadBallTexture(gl, con- text,10); } else if(stage==5){

CurrentAngle += AnimateStep;

if (CurrentAngle > 360.0) { //CurrentAngle -= 360.0*Math.floor(CurrentAngle/360.0); CurrentAngle=0.0f; CurrentAngle += Ani-

mateStep; }

CurrentAngle2 += AnimateStep2; if (CurrentAngle2 > 360.0) {

//CurrentAngle -= 360.0*Math.floor(CurrentAngle/360.0); CurrentAngle2=0.0f; CurrentAngle2 += Ani-

mateStep2; }

// pengkondisian penghitungan pantulan mulai dari nol /*if(Run_ModeScale==0){ this.CurrentScale- =ScaleStep; this.Run_ModeScale=1; }*/

CurrentScale += ScaleStep; if (CurrentScale % 10.0f==0) {

ScaleStep = -1*ScaleStep; }

//gl.glFlush();

public float getX_touch() { return x_touch; }

public void setX_touch(float x_touch) { this.x_touch = x_touch; }

public float getY_touch() { return y_touch; } public float getY_touch() { return y_touch; }

public String getArah_joystick() { return arah_joystick; }

public void setArah_joystick(String arah_joystick) { this.arah_joystick = arah_joystick; }

public float getJarak_center() { return jarak_center; }

public void setJarak_center(float jarak_center) { this.jarak_center = jarak_center; }

public float getSudut_pointer() { return sudut_pointer; }

public void setSudut_pointer(float sudut_pointer) { this.sudut_pointer = sudut_pointer; }

public float getX_lebar_layar() { return x_lebar_layar; }

public void setX_lebar_layar(float x_lebar_layar) { this.x_lebar_layar = x_lebar_layar; }

public float getY_tinggi_layar() { return y_tinggi_layar; }

public void setY_tinggi_layar(float y_tinggi_layar) { this.y_tinggi_layar = y_tinggi_layar; }

public float getX_pointer_awal() { return x_pointer_awal; public float getX_pointer_awal() { return x_pointer_awal;

public float getY_pointer_awal() { return y_pointer_awal; }

public void setY_pointer_awal(float y_pointer_awal) { this.y_pointer_awal = y_pointer_awal; }

public float getX_pointer() { return x_pointer; }

public void setX_pointer(float x_pointer) {

this.x_pointer = x_pointer; }

public float getY_pointer() { return y_pointer; }

public void setY_pointer(float y_pointer) {

this.y_pointer = y_pointer; }

public float getX_anim_stick() { return x_anim_stick; }

public void setX_anim_stick(float x_anim_stick) { this.x_anim_stick = x_anim_stick; }

public float getY_anim_stick() { return y_anim_stick; }

public void setY_anim_stick(float y_anim_stick) { this.y_anim_stick = y_anim_stick; }

public float getRadius() { return radius; public float getRadius() { return radius;

public int getMywidth() { return mywidth; }

public void setMywidth(int mywidth) { this.mywidth = mywidth; }

public int getMyheight() { return myheight; }

public void setMyheight(int myheight) { this.myheight = myheight; }

public int getNumberRow() { return numberRow; }

public void setNumberRow(int numberRow) {

this.numberRow = numberRow;

public float getWidthObject() { return WidthObject; }

public void setWidthObject(float widthObject) { WidthObject = widthObject; }

public float getX_player() { return x_player; }

public void setX_player(float x_player) { this.x_player = x_player; }

public float getY_player() { return y_player; }

public void setY_player(float y_player) { this.y_player = y_player; } public void setY_player(float y_player) { this.y_player = y_player; }

public void setNavigate(int navigate) { Navigate = navigate; }

public boolean goForward() {

if(Navigate == 0 && positionRow > 0 && ho- ri[positionRow][positionCol] == 0) return true; if(Navigate == 1 && positionCol < (num- berCol-1) && verti[positionRow][positionCol+1] == 0) return true;

if(Navigate == 2 && positionRow < (number- Row-1) && hori[positionRow+1][positionCol] == 0) re- turn true;

if(Navigate == 3 && positionCol > 0 && ver- ti[positionRow][positionCol] == 0) return true; return false; }

public int getPositionRow() { return positionRow; }

public void setPositionRow(int positionRow) {

this.positionRow = positionRow; }

public int getPositionCol() { return positionCol; }

public void setPositionCol(int positionCol) {

this.positionCol = positionCol; }

@Override public void onSurfaceCreated(GL10 gl, EGLConfig

config) { gl.glClearColor(0.5f, 0.5f, 0.5f, 1.0f); // Set color's clear-value to //gl.glClearColor(1.0f, 1.0f, 1.0f, 1.0f); // Set color's clear-value to

// black //gl.glClearColor(0.0f, 0.0f, 0.0f, 1.0f); // Set color's clear-value to

gl.glClearDepthf(1.0f); // Set depth's clear-value to farthest gl.glEnable(GL10.GL_DEPTH_TEST); // Ena- bles depth-buffer for hidden // surface removal gl.glDepthFunc(GL10.GL_LEQUAL); // The

type of depth testing to do type of depth testing to do

able smooth shading of color //gl.glDisable(GL10.GL_DITHER); // Disa- ble dithering for better // performance gl.glEnable(GL10.GL_LIGHTING);

gl.glEnable(GL10.GL_LIGHT0); gl.glEnable(GL10.GL_LIGHT1);

// Setup Blending (NEW) gl.glColor4f(1.0f, 1.0f, 1.0f, 1f); // Full brightness, 50% alpha (NEW) gl.glBlendFunc(GL10.GL_SRC_ALPHA, GL10.GL_ONE); // Select blending function (NEW)

//mengeset texture berdasarkan stage

//akhir mengeset tekstur stage

//texture hati loser.loadBallTexture(gl, context, 13); lifer.loadBallTexture(gl, context, 4); //texture perbedaan satu.loadBallTexture(gl, context,3); dua.loadBallTexture(gl, context,3); tiga.loadBallTexture(gl, context, 4); //akhir texture perbedaan glText = new ESText(gl, con-

text.getAssets());

// Load the font from file (set size + padding), creates the texture // NOTE: after a successful call to this the font is ready for // rendering! glText.load("Roboto-Regular.ttf", 14, 2,

2); // Create Font (Height: 14

// Pixels / X+Y Padding

// 2 Pixels) gl.glEnable(GL10.GL_TEXTURE_2D); // Ena- ble texture (NEW)

@Override public void onSurfaceChanged(GL10 gl, int width,

int height) { mywidth = width; myheight = height; int height) { mywidth = width; myheight = height;

// Setup orthographic projection gl.glMatrixMode(GL10.GL_PROJECTION); //

Activate Projection Matrix gl.glLoadIdentity(); // Load Identity Ma- trix gl.glOrthof( // Set Ortho Projection (Left,Right,Bottom,Top,Front,Back)

0, width, 0, height, 500.0f, -500.0f);

// Save width and height // this.width = width; // Save Current

Width // this.height = height; // Save Current Height

gl.glMatrixMode(GL10.GL_MODELVIEW); // Select model-view matrix

gl.glLoadIdentity(); // Reset

public float getxMax() { return xMax; }

public void setxMax(int xmax) { xMax = xmax; }

public float getxMin() { return xMin; }

public void setxMin(int xmin) { xMin = xmin; }

public float getyMax() { return yMax; }

public void setyMax(int ymax) { yMax = ymax; }

public float getyMin() { return yMin; }

public void setyMin(int ymin) { yMin = ymin; }

public float getspeedX() { return speedX; } public float getspeedX() { return speedX; }

public float getspeedY() { return speedY; }

public void setspeedY(float speedY_) { speedY = speedY_; }

public void moveWithCollisionDetection(ESRender esRender) { // Get new (x,y) position x += speedX; y += speedY; // Detect collision and react if (x + radius > esRender.getxMax()) {

speedX = -speedX; x = esRender.getxMax() - radius; this.jumlah_pantulan+=1;

} else if (x - radius < esRen- der.getxMin()) { speedX = -speedX; x = esRender.getxMin() + radius; this.jumlah_pantulan+=1;

} if (y + radius > esRender.getyMax()) {

speedY = -speedY; y = esRender.getyMax() - radius; this.jumlah_pantulan+=1;

} else if (y - radius < esRen- der.getyMin()) { speedY = -speedY; y = esRender.getyMin() + radius; this.jumlah_pantulan+=1;

// pengkondisian penghitungan pantulan mulai dari nol if(Run_Mode==0){ this.jumlah_pantulan-=4; this.Run_Mode=1;

public void set(int x, int y, int width, int height) { xMin = x; // xMax = x + width - 1; xMax = x + width; yMin = y; // yMax = y + height - 1; yMax = y + height;

/*ESText.java*/

// This is a OpenGL ES 1.0 dynamic font rendering system. It loads actual font // files, generates a font map (texture) from them, and allows rendering of // text strings. // // NOTE: the rendering portions of this class uses a sprite batcher in order // provide decent speed rendering. Also, rendering assumes a BOTTOM-LEFT // origin, and the (x,y) positions are relative to that, as well as the // bottom-left of the string to render.

package com.modelloading;

import javax.microedition.khronos.opengles.GL10;

import android.content.res.AssetManager; import android.graphics.Bitmap; import android.graphics.Canvas; import android.graphics.Paint; import android.graphics.Typeface; import android.opengl.GLUtils;

public class ESText {

//--Constants--// public final static int CHAR_START = 32;

// First Character (ASCII Code) public final static int CHAR_END = 126; // Last Character (ASCII Code) public final static int CHAR_CNT = ( ( ( CHAR_END - CHAR_START ) + 1 ) + 1 ); // Character Count (Including Character to use for Unknown)

public final static int CHAR_NONE = 32; // Character to Use for Unknown (ASCII Code) public final static int CHAR_UNKNOWN = ( CHAR_CNT - 1 ); // Index of the Unknown Character

public final static int FONT_SIZE_MIN = 6; // Minumum Font Size (Pixels)

public final static int FONT_SIZE_MAX = 180; // Maximum Font Size (Pixels)

public final static int CHAR_BATCH_SIZE = 100; // Number of Characters to Render Per Batch

//--Members--// GL10 gl;

// GL10 Instance

AssetManager assets; // Asset Manager SpriteBatch batch; // Batch Renderer

int fontPadX, fontPadY; // Font Padding (Pixels; On Each Side, ie. Doubled on Both X+Y Axis)

float fontHeight; // Font Height (Actual; Pixels) float fontAscent; // Font Ascent (Above Baseline; Pixels) float fontDescent; // Font Descent (Below Baseline; Pixels)

int textureId; // Font Texture ID [NOTE: Public for Testing Purposes Only!]

int textureSize; // Texture Size for Font (Square) [NOTE: Public for Testing Purposes Only!]

TextureRegion textureRgn; // Full Texture Region

float charWidthMax; // Character Width (Maximum; Pixels) float charHeight; // Character Height (Maximum; Pixels) final float[] charWidths; // Width of Each Character (Actual; Pixels) TextureRegion[] charRgn; // Region of Each Character (Texture Coordinates) int cellWidth, cellHeight; // Character Cell Width/Height int rowCnt, colCnt; // Number of Rows/Columns

float scaleX, scaleY; // Font Scale (X,Y Axis) float spaceX; // Additional (X,Y Axis) Spacing (Unscaled)

//--Constructor--// // D: save GL instance + asset manager, create

arrays, and initialize the members // A: gl - OpenGL ES 10 Instance public ESText(GL10 gl, AssetManager assets) {

this.gl = gl; // Save the GL10 Instance this.assets = assets; // Save the Asset Manager Instance

batch = new SpriteBatch( gl, CHAR_BATCH_SIZE ); // Create Sprite Batch (with Defined Size)

charWidths = new float[CHAR_CNT]; // Create the Array of Character Widths charWidths = new float[CHAR_CNT]; // Create the Array of Character Widths

// initialize remaining members fontPadX = 0; fontPadY = 0;

fontHeight = 0.0f; fontAscent = 0.0f; fontDescent = 0.0f;

textureId = -1; textureSize = 0;

charWidthMax = 0; charHeight = 0;

cellWidth = 0; cellHeight = 0; rowCnt = 0; colCnt = 0;

scaleX = 1.0f; // Default Scale = 1 (Unscaled) scaleY = 1.0f; // Default Scale = 1 (Unscaled) spaceX = 0.0f; }

//--Load Font--// // description // this will load the specified font file,

create a texture for the defined // character range, and setup all required values used to render with it. // arguments: // file - Filename of the font (.ttf, .otf) to

use. In 'Assets' folder. // size - Requested pixel size of font (height) // padX, padY - Extra padding per character

(X+Y Axis); to prevent overlapping characters.

public boolean load(String file, int size, int padX, int padY) {

// setup requested values fontPadX = padX;

// Set Requested X Axis Padding fontPadY = padY; // Set Requested Y Axis Padding

// load the font and setup paint instance for drawing Typeface tf = Typeface.createFromAsset( assets, file ); // Create the Typeface from Font File Paint paint = new Paint(); // Create Android Paint Instance paint.setAntiAlias( true ); // Enable Anti Alias paint.setTextSize( size );

// Set Text Size paint.setColor( 0xffffffff ); // Set ARGB (White, Opaque) paint.setTypeface( tf ); // Set Typeface

// get font metrics Paint.FontMetrics fm = paint.getFontMetrics();

// Get Font Metrics

fontHeight = (float)Math.ceil( Math.abs( fm.bottom ) + Math.abs( fm.top ) ); // Calculate Font Height

fontAscent = (float)Math.ceil( Math.abs( fm.ascent ) ); // Save Font Ascent

fontDescent = (float)Math.ceil( Math.abs( fm.descent ) ); // Save Font Descent

// determine the width of each character (including unknown character) // also determine the maximum character width char[] s = new char[2];

// Create Character Array charWidthMax = charHeight = 0; // Reset Character Width/Height Maximums float[] w = new float[2]; // Working Width Value int cnt = 0; // Array Counter for ( char c = CHAR_START; c <= CHAR_END; c++ ) { // FOR Each Character s[0] = c; // Set Character

paint.getTextWidths( s, 0, 1, w ); // Get Character Bounds charWidths[cnt] = w[0]; // Get Width

if ( charWidths[cnt] > charWidthMax ) // IF Width Larger Than Max Width

charWidthMax = charWidths[cnt];

// Save New Max Width cnt++; // Advance Array Counter } s[0] = CHAR_NONE;

// Set Unknown Character paint.getTextWidths( s, 0, 1, w ); // Get Character Bounds charWidths[cnt] = w[0]; // Get Width if ( charWidths[cnt] > charWidthMax ) // IF Width Larger Than Max Width charWidthMax = charWidths[cnt]; // Save New Max Width cnt++; // Advance Array Counter

// set character height to font height charHeight = fontHeight;

// Set Character Height

// find the maximum size, validate, and setup cell sizes cellWidth = (int)charWidthMax + ( 2 * fontPadX ); // Set Cell Width cellHeight = (int)charHeight + ( 2 * fontPadY ); // Set Cell Height int maxSize = cellWidth > cellHeight ? cellWidth : cellHeight; // Save Max Size (Width/Height)

if ( maxSize < FONT_SIZE_MIN || maxSize > FONT_SIZE_MAX ) // IF Maximum Size Outside Valid Bounds

return false; // Return Error

// set texture size based on max font size (width or height) // NOTE: these values are fixed, based on the defined characters. when // changing start/end characters (CHAR_START/CHAR_END) this will need adjustment too! if ( maxSize <= 24 ) // IF Max Size is 18 or Less textureSize = 256; // Set 256 Texture Size else if ( maxSize <= 40 ) // ELSE IF Max Size is 40 or Less textureSize = 512; // Set 512 Texture Size else if ( maxSize <= 80 ) // ELSE IF Max Size is 80 or Less textureSize = 1024; // Set 1024 Texture Size else // ELSE IF Max Size is Larger Than 80 (and Less than FONT_SIZE_MAX)

textureSize = 2048; // Set 2048 Texture Size

// create an empty bitmap (alpha only) Bitmap bitmap = Bitmap.createBitmap(

textureSize, textureSize, Bitmap.Config.ALPHA_8 ); // Create Bitmap

Canvas canvas = new Canvas( bitmap ); // Create Canvas for Rendering to Bitmap bitmap.eraseColor( 0x00000000 ); // Set Transparent Background (ARGB)

// calculate rows/columns // NOTE: while not required for anything, these

may be useful to have :) colCnt = textureSize / cellWidth; // Calculate Number of Columns

rowCnt = (int)Math.ceil( (float)CHAR_CNT / (float)colCnt ); // Calculate Number of Rows

// render each of the characters to the canvas (ie. build the font map) // render each of the characters to the canvas (ie. build the font map)

if ( ( x + cellWidth - fontPadX ) > textureSize ) { // IF End of Line Reached x = fontPadX; // Set X for New Row y += cellHeight; // Move Down a Row } } s[0] = CHAR_NONE;

// Set Character to Use for NONE

canvas.drawText( s, 0, 1, x, y, paint ); // Draw Character

// generate a new texture int[] textureIds = new int[1];

// Array to Get Texture Id gl.glGenTextures( 1, textureIds, 0 ); // Generate New Texture textureId = textureIds[0]; // Save Texture Id

// setup filters for texture gl.glBindTexture( GL10.GL_TEXTURE_2D, textureId

); // Bind Texture gl.glTexParameterf( GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MIN_FILTER, GL10.GL_NEAREST ); // Set Minification Filter

gl.glTexParameterf( GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MAG_FILTER, GL10.GL_LINEAR ); // Set Magnification Filter

gl.glTexParameterf( GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_S, GL10.GL_CLAMP_TO_EDGE ); // Set U Wrapping

gl.glTexParameterf( GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_T, GL10.GL_CLAMP_TO_EDGE ); // Set V Wrapping

// load the generated bitmap onto the texture GLUtils.texImage2D( GL10.GL_TEXTURE_2D, 0,

bitmap, 0 ); // Load Bitmap to Texture

gl.glBindTexture( GL10.GL_TEXTURE_2D, 0 ); // Unbind Texture

// release the bitmap bitmap.recycle();

// Release the Bitmap

// setup the array of character texture regions x = 0;

// Initialize X y = 0; // Initialize Y

for ( int c = 0; c < CHAR_CNT; c++ ) { // FOR Each Character (On Texture) charRgn[c] = new TextureRegion( textureSize, textureSize, x, y, cellWidth-1, cellHeight-1 ); // Create Region for Character

x += cellWidth; // Move to Next Char (Cell)

if ( x + cellWidth > textureSize ) {

x = 0; // Reset X Position to Start y += cellHeight; // Move to Next Row (Cell) } }

// create full texture region textureRgn = new TextureRegion( textureSize,

textureSize, 0, 0, textureSize, textureSize ); // Create Full Texture Region

// return success return true;

// Return Success }

//--Begin/End Text Drawing--// // D: call these methods before/after

(respectively all draw() calls using a text instance // NOTE: color is set on a per-batch basis, and fonts should be 8-bit alpha only!!! // A: red, green, blue - RGB values for font (default = 1.0) // alpha - optional alpha value for font (default = 1.0) // R: [none] public void begin() {

begin( 1.0f, 1.0f, 1.0f, 1.0f ); // Begin with White Opaque } public void begin(float alpha) {

begin( 1.0f, 1.0f, 1.0f, alpha ); // Begin with White (Explicit Alpha) } public void begin(float red, float green, float

blue, float alpha) {

gl.glColor4f( red, green, blue, alpha ); // Set Color+Alpha gl.glBindTexture( GL10.GL_TEXTURE_2D, textureId ); // Bind the Texture batch.beginBatch(); // Begin Batch } public void end() {

batch.endBatch();

// End Batch

gl.glColor4f( 1.0f, 1.0f, 1.0f, 1.0f ); // Restore Default Color/Alpha }

//--Draw Text--// // D: draw text at the specified x,y position // A: text - the string to draw // x, y - the x,y position to draw text at

(bottom left of text; including descent) // R: [none] public void draw(String text, float x, float y) {

float chrHeight = cellHeight * scaleY; // Calculate Scaled Character Height float chrWidth = cellWidth * scaleX; // Calculate Scaled Character Width int len = text.length(); // Get String Length x += ( chrWidth / 2.0f ) - ( fontPadX * scaleX ); // Adjust Start X y += ( chrHeight / 2.0f ) - ( fontPadY * scaleY ); // Adjust Start Y for ( int i = 0; i < len; i++ ) { // FOR Each Character in String int c = (int)text.charAt( i ) - CHAR_START; // Calculate Character Index (Offset by First Char in Font)

if ( c < 0 || c >= CHAR_CNT ) // IF Character Not In Font

c = CHAR_UNKNOWN; // Set to Unknown Character Index batch.drawSprite( x, y, chrWidth, chrHeight, charRgn[c] ); // Draw the Character x += ( charWidths[c] + spaceX ) * scaleX; // Advance X Position by Scaled Character Width } }

//--Draw Text Centered--// // D: draw text CENTERED at the specified x,y

position // A: text - the string to draw // x, y - the x,y position to draw text at

(bottom left of text)

// R: the total width of the text that was drawn public float drawC(String text, float x, float y)

{ float len = getLength( text ); // Get Text Length draw( text, x - ( len / 2.0f ), y - ( getCharHeight() / 2.0f ) ); // Draw Text Centered return len; // Return Length } public float drawCX(String text, float x, float y)

{ float len = getLength( text ); // Get Text Length draw( text, x - ( len / 2.0f ), y );

// Draw Text Centered (X-Axis Only) return len; // Return Length } public void drawCY(String text, float x, float y)

{ draw( text, x, y - ( getCharHeight() / 2.0f ) ); // Draw Text Centered (Y-Axis Only) }

//--Set Scale--// // D: set the scaling to use for the font // A: scale - uniform scale for both x and y axis

scaling // sx, sy - separate x and y axis scaling factors // R: [none] public void setScale(float scale) {

scaleX = scaleY = scale; // Set Uniform Scale } public void setScale(float sx, float sy) {

scaleX = sx; // Set X Scale scaleY = sy; // Set Y Scale }

//--Get Scale--// // D: get the current scaling used for the font // A: [none] // R: the x/y scale currently used for scale public float getScaleX() {

return scaleX; // Return X Scale } public float getScaleY() {

return scaleY; // Return Y Scale }

//--Set Space--// // D: set the spacing (unscaled; ie. pixel size)

to use for the font // A: space - space for x axis spacing // R: [none] public void setSpace(float space) {

spaceX = space; // Set Space }

//--Get Space--// // D: get the current spacing used for the font // A: [none] // R: the x/y space currently used for scale public float getSpace() {

return spaceX; // Return X Space }

//--Get Length of a String--// // D: return the length of the specified string if

rendered using current settings // A: text - the string to get length for // R: the length of the specified string (pixels) public float getLength(String text) {

float len = 0.0f; // Working Length int strLen = text.length(); // Get String Length (Characters) for ( int i = 0; i < strLen; i++ ) { // For Each Character in String (Except Last int c = (int)text.charAt( i ) - CHAR_START; // Calculate Character Index (Offset by First Char in Font)

len += ( charWidths[c] * scaleX ); // Add Scaled Character Width to Total Length } len += ( strLen > 1 ? ( ( strLen - 1 ) * spaceX

) * scaleX : 0 ); // Add Space Length return len; // Return Total Length }

//--Get Width/Height of Character--// // D: return the scaled width/height of a

character, or max character width // NOTE: since all characters are the same height, no character index is required! // NOTE: excludes spacing!! // A: chr - the character to get width for // R: the requested character size (scaled) public float getCharWidth(char chr) {

int c = chr - CHAR_START; // Calculate Character Index (Offset by First Char in Font)

return ( charWidths[c] * scaleX ); // Return Scaled Character Width } public float getCharWidthMax() {

return ( charWidthMax * scaleX ); // Return Scaled Max Character Width } public float getCharHeight() {

return ( charHeight * scaleY ); // Return Scaled Character Height }

//--Get Font Metrics--// // D: return the specified (scaled) font metric // A: [none] // R: the requested font metric (scaled) public float getAscent() {

return ( fontAscent * scaleY ); // Return Font Ascent } public float getDescent() {

return ( fontDescent * scaleY );

// Return Font Descent } public float getHeight() {

return ( fontHeight * scaleY ); // Return Font Height (Actual) }

//--Draw Font Texture--// // D: draw the entire font texture (NOTE: for

testing purposes only)

// A: width, height - the width and height of the area to draw to. this is used

// to draw the texture to the top-left corner. public void drawTexture(int width, int height) {

batch.beginBatch( textureId ); // Begin Batch (Bind Texture) batch.drawSprite( textureSize / 2, height - ( textureSize / 2 ), textureSize, textureSize, textureRgn ); // Draw

batch.endBatch(); // End Batch }