Friday, June 17, 2011

Mini project "3D Bounce " in OpenGL

This project is my second year mini project.I have use GLUT(OpenGL) library in c++.3D Bounce is a game in which we have to bounce the ball to collect the floating star,after collecting all star then door opens for next room.Due to lack of time I can't complete this project but all image drawing part is completed and I hope you will complete it for your collage project.You can download it source code from this link http://www.4shared.com/file/J-cjGaN-/bounce.html .This program is written in complete object oriented environment ,I have made different class in different file and It's code is very lengthy so  I can't give source code here.



List of class that I have made are:-

loadBMP.h //file use for loading bitmap image for texture map


class Image {
public:
Image(char* ps, int w, int h);
~Image();
char* pixels;
int width;
int height;
};


Image* loadBMP(const char* filename);
//Reads a bitmap image from file.


drawing.h   //all image drawing for game content in this file


#include <glut.h>
#include <iostream>
//#include <stdio.h>
//#include <math.h>
#include "loadBMP.h"
class Ball;  //creating object for class ball
typedef struct
{
int X;
int Y;
int Z;
double U;
double V;
}VERTICES;
class drawing
{
private:
Ball *ball;


GLuint _cellingtextureID;
GLuint _walltextureID;
GLuint _floortextureID;
GLuint _secondfloortextureID;
GLuint _cubetextureID;
GLuint _gatetextureID;
GLuint _balltextureID;
GLuint _poletextureID;
GLuint _foodtextureID;
// GLuint _gatetextureID;

GLint CELL;
GLint poleDisplayList;
GLint gateDisplayList;
GLint roomDisplayList;
GLint cubeDisplayList;
GLint foodDisplayList;
GLuint menuDisplayList;


/*const*/ int space;// = 10;
/*const*/ int VertexCount;// = (90 / space) * (360 / space) * 4;
VERTICES *VERTEX;//[VertexCount];
int PI;
GLfloat CELL2;
GLfloat CUBE_POS;
GLfloat FOOD_POS;
int cube_ran_pos[6][6];
int food_ran_pos[4][4];
bool Gamestart;

void startwindow();
void drawRoom();
void drawBall();
void setupPole();
void setupGate();
void drawcube();
void drawFood();
void DisplaySphere(double);

//void drawGate();
void drawPole_and_Gate();
void setupLighting();
//int random_num(int);
public:
drawing();
void CreateSphere (double R, double H, double K, double Z);
void callBallConstructor();
//void setdrawing();
void draw();
~drawing();

void checkleftkey();
void checkrightkey();
void checkupkey();
void checkdownkey();
};

//this class used to draw image

game.h //this file content ball class from where all ball action is controled



//#include<vector>
#include <glut.h>
//const float BARRIER_SIZE = 0.12f;


class Ball {
private:
//The radius of the ball
float r;
//The x coordinate of the ball
float x0;
//The y coordinate of the ball
float y0;
//The z coordinate of the ball
float z0;

//The angle at which the ball is traveling.  An angle of 0 indicates the
//positive x direction, while an angle of PI / 2 indicates the positive
//z direction.  The angle is always between 0 and 2 * PI.
float angle0;
//The fraction that the ball is "faded in", from 0 to 1.  It is not 1
//when the ball is fading in or out.
float fadeAmount0;
//Whether the ball is fading out
bool isFadingOut0;

//collision detection
void DetectCollision();



public:
//Constructs a new ball with the specified radius, x,  y and z coordinates,
//and angle of travel.  An angle of 0 indicates the positive x
//direction, while an angle of PI / 2 indicates the positive z
//direction.  The angle must be between 0 and 2 * PI.
Ball();

//Returns the radius of the ball
float radius();
//Returns the x coordinate of the ball
float x();

//returns the z coordinate of the ball

float y();
//Returns the z coordinate of the ball
float z();
//Returns the angle at which the ball is traveling.  An angle of 0
//indicates the positive x direction, while an angle of PI / 2 indicates
//the positive z direction.  The returned angle is between 0 and 2 * PI.
float angle();

//Causes the ball to begin fading out
void fadeOut();
//Returns whether the ball is fading out
bool isFadingOut();

//sets the angle of ball
void setangle();

//checks whether the left key is pressed
void checkleftkey();

//checks whether the right key is pressed
void checkrightkey();

//checks whether the up key is currently depressed
void checkupkey();

//checks whether the down key is currently depressed
void checkdownkey();
};

I hope you guys got a little idea for this game .Download it's complete source code and complied it in codeblock or visual studio but don't forgot to setup GLUT(OpenGL).
Thank you.

1 comment: