FallSimulator/FallSimulation.cpp

144 lines
2.9 KiB
C++
Raw Normal View History

2019-09-13 14:43:18 +03:00
#include <TXLib.h>
2019-09-20 15:08:09 +03:00
#include <iostream>
using namespace std;
int middleX;
int middleY;
int extentX;
int extentY;
2019-09-23 15:35:44 +03:00
struct Button {
RECT coords;
const char* text;
HDC picture;
};
2019-09-20 15:08:09 +03:00
void background(COLORREF color);
void drawMenu();
2019-09-23 15:35:44 +03:00
void drawButton(Button but);
void loadingAnimation(int delay);
void mainFunc();
2019-09-20 15:08:09 +03:00
int main()
{
txCreateWindow(1300, 600);
middleX = txGetExtentX() / 2;
middleY = txGetExtentY() / 2;
extentX = txGetExtentX();
extentY = txGetExtentY();
background(TX_WHITE);
txSleep(50);
txBegin();
2019-09-23 15:35:44 +03:00
txSleep(50);
loadingAnimation(10);
txSleep(1000);
2019-09-20 15:08:09 +03:00
drawMenu();
txEnd();
txDisableAutoPause();
}
void background(COLORREF color)
{
txSetFillColor(color);
txClear();
}
2019-09-23 15:35:44 +03:00
void drawButton(Button but)
{
//drawing button
txRectangle(but.coords.left,
but.coords.top,
but.coords.right,
but.coords.bottom);
//drawing text
txDrawText (but.coords.left,
but.coords.top,
but.coords.right,
but.coords.bottom,
but.text);
}
2019-09-20 15:08:09 +03:00
void drawMenu()
{
2019-09-23 15:35:44 +03:00
//button "Play"
Button buttonPlay = {
{
middleX - 100, extentY / 3 - 50,
middleX + 100, extentY / 3 + 50
}, "Play"
2019-09-20 15:08:09 +03:00
};
2019-09-23 15:35:44 +03:00
//button "Exit"
Button buttonExit = {
{
middleX - 100, extentY / 2 - 50,
middleX + 100, extentY / 2 + 50
}, "Exit"
2019-09-20 15:08:09 +03:00
};
txSetColor(TX_BLACK, 3);
txSetFillColor(TX_WHITE);
2019-09-23 15:35:44 +03:00
drawButton(buttonPlay);
drawButton(buttonExit);
2019-09-20 15:08:09 +03:00
txSleep(50);
while (!GetAsyncKeyState('Q')) {
2019-09-23 15:35:44 +03:00
if (In(txMousePos(), buttonPlay.coords) && txMouseButtons() & 1) {
2019-09-20 15:08:09 +03:00
while (txMouseButtons() & 1) {
txSleep(10);
}
2019-09-23 15:35:44 +03:00
loadingAnimation(18);
txSleep(50);
mainFunc();
2019-09-20 15:08:09 +03:00
txMessageBox("������ ���� ���� ��� �� ��������!", "������");
}
2019-09-23 15:35:44 +03:00
if (In(txMousePos(), buttonExit.coords) && txMouseButtons() & 1) {
2019-09-20 15:08:09 +03:00
while (txMouseButtons() & 1) {
txSleep(10);
}
break;
}
}
}
2019-09-23 15:35:44 +03:00
void loadingAnimation(int delay)
{
background(TX_WHITE);
for (int circle_radius = 0;
circle_radius * circle_radius < extentX * extentX + extentY * extentY;
circle_radius += 3) {
txSetColor(TX_BLACK, 2);
txSetFillColor(TX_BLACK);
txCircle(0, 0, circle_radius);
txSleep(delay);
}
background(TX_WHITE);
}
void mainFunc()
{
HDC block = txLoadImage("pictures\\block.bmp");
HDC quest = txLoadImage("pictures\\question.bmp");
txBitBlt(txDC(), extentX - 60, 0, 60, 60, block);
txBitBlt(txDC(), extentX - 60, 60, 60, 60, quest);
}