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);
- void 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);
- //Rock* _Rock = NULL;
- Point* _Projectile = NULL; //указатель на объект взаимодействия
- //WAVE* Wave = NULL;
- //HEALTH_MODE* Health = NULL;
- 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(); //вывод на экран реки
- _Grinder.Show(); //вывод на экран мельницы
- if (_Projectile == NULL)
- {
- randKey = rand() % 3; //генератор случайного числа от 0 до 2
- if (randKey == 0) _Projectile = new Rock(X_0, Y_0, Scale_0);
- else if (randKey == 1) _Projectile = new Wave(X_0, Y_0, Scale_0);
- else if (randKey == 2) _Projectile = new Health_mode(X_0, Y_0, Scale_0);
- }
- if (_Grinder.GetRotation() == true)
- {
- current_Angle = _Grinder.GetAngleWH(); //получение текущего угла поворта
- if (current_Angle < 90.0)
- {
- current_Angle += 10.0;
- }
- else current_Angle = 0;
- _Grinder.SetAngleWH(current_Angle); //задание текущего угла поворта
- }
- _Projectile->Show(); //отображения объекта взаимодействия
- _Catcher.Show(); //отображения ловца
- _Catcher.Drag(30); //перемещение ловца
- WheelCollision(&_Projectile, &_Grinder, &_Catcher, randKey, Scale_0); //проверка взаимодействия
- if (_Projectile != NULL) _Projectile->MoveTo(_Projectile->GetX() + Step, _Projectile->GetY());
- Sleep(100);
- _Grinder.Hide(); //скрытие меьницы
- _River.Hide(); //скрытие реки
- if (_Projectile != NULL) _Projectile->Hide(); //скрытие объекта взаимодествия, если он существует
- }
- }
- }
- }
- void PressKey(int VkCode)
- {
- while (1)
- {
- if (KEY_DOWN(VkCode))
- {
- break;
- }
- }
- }
- void WheelCollision(Point** _Projectile, Grinder* _Grinder, Catcher* _Catcher, int _Key, int ScaleProjectile) //функция проверки столкновения обекта с колесом
- {
- if ((*_Projectile)->GetX() > 890)
- {
- if (_Key == 0) _Grinder->SetRotation(false);
- if (_Key == 2) _Grinder->SetRotation(true);
- delete (*_Projectile);
- (*_Projectile) = NULL;
- return;
- }
- int xProjectile = (*_Projectile)->GetX();
- int yProjectile = (*_Projectile)->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) //если области ловца и объекта наложились
- {
- delete (*_Projectile);
- (*_Projectile) = NULL;
- }
- return;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement