Advertisement
baadgeorge

сорс

Jun 3rd, 2021
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.31 KB | None | 0 0
  1. # pragma once
  2. #include <windows.h>
  3. #include <conio.h>
  4. #include <iostream>
  5. #include <ctime>
  6. #include "Classes.h"
  7.  
  8. using namespace std;
  9.  
  10. #define KEY_DOWN(vk_code)((GetAsyncKeyState(vk_code)) & 0x8000 ? 1 : 0)
  11.  
  12. void PressKey(int VkCode);
  13.  
  14. void WheelCollision(Point** _Projectile, Grinder* _Grinder, Catcher* _Catcher, int _Key, int ScaleProjectile); //функция проверки столкновения обекта с колесом
  15.  
  16. HDC hdc;
  17.  
  18. int main()
  19. {
  20.     int X_0 = 300; //начальные координаты по Х
  21.     int Y_0 = 0; //начальные координаты по Y
  22.     int Scale_0 = 1; //масштаб
  23.     int randKey = 0; //ключ двигающегося объекта
  24.     double Angle_0 = 30.0; //начальный угол колеса
  25.     double current_Angle; //текущий угол колеса
  26.     double Angle_step = 10.0; //шаг угла поворота
  27.     int Step = 20; //шаг перемещения
  28.     system("color F0");
  29.  
  30.     srand(time(NULL)); // задание зерна генеатора случайных чисел
  31.  
  32.     HWND hwnd = GetConsoleWindow();
  33.  
  34.     if (hwnd != NULL)
  35.     {
  36.         hdc = GetWindowDC(hwnd);
  37.         if (hdc != 0)
  38.         {
  39.             Grinder _Grinder(X_0, Y_0, Scale_0, Angle_0);
  40.             //Rock* _Rock = NULL;
  41.             Point* _Projectile = NULL; //указатель на объект взаимодействия
  42.             //WAVE* Wave = NULL;
  43.             //HEALTH_MODE* Health = NULL;
  44.             River _River(X_0, Y_0, Scale_0);
  45.             Catcher _Catcher(X_0, Y_0, Scale_0);
  46.  
  47.             while (1)
  48.             {
  49.  
  50.                 if (KEY_DOWN(VK_ESCAPE))
  51.                     break;
  52.                 _River.Show(); //вывод на экран реки
  53.  
  54.                 _Grinder.Show(); //вывод на экран мельницы
  55.  
  56.                 if (_Projectile == NULL)
  57.                 {
  58.                     randKey = rand() % 3; //генератор случайного числа от 0 до 2
  59.                     if (randKey == 0) _Projectile = new Rock(X_0, Y_0, Scale_0);
  60.                     else if (randKey == 1) _Projectile = new Wave(X_0, Y_0, Scale_0);
  61.                     else if (randKey == 2) _Projectile = new Health_mode(X_0, Y_0, Scale_0);
  62.                 }
  63.  
  64.                 if (_Grinder.GetRotation() == true)
  65.                 {
  66.                     current_Angle = _Grinder.GetAngleWH(); //получение текущего угла поворта
  67.  
  68.                     if (current_Angle < 90.0)
  69.                     {
  70.                         current_Angle += 10.0;
  71.                     }
  72.                     else current_Angle = 0;
  73.  
  74.                     _Grinder.SetAngleWH(current_Angle); //задание текущего угла поворта
  75.                 }
  76.  
  77.                 _Projectile->Show(); //отображения объекта взаимодействия
  78.                
  79.                 _Catcher.Show(); //отображения ловца
  80.                
  81.                 _Catcher.Drag(30); //перемещение ловца
  82.  
  83.                 WheelCollision(&_Projectile, &_Grinder, &_Catcher, randKey, Scale_0); //проверка взаимодействия
  84.  
  85.                 if (_Projectile != NULL) _Projectile->MoveTo(_Projectile->GetX() + Step, _Projectile->GetY());
  86.  
  87.                 Sleep(100);
  88.                 _Grinder.Hide(); //скрытие меьницы
  89.                 _River.Hide(); //скрытие реки
  90.                 if (_Projectile != NULL) _Projectile->Hide(); //скрытие объекта взаимодествия, если он существует
  91.             }
  92.         }
  93.     }
  94. }
  95.  
  96.  
  97. void PressKey(int VkCode)
  98. {
  99.     while (1)
  100.     {
  101.         if (KEY_DOWN(VkCode))
  102.         {
  103.             break;
  104.         }
  105.     }
  106. }
  107.  
  108. void WheelCollision(Point** _Projectile, Grinder* _Grinder, Catcher* _Catcher, int _Key, int ScaleProjectile) //функция проверки столкновения обекта с колесом
  109. {
  110.     if ((*_Projectile)->GetX() > 890)
  111.     {
  112.         if (_Key == 0) _Grinder->SetRotation(false);
  113.         if (_Key == 2) _Grinder->SetRotation(true);
  114.         delete (*_Projectile);
  115.         (*_Projectile) = NULL;
  116.         return;
  117.     }
  118.  
  119.     int xProjectile = (*_Projectile)->GetX();
  120.     int yProjectile = (*_Projectile)->GetY();
  121.  
  122.     int xCatcher = _Catcher->GetX();
  123.     int yCatcher = _Catcher->GetY();
  124.  
  125.     int ScaleCatcher = _Catcher->GetScale();
  126.  
  127.     bool c1 = (xProjectile - 150 * ScaleProjectile) < (xCatcher + 20 * ScaleCatcher);
  128.     bool c2 = (xProjectile - 100 * ScaleProjectile) > (xCatcher - 20 * ScaleCatcher);
  129.     bool c3 = (yProjectile + 340 * ScaleProjectile) < (yCatcher + 390 * ScaleCatcher);
  130.     bool c4 = (yProjectile + 380 * ScaleProjectile) > (yCatcher + 330 * ScaleCatcher);
  131.  
  132.     if (c1 && c2 && c3 && c4) //если области ловца и объекта наложились
  133.     {
  134.         delete (*_Projectile);
  135.         (*_Projectile) = NULL;
  136.     }
  137.  
  138.     return;
  139. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement