Tribhuwan University
Institute of Engineering
Pulchowk Campus
A project report on: Mrita-Sikar
Submitted by :
Anjesh Kafle (069/BCT/503)
Ankit Mehata (069/BCT/504)
Bibek Dahal (069/BCT/507)
Submitted to :
Department of Electronics & Computer
P a g e | 1
Acknowledgement
We’d like to express our deep gratitude to Mr. Daya Sagar Baral and the
Department of Electronics and Computer Engineering, Central Campus for this
wonderful opportunity to create our very own project using Object Oriented
Programming. We’d also like to express our very great appreciation to all of our
friends for their valuable and constructive suggestions during the planning and
development of this research work.
P a g e | 2
Abstract
The field of programming is getting higher and higher on scope every new day, as
the world is drastically getting more and more advanced in technology. World is
now highly dependent to software because of its rapid development and it ability
to provide versatility to the hardware it runs on. So, the large success of the
programming field comes from the different genres in which a programmer can
code on and the advanced game programming is one of them. The 3D games, now
days, are built to have extremely high quality graphics which almost looks like
simulation of real life. Providing that level of graphic quality in a game makes it
really interesting for the players but it’s very difficult for game development
group, it’s a challenge for them. Also this type of project takes developers to their
extent of knowledge and skills. So we, our team, decided to accept this challenge
a few months earlier and to build a high level 3D action game. We started this
project, progressing day by day till it became able to be called a 3D action game.
We hope this attempt of ours, to give the modern gaming what they want, to
become a successful.
P a g e | 3
Table of Contents
1. Objectives ----------------------- 4
2. Introduction ----------------------- 5
3. Methodology & Implementation ----------------------- 6
4. Knowledge and Tools Required ----------------------- 16
5. Conclusion ----------------------- 12
6. Reference ----------------------- 13
P a g e | 4
Objectives
To design and develop a 3D action, first person/third person shooter game. To introduce high-tech graphics and audio feature in the game.
P a g e | 5
Introduction
The project “Mrita-Sikar” is a 3D-action third-person shooter game which is
based on the science fiction character Zombies. The game models a world where
the character of player can freely roam in search of the zombies. The main
objective of the player in this game is to search for the zombies and kill them
before other people (civilians) in the game gets hurt or killed by the zombies. The
player is given a pistol as the weapons, which he/she has to aim for and shoot at
the zombie. Killing the zombies will gain the player points and letting the people
get harmed by the zombies will cause the points to be lost. When attacked by a
zombie, the health of player will get reduced or may be killed according to current
health condition of the player. So, the player needs to kill the zombies without
getting himself/herself and the other person attacked.
Zombie is an animated corpse raised due to the infection by some fictional virus
which has ability to take control over the human’s body. As fictional undead
creatures, zombies are regularly encountered in horror and fantasy themed works.
They are typically depicted as mindless, reanimated corpses with a hunger for
human flesh, and particularly for human brains in some depictions.
Third-person shooter (TPS) is a genre of 3D action games in which the player
character is visible on-screen, and the gameplay consists primarily of shooting.
To make the game more interesting, enjoyable and addicting, we can add some
extra features in the game. Such as, some background story before the player
enters the world. We can also add missions which can be played over different
worlds and with different difficulty level. We can also work on more realistic
effects and make the simulation more accurate. These features can be gradually
added to the game in upcoming releases of the game.
P a g e | 6
Methodology & Implementation
Knowledge and Tools Used
Object-oriented Programming
Object-oriented programming (OOP) is a programming paradigm that represents
concepts as "objects" that have data fields (attributes that describe the object) and
associated procedures known as methods. Objects, which are usually instances of
classes, are used to interact with one another to design applications and computer
programs. Rather than structure programs as code and data, an object-oriented
system integrates the two using the concept of an "object". An object has state
(data) and behavior (code). Objects correspond to things found in the real world.
C++, java, C# are some popular OOP languages.
We have used C++ programming language to program the game with object-
oriented approach.
The OpenGL API and helper libraries
OpenGL (Open Graphics Library) is a cross-language, multi-platform application
programming interface (API) for rendering 2D and 3D computer graphics. The
API is typically used to interact with a Graphics processing unit (GPU), to achieve
hardware-accelerated rendering. The API is defined as a number of functions
which may be called by the client program, alongside a number of named integer
constants.
We have used OpenGL 3.3 in our project to render high-quality graphics with best
performance using shaders. Shaders are small programs that are executed in GPU
and provides flexibility and speed to graphics rendering ability.
Besides OpenGL itself, other helper libraries are used to make development
easier. GLEW (OpenGL Extension Wrangler Library) is used to run and query
OpenGL extensions. GLM (OpenGL Mathematics) is used to perform different
mathematics operations that include matrices, vectors and quaternions. SOIL
(Simple OpenGL Image Library) is used to load textures in the format OpenGL
recognizes from any image file.
P a g e | 7
irrKlang - High Level Audio Engine/API
irrKlang is a high level 2D and 3D cross platform (Windows, Mac OS X, Linux)
sound engine and audio library which can play various audio format and is usable
in C++ and various other programming language. It is a powerful high level API
for playing back sound in 3D and 2D applications like games, scientific
visualizations and multimedia applications.
We have used irrKlang audio engine as our audio API to provide a better audio
experience for the players.
GitHub
GitHub is a web-based hosting service for software development projects that use
the Git revision control system. The site provides social networking functionality
such as feeds, followers, wikis and the social network graph to display how
developers work on their versions of a repository. A team can use GitHub to work
on same project and synchronize their works as a contribution to the project.
So, we have used GitHub for our work synchronization and better project
management as a team.
Microsoft Visual Studio
Microsoft Visual Studio is an integrated development environment (IDE) from
Microsoft. Visual Studio supports different programming languages by means of
language services, which allow the code editor and debugger to support (to
varying degrees) nearly any programming language, provided a language-specific
service exists.
We have used Microsoft Visual Studio 2013 as our IDE which supports source
control from GitHub.
P a g e | 8
System Design
The overall system of the project can be divided into 4 major programming
components that work together with the output system as follows.
The four major systems are as follows:
Window and Graphics System
Audio System
Collision System
Scene Management & Gaming System
Each of these is described in subsequent sections in detail.
Window and Graphics System
This system is responsible for the graphics handling of the game. It provides two
central classes:
Window : to create and manage window using WIN32 API and manage
OpenGL rendering context
Renderer : to manage OpenGL states, shaders, depth-maps, and begin and end
rendering frames
Window &
Graphics System
Collision
System Audio
System
Scene
Management &
Gaming System
Display & Audio
Output System
P a g e | 9
These work together with following classes to provides graphic handling features.
Mesh : represents a set of vertices and indices to form a 3d object. A mesh
may be boned/skinned to provide smooth animation and has a texture attached to
it.
Model : represents a collection of meshes and are actually used for rendering
any 3d object in the game. A model can be loaded from a file and can have
animation data attached to it in the form of animation hierarchy. The animation
hierarchy is a tree-like structure where a parent node’s animation affects all its
children nodes’ animations.
Sprite : represents an image that can be displayed as 2-d objects or billboards.
Sprites can be animation using a sprite sheet for image.
Skybox : represents a cube that holds 6 textures for each of its face and uses
cube-mapping to provide a sky around the world.
Techniques : to manage different sets of uniforms for different types of shaders.
Each type of shaders is managed by a Techniques class that inherits from a
common parent. These are separately used for normal-mesh rendering, skinned-
mesh rendering, sprite and billboard rendering, depth-map rendering, skybox
rendering etc.
Audio System
The audio system consists of an audio engine. It uses the irrKlang library to load
and play 2d as well as 3d sounds. It provides interfaces to other systems to
manage the audio data and play them.
Window Renderer Technique
Normal3d Skin3d ...
Model Mesh Sprite Skybox
P a g e | 10
Scene Management & Gaming System
The scene management system is the heart of the game where a game world is
represented by a scene. It interacts with other systems to produce final output. It
consists of following different classes.
Scene : A scene is a collection of 2-d, 3-d and billboard units. It is also attached
with a camera and a skybox. It provides features for text handling as well. The
Scene class is responsible for managing, updating and rendering each unit. Further
it provides some basic algorithms like ray-picking and checking potential collision
with the help of collision system. It is also responsible for managing QuadTree
The GameScene inherits from the Scene class. The GameScene is responsible for
actual 3-d game while the normal Scene class is used for menus and splash
screens only.
Unit : A unit represents a 3-d object with position, rotation, a model and
animation attached to it and other parameters. Each unit also have a bounding
volume that is used for collision detection. Buildings as WorldObject class and
Ground inherits from Unit class.
LiveUnit : A LiveUnit inherits from Unit to provide a dynamic 3-d object which
changes its position and rotation frequently. Such units need to be updated in
quadtree and scene frequently and are thus managed as separated class. Player,
Zombie and People inherits from LiveUnit class.
Unit2d : A unit2d represents a 2-d object. These are used for Heads-Up Display
(HUD) and menu items. They are attached to a sprite.
BillboardUnit : It represents a billboard object that has a 3d-position but a 2-d
sprite attached to it.
Camera : A camera is responsible for managing view and projection
transformations. It further stores a frustum that represent the camera-view which
is used for culling during rendering. A TPCamera class inherits from Camera class
to represent a third person camera.
WorldMap : It is responsible for loading map files.
P a g e | 11
Game : The Game class creates and manages player, zombie, map and other
game objects, assign them to GameScene and updates and renders the entire
scene. It also checks inputs and take appropriate actions.
Following sections describe in further detail some concepts used in the gaming
and scene management system.
Overall Game Flow
The overall game flow is presented in following flowchart.
Game Scene
Game Scene
Unit2d Unit
Live Unit
Player Zombie
World Object
Ground
Camera
TPCamera
Billboard Unit
World map
Credits
Display credits
End
Splash Screen
Load Game Resources
Main Menu
Provide various
options
Reset
Reset units’ positions,
load map, reset
animations etc.
Game
Start updating and
rendering game scene
START
New
Game
Continue
Exit
Credits
ESC
ESC
P a g e | 12
Main Game Flow
The main game starts (in case of new game) by loading the level map and
resetting units. Each unit is reset in its position, animation and status. Then a
continuous loop of update and draw is executed. Each update updates the entire
scene and its units as well as the camera. Zombie AI and player inputs are
processed in the update stage. A level completion reloads and reset the game with
new level map.
START
Load Level
Map
Reset Units
Zombie->Take Hit
Player->Shoot
Hit
Zomb
People->Die
Hit
Peopl
Player
Movement
Update
Zombie AI
Update Player
Update
Camera and
Scene
Draw Scene
END
Level
Complete
?
Game
Won/Lost
?
P a g e | 13
Zombie AI
The zombie has an AI that simulates its states as shown in following diagram.
The zombie starts in wandering state, where it is just walking avoiding obstacles.
In case the player or a civilian comes into view, it starts chasing it as target. The
target may get out of view, in which case, it restarts wandering, or may actually
meet up with zombie when it starts attacking. If target get out of reach, it starts
chasing target again and if the target is dead, it starts wandering.
The chase and obstacle avoidance are two important parts of this simulation. To
simulate such AI, the technique of Potential Function is used. The Lenard-Jones
potential function gives force between two molecules, given by
Where r is distance, A is attraction coefficient and B is repulsion coefficient and n
and m controls the attenuation of force. By controlling parameters A, B, n and m
we can appropriately find force (or displacement) to move the zombie to simulate
attraction towards target and repulsion from obstacles.
Wandering
Chasing Attack
Target in view
Target out of
view
Target in
reach
Meet target
Target dead
Target out of
reach
P a g e | 14
The collision detection system also makes the zombie avoid the obstacles, or
prevents the zombie from penetrating into obstacles.
Collision System
The collision system provides algorithms to detect and resolve collision between
objects. It consists of following classes.
Box : Represents a 3-d box with center and extents. It provides algorithms to
detect collision between two axis-aligned and rotated boxes. For rotated boxes, it
uses Separating Axis Test (SAT) to detect for intersection.
Ray : Represents a 3-d ray with origin and direction. It provides algorithms to
detect collision with axis-aligned and rotated box.
Frustum : Represents a frustum used by camera to cull away unnecessary objects
while rendering.
Plane : Represents a plane in 3-d with normal and distance from origin. It is used
by Frustum class and has algorithm to find the distance to a point.
QuadTree : Represents a tree of rectangles where each rectangle is a piece of
world and has further rectangles. It is used for speeding up collision detection.
Collision detection is a slow process since each object needs to be tested with
every other object in the scene for collision. To speed up this process, quad-tree is
used.
Quadtree Box Ray Plane Frustum
P a g e | 15
QuadTree
The quad-tree is actually a square that covers the whole scene. The scene is
further divided into four squares of equal area. Each square is further divided as
per the number of objects it holds. When an object needs to detect collision, the
square where it lies is first determined and then collision is tested for every other
object in that square.
A Quad Tree
Example
P a g e | 16
Conclusion
This project was a big challenge to us; by working on this project, we were able to
sharpen our programming skills, learn to work as a team, knew how to do high
quality graphics rendering and many other things as well. We knew a lot of other
things and gained some fine experience on Object-oriented Programming. We
enjoyed doing this project and at the same time learned a lot too.
P a g e | 17
Reference
Wikipedia (www.wikipedia.org)
OpenGL reference (www.opengl.org)
irrKlang documentation (www.ambiera.com/irrklang)
The OpenGL Programming Guide – 8th
Edition
MSDN documentation for Visual Studio
Real-Time Collision Detection – Christer Ericson
Collision Detection In Interactive 3D Environments – Gino Van Den Bergen
3D Game Engine Architecture – David H. Eberly