3D Shooting Game
3D Shooting Game
3D Shooting Game
• Our Goal
• Why make a game
• Thanks Giving to “OpenGL Game
Programming” Book by Dave Astle
• Storyline
• Design
• Problems
• Screenshots
Our Goal
The main goal of our project was to make a 3D First Person Shooter Game.
Although there are lots of such games already in the market. We wished to
make it our own way. Initially When we opted for our project we knew only
about how to make a Room. But later Studying various Books and Websites
we got the ideas to load an MD2 Model which would be the monster in
our game. We could have designed our own MD2 Model. But due to lack of
time, We used the Models that were developed for Quake2 game.
Our Game World Consists of Various Rooms. These Rooms have a Sliding
door which gets automatically opened when the player is near it, and gets
closed when player moves away from it.
Our Project is implemented in C++/OpenGL. C++ takes care of the Backend
Part
OpenGL takes care of the Frontend part.
Why Make a Game?
• Something We always wanted to do
• More fun than previous projects
• Graphics programming
• Uses concepts learned in CS courses
Thanks to
“OpenGL Game Programming” for It’s
Invaluable Ideas for our Project
Storyline
You’ve been trapped inside a Monster
House. You Got to Kill all the Sod
monsters of Level 1 and get into the
Level 2. The Level 2 brings you to attack
with Ogro Monsters.
That’s It! You are set free from
the Monster house: GAME OVER
Design
Data Structures/Algorithms:
• Our Game Engine
• Trees
• CObject and Collision Detection
• Game Engine Core
• Artificial Intelligence
• Game Mode
Our Game Engine
Our Game Engine’s Class Design
Example of Game World Architecture
Tree Data Structure
To make a Tree we need Nodes to get attached to it, So we introduce the
concept of CNode class. An CNode would look something like this:
Attaching Nodes
void AttachTo(CNode *newParent)
{
// if this node is already attached to another node, then detach
if (parentNode)
Detach();
parentNode = newParent;
if (parentNode->childNode)
{
prevNode = parentNode->childNode->prevNode;
nextNode = parentNode->childNode;
parentNode->childNode->prevNode->nextNode = this;
parentNode->childNode->prevNode = this;
}
else
{
parentNode->childNode = this; // this is the first child
}
}
CObject
For Example: a Room and a Monster are not the same. Room is static
whereas Monster attacks the player, it has animation in it and also some
amount of AI.
CObject is basically derived from the CNode, which makes the Tree Data
Structure.
The Attributes of an Object are:
Position Vector: Where the object is in the 3D World
Velocity Vector: With what velocity the object is moving
Acceleration Vector: Acceleration of the object
maxX: This determines the maximum value of x component from the origin of the
object
minX: This determines the minimum value of x component from the origin of the object
maxY: This determines the maximum value of y component from the origin of the
object
minY: This determines the minimum value of y component from the origin of the object
maxZ: This determines the maximum value of z component from the origin of the object
minZ: This determines the minimum value of z component from the origin of the object
Size: This describes the Size of the Object from the origin of the object
isDead: This determines whether the object should be in the 3D World or not.
The attributes maxX, minx, maxY, minY, maxZ, minZ describes the bounding box of the
object for Collision Detection w.r.t other objects.
The CObject has the following methods:
// draw siblings
if (HasParent() && !IsLastChild())
((CObject*)nextNode)->Draw(camera);
}
The Trace for Animate(deltaTime) is as shown below:
gameCamera->yaw += (float)diffx;
gameCamera->pitch -= (float)diffy;
glutPostRedisplay();
Here every time we OnMouseMove () is called we find diffx and diffy. We store the x
and y in lastx and lasty for the next call to OnMouseMove ().
Next we update the gameCamera’s yaw by diffx and gameCamera’s pitch by diffy.
The Texture Class
class CTexture
{
private:
long int scaledWidth;
long int scaledHeight;
public:
int width;
int height;
int bitDepth;
unsigned int texID;
unsigned char *data;
CTexture() { data = NULL; count++; printf("%d " , count ); }
~CTexture() { Unload(); }
void LoadTexture(char *filename);
void Unload()
{
glDeleteTextures(1, &texID);
if (data != NULL)
free(data);
data = NULL;
}
};
The LoadTexture(filename) lets to load the desired texture, and the texture id would
be stored in texID.
The Game World
Finally, here we describe about the class which is letting us to walk into.
We named it as CWorld class.
It has the following attributes:
All the Objects of the world. This mainly includes the Room Objects. Rooms can be
of FRoom, LRoom, RRoom or Broom type.
It has a pointer to the current position of the Game Camera: camera
It has a CGUI class object which lets us to print scores and other stuff onto the
screen.
And other miscellaneous objects as per the Game Development.
It has the following Methods:
void LoadRooms() : It loads all the rooms of the world into the memory.
void LoadWorld() : This calls LoadRooms() and also creates some monsters as per
necessity.
void Animate(float deltaTime) : This function lets the Preorder Traversal of all the
Objects connected to the main Object “house” to be animated.
void Draw(CCamera *camera) : This function lets the Preorder Traversal of all the
Objects connected to the main Object “house” to be drawn onto the Screen.
void Prepare() : This function lets the Preorder Traversal of all the Objects
connected to the main Object “house” to be prepared for the next GameCycle.
void FadeScreen() : This function Fades the screen by blending. We use this
Function to display Game Over.
And Other miscellaneous methods as per the Game Development.
The Game Camera
As expected, the CCamera class defines the camera viewing system for the
engine and is responsible for determining how you view the world. The
CCamera class is defined as follows:
class CCamera
{
public:
//CVector oldpos;
CVector position; // position of camera
CVector velocity; // velocity of camera
CVector acceleration; // acceleration of camera
CVector lookAt; // lookat vector
The other attributes i.e., position, lookAt , acceleration and velocity are altered or
changed by the Animate().
The code of void Animate(scalar_t deltaTime) is:
velocity += acceleration*deltaTime;
The player is the interactive part of the game and he can be moved around the
world with the mouse and keyboard.
We should keep track of old coordinates to know how far the player should move
and in which direction.
Sliding Door
Door slides automatically to open, when the player is near the door and closes as the
player moves away from it, this is implemented with the help of distance of player from the
door. If this distance is equal or less than the minimum distance then door opens and when
distance is greater than this minimum distance it closes.
ROOMS
The Rooms are nothing but than an modified version of a cube. Having various
ways of entrances
Entrance at Front: FROOM
Entrance at Back: BROOM
Entrance at Left: LROOM
Entrance at Right: RROOM
Each Rooms are made out of a still more basic Unit called as Wall.
A CWall produces a Quad with position at the center.
If Orientation=0 then it’s parallel to x-axis
Else if Orientation=1 then it’s parallel to y-axis
Rooms Design:
Walls Design:
Front Entrance Design:
Fog
float fogColor[4] = {0.1, 0.1, 0.1, 0}; // Let's make the Fog Color black too
glEnable(GL_FOG);
Snapshots
CONLUSION