Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # pragma once
- #include <windows.h>
- #include <conio.h>
- #include <iostream>
- #include <ctime>
- #include "Classes.h"
- using namespace std;
- #define KEY_DOWN(vk_code)((GetAsyncKeyState(vk_code)) & 0x8000 ? 1 : 0)
- void PressKey(int VkCode);
- int WheelCollision(Point** _Projectile, Grinder* _Grinder, Catcher* _Catcher, int _Key, int ScaleProjectile); //функция проверки столкновения обекта с колесом
- HDC hdc;
- int main()
- {
- int X_0 = 300; //начальные координаты по Х
- int Y_0 = 0; //начальные координаты по Y
- int Scale_0 = 1; //масштаб
- int randKey = 0; //ключ двигающегося объекта
- double Angle_0 = 30.0; //начальный угол колеса
- double current_Angle; //текущий угол колеса
- double Angle_step = 10.0; //шаг угла поворота
- int Step = 20; //шаг перемещения
- system("color F0");
- srand(time(NULL)); // задание зерна генеатора случайных чисел
- HWND hwnd = GetConsoleWindow();
- if (hwnd != NULL)
- {
- hdc = GetWindowDC(hwnd);
- if (hdc != 0)
- {
- Grinder _Grinder(X_0, Y_0, Scale_0, Angle_0);
- GrinderDamage _GrinderDamage(X_0, Y_0, Scale_0, Angle_0);
- Grinder* BufGrinder[2];
- BufGrinder[0] = &_Grinder;
- BufGrinder[1] = &_GrinderDamage;
- Grinder* pCurrGrinder = BufGrinder[0];
- //Point* _Projectile = NULL; //указатель на объект взаимодействи
- Point* BufProjectile[3];
- BufProjectile[0] = (Point*) new Rock(X_0, Y_0, Scale_0);
- BufProjectile[1] = (Point*) new Wave(X_0, Y_0, Scale_0);
- BufProjectile[2] = (Point*) new Health_mode(X_0, Y_0, Scale_0);
- Point* pCurrProjectile = BufProjectile[0];
- River _River(X_0, Y_0, Scale_0);
- Catcher _Catcher(X_0, Y_0, Scale_0);
- while (1)
- {
- if (KEY_DOWN(VK_ESCAPE))
- break;
- _River.Show(); //вывод на экран реки
- pCurrGrinder->Show(); //вывод на экран мельницы
- if (pCurrGrinder->GetRotation() == true)
- {
- current_Angle = pCurrGrinder->GetAngleWH(); //получение текущего угла поворта
- if (current_Angle < 90.0)
- {
- current_Angle += 10.0;
- }
- else current_Angle = 0;
- pCurrGrinder->SetAngleWH(current_Angle); //задание текущего угла поворта
- }
- pCurrProjectile->Show(); //отображения объекта взаимодействия
- _Catcher.Show(); //отображения ловца
- _Catcher.Drag(30); //перемещение ловца
- if (pCurrProjectile != NULL) pCurrProjectile->MoveTo(pCurrProjectile->GetX() + Step, pCurrProjectile->GetY());
- int res = WheelCollision(&pCurrProjectile, pCurrGrinder, &_Catcher, randKey, Scale_0); //проверка взаимодействия
- if (res == 1)
- {
- //pCurrGrinder = BufGrinder[1];
- pCurrProjectile->Hide();
- randKey = rand() % 3; //генератор случайного числа от 0 до 2
- if (randKey == 0) pCurrProjectile = BufProjectile[0];
- else if (randKey == 1) pCurrProjectile = BufProjectile[1];
- else if (randKey == 2) pCurrProjectile = BufProjectile[2];
- }
- if (res == 2)
- {
- }
- Sleep(100);
- pCurrGrinder->Hide(); //скрытие меьницы
- _River.Hide(); //скрытие реки
- //if (_Projectile != NULL) _Projectile->Hide(); //скрытие объекта взаимодествия, если он существует
- }
- }
- }
- }
- void PressKey(int VkCode)
- {
- while (1)
- {
- if (KEY_DOWN(VkCode))
- {
- break;
- }
- }
- }
- int WheelCollision(Point** pCurrProjectile, Grinder* _Grinder, Catcher* _Catcher, int _Key, int ScaleProjectile) //функция проверки столкновения обекта с ловцом или колесом
- {
- if ((*pCurrProjectile)->GetX() > 890)
- {
- if (_Key == 0) _Grinder->SetRotation(false);
- if (_Key == 2) _Grinder->SetRotation(true);
- //delete (*pCurrProjectile);
- //(*pCurrProjectile) = NULL;
- return 1;
- }
- int xProjectile = (*pCurrProjectile)->GetX();
- int yProjectile = (*pCurrProjectile)->GetY();
- int xCatcher = _Catcher->GetX();
- int yCatcher = _Catcher->GetY();
- int ScaleCatcher = _Catcher->GetScale();
- bool c1 = (xProjectile - 150 * ScaleProjectile) < (xCatcher + 20 * ScaleCatcher);
- bool c2 = (xProjectile - 100 * ScaleProjectile) > (xCatcher - 20 * ScaleCatcher);
- bool c3 = (yProjectile + 340 * ScaleProjectile) < (yCatcher + 390 * ScaleCatcher);
- bool c4 = (yProjectile + 380 * ScaleProjectile) > (yCatcher + 330 * ScaleCatcher);
- if (c1 && c2 && c3 && c4) //если области ловца и объекта наложились
- {
- return 2;
- }
- return 2;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement