Shooting Game - Using C Programming Language









After I started programming a simple game, I wanted to make a shooting game and finally got an idea of this one where I have used same concept like in "Dinosaur Game". The main objective, in this game, is to dodge the bullets shoot by enemy and shoot the enemy. The maximum number of bullets that the user/ player can shoot at a time is three. In order to win the game, player need to play the game until the health of enemy become zero.

 

How to download source code?

  • Click here for source code.
  • New window will open where there is a source code of this project. Download all the files.

 

Demo of the game

Check out the following video for the demo of this project.

 

For more source code and tutorial, SUBSCRBE to my YouTube channel.

 

Development platform

Computer programming language has been used to develop this project.

 

Compiler

Dev C++ and Turbo C++ has been used as compiler whose versions are 5..11 and 3.7.8.9 respectively.

 

Header files used

The header files used in this project are as follows :

  1. Conio
  2. Graphics
  3. Stdio
  4. Time

 

Library functions

The following library functions has been used :

  1. Under conio header file
    1. Clrscr
    2. Getch
    3. Kbhit
  2. Under graphics header file
    1. Initgraph
    2. Bar
    3. Closegraph
    4. Setfillstyle
    5. Settextstyle
    6. Floodfill
    7. Getpixel
    8. Outtextxy
    9. Rectangle
    10. Floodfill
  3. Under stdio header file
    1. Printf
    2. Scanf
    3. Exit
  4. Under time header file
    1. Delay
  5. Under stdlib header file
    1. Rand

Concepts used

Topics/ concepts of this language that you need to know for making this type of game :

  1. Array
  2. Do while looping statement
  3. For looping statement
  4. If else conditional statement

 

Code logic for Turbo C++ compiler

First of all, for the movement of the player, keys 'a', 'd', 'l' have been used for the right movement, left movement and shooting respectively. The player can shoot maximum of three bullets only if no bullet shoot by player in on the screen. When a bullet is shoot, x and y coordinate is provided to the bullet whose only y-coordinate gets on decreasing.   


When the coordinates of the bullet matches with the coordinates of the enemy, its health status decreases. This mechanism is same for the bullets shoot by enemy too.


For the indication of health of  player and enemy, a rectangle and line functions have been used where on getting hit by bullet, coordinates of respective line changes and when a color is flood filled on that rectangle, it indicated health status.


This project is not a complete one, and one bad thing about this game is it can not be terminated until health is one of the player is completely low.


Code logic for Dev C++ compiler

For Dev C++ compiler, all the rules for changing of coordinates of bullet and opponents and health decrement rules are same except the control keys. Here, for left and right movement, user can press left arrow key and right arrow key respectively. Similarly, for shooting a bullet player need to press 'space' key. 

No comments:

Post a Comment

Article Ad1