Advertisement
Felanpro

Shooting game fundementals

Mar 14th, 2019
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.42 KB | None | 0 0
  1. #include "pch.h"
  2. #include <iostream>
  3. #include <conio.h>
  4. #include <Windows.h>
  5.  
  6. using namespace std;
  7.  
  8. int projectileX;
  9. int projectileY;
  10.  
  11. int objectX = 5;
  12. int objectY = 5;
  13.  
  14. int playerX = 2;
  15. int playerY = 9;
  16.  
  17. bool shooting_time = false;
  18.  
  19. void draw_playBoard()
  20. {
  21.     for (int y = 0; y < 10; y++)
  22.     {
  23.         for (int x = 0; x < 6; x++)
  24.         {
  25.             if (x == playerX && y == playerY)
  26.             {
  27.                 cout << "X";
  28.             }
  29.             else if (x == projectileX && y == projectileY)
  30.             {
  31.                 cout << "o";
  32.             }
  33.             else if (x == objectX && y == objectY)
  34.             {
  35.                 cout << "V";
  36.             }
  37.             else
  38.                 cout << " ";
  39.         }
  40.         cout << endl;
  41.     }
  42.     system("cls");
  43. }
  44.  
  45. void shoot()
  46. {
  47.     if (_kbhit())
  48.     {
  49.         char input_variable;
  50.         input_variable = _getch();
  51.  
  52.         if (input_variable == 's')
  53.         {
  54.             shooting_time = true;
  55.             projectileX = playerX;
  56.             projectileY = playerY - 1;
  57.         }
  58.         else if (input_variable == 'd')
  59.         {
  60.             playerX++;
  61.         }
  62.         else if (input_variable == 'a')
  63.         {
  64.             playerX--;
  65.         }
  66.     }
  67. }
  68.  
  69. void increase_projectile()
  70. {
  71.     if (shooting_time == true)
  72.     {
  73.         projectileY--;
  74.         Sleep(30);
  75.     }
  76.     else
  77.         ;
  78. }
  79.  
  80. void logic()
  81. {
  82.     int x_position_of_object = objectX;
  83.     if (projectileX == objectX && projectileY == objectY)
  84.     {
  85.         while (objectX == x_position_of_object)
  86.             objectX = rand() % 5;
  87.     }
  88. }
  89.  
  90. int main()
  91. {
  92.     while (1)
  93.     {
  94.         draw_playBoard();
  95.         shoot();
  96.         increase_projectile();
  97.         logic();
  98.     }
  99.  
  100.     int pause; cin >> pause; //Pause the program
  101. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement