Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "pch.h"
- #include <iostream>
- #include <conio.h>
- #include <Windows.h>
- using namespace std;
- int projectileX;
- int projectileY;
- int objectX = 5;
- int objectY = 5;
- int playerX = 2;
- int playerY = 9;
- bool shooting_time = false;
- void draw_playBoard()
- {
- for (int y = 0; y < 10; y++)
- {
- for (int x = 0; x < 6; x++)
- {
- if (x == playerX && y == playerY)
- {
- cout << "X";
- }
- else if (x == projectileX && y == projectileY)
- {
- cout << "o";
- }
- else if (x == objectX && y == objectY)
- {
- cout << "V";
- }
- else
- cout << " ";
- }
- cout << endl;
- }
- system("cls");
- }
- void shoot()
- {
- if (_kbhit())
- {
- char input_variable;
- input_variable = _getch();
- if (input_variable == 's')
- {
- shooting_time = true;
- projectileX = playerX;
- projectileY = playerY - 1;
- }
- else if (input_variable == 'd')
- {
- playerX++;
- }
- else if (input_variable == 'a')
- {
- playerX--;
- }
- }
- }
- void increase_projectile()
- {
- if (shooting_time == true)
- {
- projectileY--;
- Sleep(30);
- }
- else
- ;
- }
- void logic()
- {
- int x_position_of_object = objectX;
- if (projectileX == objectX && projectileY == objectY)
- {
- while (objectX == x_position_of_object)
- objectX = rand() % 5;
- }
- }
- int main()
- {
- while (1)
- {
- draw_playBoard();
- shoot();
- increase_projectile();
- logic();
- }
- int pause; cin >> pause; //Pause the program
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement