"Dinosaur Game" is a simple game where green-bar has to jump so that it do not collide with the red-bars (obstacles). The idea of creating this game arose when I was surfing over the internet and suddenly it went down. I have tried to use simple logic used in "T-Rex Run". However, this project is just an simple idea for beginners who want to create a game. Here, user has to press 'space' key to make the green-bar jump. If the green-bar collides with the red-bars, the game gets terminated. The interesting part of this game is that, the two obstacles are reused over-and-over to reduce the size of the project.
How to download source code?
- Click here for source code.
- New window will open where there is a source code of this project.
- 'Dinosaur' folder contains the source code for Dev C++ compiler, whereas another source code is for Turbo C++ compiler.
- Remember to run this project on both Dev C++ and Turbo C++ compilers.
Demo of the game
Check out the following video for the demo of this project.
Development platform
Computer programming language has been used to develop this project.
Compiler
Both Dev C++ and Turbo C++ has been used as compiler whose versions are 5.11 and 4.9.11 respectively.
Header files used
The header files used in this project are as follows :
- Conio
- Graphics
- Stdio
Library functions
The following library functions has been used :
- Under conio header file
- Clrscr
- Getch
- Under graphics header file
- Initgraph
- Bar
- Closegraph
- Floodfill
- Line
- Setfillstyle
- Setlinestyle
- Under stdio header file
- Kbhit
- Isspace
Concepts used
Topics/ concepts of this language that you need to know for making this type of game :
- For looping statement
- If else conditional statement
- Graphics
Logic description
The x-coordinate of the green-bar remains the same, whereas the y-coordinate can be changed by pressing space key. To check whether the 'space' key has been pressed, isspace-function has been used. But, if the y-coordinate is already greater than 0, even if the user press space key, there is no effect on the y-coordinate of the green-bar.
On the other hand, the x-coordinate of both red-bars decreases with 20 pixels at a time.
If the x and y coordinate of green-bars matches with any one of the red-bars, it is the case of game termination.
The main task in this project(game) is the creation of obstacle. If code for each obstacle is written, then it would be a messy-code as it is required to check collision with each obstacles. So, I decided to reuse both bars(obstacles). Once the game starts, a x-coordinate is provided to the red-bars, and it decreases gradually. Then the point comes where the x-coordinate of first bar exceeds -800. In that case, the position of both bars is repositioned. This process gets executed again and again until the collision do not occur.
No comments:
Post a Comment