TRIBHUVAN UNIVERSITY INSTITUTE OF ENGINEERING LAB REPORT ON Experiment Date: Submission Date: Submitted by: Submitted to: Department of Acknowledgment The sensation and final upshot of this project required a lot of guidance and assistance from many people and we are exceptionally honored to have got this all along the completion of our project. All that we have done is only due to such supervision and assistance so we would like to express our sincere and earnest gratitude to all individuals who granted their helping hands to accomplish our project timely and efficiently. Firstly, we would like to express our sincere gratitude to our lecturer for providing such an splendid opportunity to do the project work in C++ and giving us all support and guidance which made us accomplish the project duly. We are extremely thankful to him for providing such a nice support and guidance. We owe our deep gratitude to all our classmates and friends who took keen interest on our project work and guided us all along, till the completion of our project work by providing all the necessary information for developing a good system. We are thankful to and fortunate enough to get constant encouragement, support and guidance from our senior brothers and sisters which helped us in successfully completing our project work. Also, we would like to extend our sincere esteems to the Department of Electronics and Computer Engineering for granting us such a platform of doing project work. So we would like to express our sincere gratitude to our teachers to provide us with such an challenging task which would enhance our skills and our knowledge related to the Object Oriented Programming. Abstract This project work was given to us as a minor project for our academic session B.E. (Computer) Second Year First Part as prescribed in the syllabus designed by IOE, TU. The main aim of this project was to develop a user-friendly program using an Object Oriented Programming language, C++. For this project we made a classic shooter game where two players try to eliminate each other. The rule for playing this game is very easy as it doesn’t have too many rules and regulations that users have to follow. Each player can jump and shoot on desired direction. Health of a player decreases by 10 when hit by a bullet shooted by enemy i.e. the player on the 1 same network in another computer. When the health of the player becomes zero, the player dies and the game is finished displaying which player wins. Table of Contents Objectives Ошибка! Закладка не определена. Introduction 3 Application 3 Literature survey 4 Existing System 3 Methodology 3 Implementation 3 Block diagram 9 Results 3 Problems Faced and Solutions 3 2 Limitations and Future Enhancements 3 Conclusion and Recommendations 3 References 3 Objectives The main objectives regarding our project are as follows: ❖ To create a project on Object Oriented Programming (OOP) to make its concept clearer. ❖ To explore the features of C++ language. ❖ To be familiar with resource reusability by making user defined header files. ❖ To learn the basics of game development and game physics. ❖ To be familiarized with graphics programming and game development using SFML in C++ programming language. ❖ To build an attractive UI for the users to help them interact easily with our game. ❖ To optimize program in terms of time and space up to greatest extent as possible. ❖ To make us able to work in major projects in coming future. ❖ To learn to work in a team. Introduction Kurukshetra, which literally means battleground, is a 2D shooter game where two players connected through a local network fight for their glory. Each player is provided with a fully loaded gun. The game requires either player to kill the other one to finish the game. It is one of the common games often played among friends. 3 Addressing the uprising technology in the today’s world, we considered making a game to play in a common network in a place. The name is inspired by a mythological place “Kurukshetra”, where the historic war occured “Mahabharat” occurred between Kauravas and Pandavas. Portraying the same war scenario in the modern approach, the two players fight each other for life. Application This program has wide range of opportunities in the real world application. As we are just beginners in the field of game development, our project might not compete with the program made by the mainstream developers. But it might serve as a way to entertainment. The program might not be much enticing graphically but will be efficient enough to provide visual aid to enjoy the game while playing. As for the system, it will just appear as a clone of the many programs that have been developed till date. In gist, this program will introduce this challenging game to those who like shooting game in a LAN. Literature survey Since this project is based on the application of Object Oriented Programming concept, different books were suggested to refer by the teachers for the OOP concept. The books like "The secrets of object oriented programming" were referred OOP as reference for the development of program that assisted us to clear the concepts regarding the language and make our program development easier. For implementing the graphics in our project, we have use SFML and for this, different e-books were referred and different video tutorials from YouTube were viewed. Similarly, the networking part was quite challenging. Various books, online documentations were consulted for the purpose. The book “Computer Network- A Top Down Approach” proved to be much helpful for the concept of the application layer, Transport layer, Sockets, types of Internet protocols, modes of connection of two nodes. Existing System At present, there are many similar games at various online platforms with different names. The most widely used version of this game is ‘Doodle Army 2: 4 Mini Militia’ by Miniclip.com for Android and iOS. Similarly, ‘Gang Beast’ by BoneLeaf is of similar type for PC. Methodology This project is based on C++ programming language utilizing SFML graphics library, and “Object Oriented Programming” concept. Different classes were created with required number of private and public member data and member functions for smooth running of the program preserving the concept of data hiding. The concept of code reusability, data abstraction were implemented in the project. The events for each object was handled by the different member functions and that they formed a final outlook working together simultaneously. C++ has the capability to manage the memory allocation/deallocation on any objects that we've created which can increase the performance of our game. Game is performance critical software that requires 100% usage of the hardware user has, and C++ is only popular language that gives you such abilities: ● High abstraction level - fine Object oriented programming and generic programming ● Very good and deterministic control of the resources you use. ● Ability to optimize special parts to very high level that is almost impossible to achieve with other popular languages. The strength of C++ when it comes to game development is the ability to exactly layout the data-structures that your software will use. C++ provides the ability to override important performance bottlenecks such as memory allocation. It has the ability to structure and place things exactly where they want in the memory. On top of this it's a flexible programming language that provides a decent development velocity. This project needed the concept of graphics but since we only had the knowledge of C++ graphics which may not fulfill the required objectives of our project having limited features. For development of the game, we used SFML which has high resolution which can definitely fulfill the objective of our project. So, we started learning SFML through various sites and e-books and understand the basic 5 gaming logic though various gaming sites and forums along with the books regarding C++ and object oriented programming itself. Then we had to decide the right compiler and IDE. So, we decided to CLion by JetBrains as IDE, which uses GCC compiler and GDB as debugger. For the graphics and other game related works, we decided to use the latest version of SFML library i.e. version 2.5.1. After collecting necessary materials, we developed the algorithm of our project and we worked according to it. The coding has been done according to the basic idea of OOP. We have created various classes and related functions and data binding has been used. All the features of C++ like objects, classes, data abstraction and encapsulation, polymorphism, message passing etc. has been used. SFML is used for various modules: system module for vector and Unicode string classes, portable threading and timer facilities, window module for window and input device management including support for joysticks, OpenGL context management, graphics module for the hardware acceleration of 2D graphics including sprites, polygons and text rendering, audio module for the hardware accelerated spatialized audio playback and recording and network module for the TCP, data encapsulation facilities. Mainly in the program, these classes are used, serving their own purposes: 1. Animation: This solely handles all the animation of both player and enemy at every state of their gameplay. 2. Bullet: This is the basic definition of the bullets rendered during the game. It includes, bullet velocity, bullet number, bullet direction etc. 3. Camera: This is the class which handles the camera movement during the game. 4. Collider: Various collision detection during the game will be handled and managed by this class. 5. Enemy: This represent the enemy of the main player whose events are handled by the socket communication. 6 6. Game: This is the main Game window class which exists throughout the game and runs every loops of updating and drawing the objects in the screen. 7. GameClient: This is the class which acts as the client i.e. receives the information from the server at the other node. 8. GameServer: This is the class which acts as the server i.e. sends the data and information to the client at the other side. 9. IpEnter: Each users are said to enter their respective ip address and see others in this class. 10. MainMenu: This class handles the main menu of the game. This is the first window seen in the game. 11. Platform: This is the class representing the walking basement and the walls in the game arena. 12. Player: This is the class which contains the attributes and methods of the player in the game. 13. ResourceHolder: This is a template class which handles all resource management of the game. It loads textures, fonts, sounds etc. required for the game. The programming methods we’ve used can as summarized below: ● Analyzing the concept that can be used to develop proper program. ● Discussion on the topic that might be faced onwards. ● Making the project schedule. ● Initial coding for creating logic. ● Coding the program. ● Execution and testing the program. ● Debugging. ● Program Documentation. Implementation The game starts with the menu that consists of Play Game, About and Exit. ● Play Game: This takes user to a screen where he is shown his IP Address and is asked to enter the IP Address of the Player with whom he/she is going to play the game along with the option of being either Player 1 or Player 2. 7 After entering the valid IP Addresses and selecting the player number, which is complementary to each other, the user is taken to a window where there is an arena with the other player waiting to kill him. Each player has health 100 when he/she is spawned and each bullet of the opponent reduces health by 10. The player which can reduce the health of other player to 0 wins the game. And the game successfully ends. ● About: This takes user to a screen where he/she can see information about the developers of the game i.e. us. ● Exit: This allows user to close the program. In overall, the following methods were implemented for the completion of the project, which is regarded as the basic steps for developing the software and listed as follows,: ● Study, research and analysis: Gathering information about the topic of the project. ● Proposal submission: Documenting the information about the project was carried out before starting the coding. ● Designing of the layout of the project: Proper positioning of the components required for the project was designed properly. ● Coding: Coding of the project was done as mentioned in the proposal. ● Testing, modification and Documentation: Project is tested and modified continuously as per requirement to make it more attractive and error free. 8 Block diagram Main Game Arena Keys UI Generate Generate Position Position Weapon Weapon Control Server Socket: sends info to Threa ClientSocket: Recieves info Threa Netw Results With the completion of the project, the objective of the project was achieved and the game was designed and completed as per the requirement. The complete game was designed with the necessary features. The main objective for the development of this game was fulfilled, but still some features in this game could not be completed which might be due to the time constraint, and also, this is the learning phase due to which much time was spent on learning the subject matter as the topic was completely unknown before the starting of project. From this project, we can take positives as we achieved the cooperation between the team members, learnt to work in a team, backing up each other in need and also the challenges to develop the software by developing this small gaming program. Problems Faced and Solutions This project was completed on time with lots of effort. Although the project was completed on time, many problems and errors were faced during the development 9 of the game and solutions to the problems were obtained by discussing with friends and teachers and thorough study of the codes finally made the game error free. The major problems that occurred during the development of program can be listed as follows: ● As SFML graphics library was completely new for us, we had to go through the e-books and video tutorials related to this library and check and the codes time and again. ● We faced problems while sending the information of player from one computer to another, since Socket Programming was completely new to us which was solved later by taking information from different websites and the documentation of SFML itself. ● We had difficulty in implementing physics in game like parabolic path for jumping of players and bullet and collision of bullet and player which was resolved by reading different reference materials related to game physics. ● We had difficulty in finding the appropriate sprites and textures i.e. background and platforms like walls. ● We had problems related to graphics options. We were not known to various graphics function and their workings. ● We had great difficulties in developing proper logic due to lack of proper reference materials. ● Problems occurred while merging the code from different members like linking the main game with the main menu. The function in one could not be called from the other. Limitations and Future Enhancements As we’ve completed the game in limited amount of time, many more features can be added to make the game more attractive and more popular among users in the competitive market. The following features can be added to our project: ● The game can be extended for multiple players to play in LAN and network peer discovery could also be added. ● This game could be enhanced by adding arenas and the players could be respawned after a certain period of time and rejoin the game until the time for the game is finished. 10 ● Weapon types could be added. Different types of guns and bombs could add beauty to the game. ● Different types of obstacles could be added and player could be made to fly using the booster for a certain period of time. ● Tournament type game play can be designed to make the game more interesting using different levels of AI. Conclusion and Recommendations This project was unquestionably a good way of learning and implementing the way for programming practice. This project leads us to the winding up on the programming practice that for developing software a good judgment and proper analysis of the topic is required at first rather than the coding. The coding is not the initial step for emergent of any program, rather a good planning on the basic framework and making decision on the way of implementing the program is the most. After the coding of the program the system may not be as per our requirement but debugging, if any error, and testing and execution of the program are furthermore required. After the completion of the system, its management takes, is another most required obsession that is to be handled with great care. Also on using the graphics we might have to load different images for different purpose so proper discussion and proper decision is required as per the situation emerges. Thus, after the completion of our project, we can conclude proper judgment and implementation of the problems or topic leads to the good programming practice which might lead to have desired output. References ● Robert Lafore, “Object Oriented Programming with C++”, Sams Publication ● Daya Sagar Baral and Diwakar Baral, “The Secrets of Object oriented Programming”, Bhundipuran Prakasan ● Harvey M. Dietel and Paul J. Dietel, “C++ How to program”, Pearson Education Inc. ● James Kurose and Keith Ross, “Computer Networking: A Top-Down Approach”, Pearson Education 11 ● Jan Haller and Henrik Vogelius Hansson, “SFML Game Development”, Packt Publishing ● https://www.sfml-dev.org/tutorials/2.5/ 12