2019-09-13 14:43:18 +03:00
|
|
|
#include <TXLib.h>
|
2019-09-20 15:08:09 +03:00
|
|
|
#include <iostream>
|
2019-10-04 15:32:55 +03:00
|
|
|
#include <fstream>
|
2019-09-20 15:08:09 +03:00
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
2019-09-27 16:34:57 +04:00
|
|
|
const COLORREF MY_LIGHTBLUE = RGB(75, 127, 196);
|
|
|
|
const COLORREF MY_BISQUE = RGB(255, 214, 89);
|
2019-10-07 15:34:23 +03:00
|
|
|
|
2019-10-04 15:32:55 +03:00
|
|
|
const int BLOCK_TYPE = 0;
|
|
|
|
const int QUEST_TYPE = 1;
|
|
|
|
const int WATER_TYPE = 2;
|
|
|
|
const int FIRE_TYPE = 3;
|
2019-09-27 16:34:57 +04:00
|
|
|
|
2019-10-07 15:34:23 +03:00
|
|
|
const int MAP_LENGHT = 15;
|
|
|
|
|
2019-09-20 15:08:09 +03:00
|
|
|
int middleX;
|
|
|
|
int middleY;
|
|
|
|
|
|
|
|
int extentX;
|
|
|
|
int extentY;
|
|
|
|
|
2019-09-30 15:30:46 +03:00
|
|
|
bool gameIsStarted = false;
|
|
|
|
|
2019-09-23 15:35:44 +03:00
|
|
|
struct Button {
|
|
|
|
RECT coords;
|
|
|
|
const char* text;
|
|
|
|
HDC picture;
|
|
|
|
};
|
|
|
|
|
2019-10-04 15:32:55 +03:00
|
|
|
struct MapPart {
|
|
|
|
RECT coords;
|
|
|
|
bool visible;
|
|
|
|
HDC picture;
|
|
|
|
int blocktype;
|
|
|
|
};
|
|
|
|
|
2019-09-27 16:34:57 +04:00
|
|
|
HDC block;
|
|
|
|
HDC quest;
|
2019-10-07 15:34:23 +03:00
|
|
|
HDC water;
|
|
|
|
|
2019-09-27 16:34:57 +04:00
|
|
|
HDC orange_but;
|
|
|
|
HDC green_but;
|
|
|
|
HDC blue_but;
|
|
|
|
HDC purple_but;
|
|
|
|
|
2019-09-20 15:08:09 +03:00
|
|
|
void background(COLORREF color);
|
|
|
|
void drawMenu();
|
2019-09-27 16:34:57 +04:00
|
|
|
void drawButton(Button but, bool picture);
|
|
|
|
void loadingAnimation(int delay, int speed);
|
2019-09-23 15:35:44 +03:00
|
|
|
void mainFunc();
|
2019-09-20 15:08:09 +03:00
|
|
|
|
|
|
|
int main()
|
|
|
|
{
|
|
|
|
txCreateWindow(1300, 600);
|
2019-09-27 16:34:57 +04:00
|
|
|
|
|
|
|
block = txLoadImage("pictures\\block.bmp");
|
|
|
|
quest = txLoadImage("pictures\\question.bmp");
|
2019-10-07 15:34:23 +03:00
|
|
|
water = txLoadImage("pictures\\water.bmp");
|
2019-10-07 11:11:39 +03:00
|
|
|
//orange_but = txLoadImage("pictures\\orange-but.bmp");
|
|
|
|
//green_but = txLoadImage("pictures\\green-but.bmp");
|
|
|
|
//blue_but = txLoadImage("pictures\\blue-but.bmp");
|
|
|
|
//purple_but = txLoadImage("pictures\\purple-but.bmp");
|
2019-09-27 16:34:57 +04:00
|
|
|
|
2019-09-20 15:08:09 +03:00
|
|
|
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(1000);
|
2019-09-27 16:34:57 +04:00
|
|
|
|
|
|
|
txSetColor(MY_LIGHTBLUE, 2);
|
|
|
|
txSetFillColor(TX_WHITE);
|
|
|
|
txRectangle(0, 0, extentX, extentY);
|
|
|
|
|
|
|
|
txSetColor(MY_LIGHTBLUE, 2);
|
|
|
|
txSetFillColor(MY_LIGHTBLUE);
|
|
|
|
txRectangle(0, 0, extentX, 50);
|
|
|
|
|
|
|
|
txSetColor(TX_BLACK, 3);
|
|
|
|
txSetFillColor(TX_WHITE);
|
|
|
|
txDrawText(0, 0, extentX, 50, "����������� ������� ���� FallSimulation");
|
|
|
|
|
2019-09-20 15:08:09 +03:00
|
|
|
drawMenu();
|
|
|
|
|
|
|
|
txEnd();
|
|
|
|
|
2019-09-27 16:34:57 +04:00
|
|
|
txDeleteDC(block);
|
|
|
|
txDeleteDC(quest);
|
|
|
|
|
2019-09-20 15:08:09 +03:00
|
|
|
txDisableAutoPause();
|
|
|
|
}
|
|
|
|
|
|
|
|
void background(COLORREF color)
|
|
|
|
{
|
|
|
|
txSetFillColor(color);
|
|
|
|
txClear();
|
|
|
|
}
|
|
|
|
|
2019-09-27 16:34:57 +04:00
|
|
|
void drawButton(Button but, bool picture)
|
2019-09-23 15:35:44 +03:00
|
|
|
{
|
|
|
|
//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
|
|
|
};
|
|
|
|
|
2019-09-27 16:34:57 +04:00
|
|
|
//button "Settings"
|
|
|
|
Button buttonSets = {
|
|
|
|
{
|
|
|
|
extentX - 100, 0,
|
|
|
|
extentX , 50
|
|
|
|
}, "Settings"
|
|
|
|
};
|
|
|
|
|
2019-09-20 15:08:09 +03:00
|
|
|
txSetColor(TX_BLACK, 3);
|
|
|
|
txSetFillColor(TX_WHITE);
|
|
|
|
|
2019-09-27 16:34:57 +04:00
|
|
|
drawButton(buttonPlay, true);
|
|
|
|
drawButton(buttonExit, true);
|
|
|
|
|
|
|
|
txSetColor(TX_BLACK, 3);
|
|
|
|
txSetFillColor(TX_TRANSPARENT);
|
|
|
|
|
|
|
|
drawButton(buttonSets, false);
|
2019-09-23 15:35:44 +03:00
|
|
|
|
2019-09-20 15:08:09 +03:00
|
|
|
txSleep(50);
|
|
|
|
|
|
|
|
while (!GetAsyncKeyState('Q')) {
|
2019-09-30 15:30:46 +03:00
|
|
|
if (!gameIsStarted) {
|
|
|
|
if (In(txMousePos(), buttonPlay.coords) && txMouseButtons() & 1) {
|
|
|
|
while (txMouseButtons() & 1) {
|
|
|
|
txSleep(10);
|
|
|
|
}
|
|
|
|
|
2019-10-04 15:32:55 +03:00
|
|
|
//loadingAnimation(2, 3);
|
2019-09-30 15:30:46 +03:00
|
|
|
txSleep(50);
|
|
|
|
mainFunc();
|
2019-09-20 15:08:09 +03:00
|
|
|
}
|
2019-09-30 15:30:46 +03:00
|
|
|
if (In(txMousePos(), buttonExit.coords) && txMouseButtons() & 1) {
|
|
|
|
while (txMouseButtons() & 1) {
|
|
|
|
txSleep(10);
|
|
|
|
}
|
2019-09-20 15:08:09 +03:00
|
|
|
|
2019-09-30 15:30:46 +03:00
|
|
|
break;
|
2019-09-20 15:08:09 +03:00
|
|
|
}
|
2019-09-30 15:30:46 +03:00
|
|
|
if (In(txMousePos(), buttonSets.coords) && txMouseButtons() & 1) {
|
|
|
|
while(txMouseButtons() & 1) {
|
|
|
|
txSleep(10);
|
|
|
|
}
|
2019-09-20 15:08:09 +03:00
|
|
|
|
2019-09-30 15:30:46 +03:00
|
|
|
txSetColor(TX_BLACK, 3);
|
|
|
|
txSetFillColor(MY_BISQUE);
|
2019-09-27 16:34:57 +04:00
|
|
|
|
2019-09-30 15:30:46 +03:00
|
|
|
txRectangle(middleX - 200, middleY - 100, middleX + 200, middleY + 100);
|
|
|
|
//code
|
|
|
|
}
|
2019-09-27 16:34:57 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
txSleep(10);
|
2019-09-20 15:08:09 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-27 16:34:57 +04:00
|
|
|
void loadingAnimation(int delay, int speed)
|
2019-09-23 15:35:44 +03:00
|
|
|
{
|
|
|
|
background(TX_WHITE);
|
|
|
|
|
|
|
|
for (int circle_radius = 0;
|
|
|
|
circle_radius * circle_radius < extentX * extentX + extentY * extentY;
|
2019-09-27 16:34:57 +04:00
|
|
|
circle_radius += speed) {
|
2019-09-23 15:35:44 +03:00
|
|
|
|
2019-10-04 15:32:55 +03:00
|
|
|
background(TX_WHITE);
|
|
|
|
|
2019-09-23 15:35:44 +03:00
|
|
|
txSetColor(TX_BLACK, 2);
|
|
|
|
txSetFillColor(TX_BLACK);
|
|
|
|
|
|
|
|
txCircle(0, 0, circle_radius);
|
|
|
|
|
|
|
|
txSleep(delay);
|
|
|
|
}
|
|
|
|
|
|
|
|
background(TX_WHITE);
|
|
|
|
}
|
|
|
|
|
|
|
|
void mainFunc()
|
|
|
|
{
|
2019-09-30 15:30:46 +03:00
|
|
|
gameIsStarted = true;
|
|
|
|
|
2019-10-04 15:32:55 +03:00
|
|
|
int arrElem = 0;
|
|
|
|
|
2019-09-30 15:30:46 +03:00
|
|
|
RECT blockBut = {
|
2019-10-07 15:34:23 +03:00
|
|
|
extentX - 60, 0, extentX, 60
|
2019-09-30 15:30:46 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
RECT questBut = {
|
2019-10-07 15:34:23 +03:00
|
|
|
extentX - 60, 60, extentX, 120
|
|
|
|
};
|
|
|
|
|
|
|
|
RECT waterBut = {
|
|
|
|
extentX - 60, 120, extentX, 180
|
2019-09-30 15:30:46 +03:00
|
|
|
};
|
|
|
|
|
2019-10-04 15:32:55 +03:00
|
|
|
RECT doneBut = {
|
|
|
|
extentX - 60, extentY - 60, extentX, extentY
|
|
|
|
};
|
|
|
|
|
2019-10-07 15:34:23 +03:00
|
|
|
MapPart mapParts[MAP_LENGHT];
|
|
|
|
|
|
|
|
for (int elem = 0; elem < MAP_LENGHT; elem++) {
|
2019-10-07 11:11:39 +03:00
|
|
|
mapParts[elem].visible = false;
|
|
|
|
}
|
2019-10-04 15:32:55 +03:00
|
|
|
|
2019-09-30 15:30:46 +03:00
|
|
|
bool clickedBlock = false;
|
|
|
|
bool clickedQuest = false;
|
2019-10-07 15:34:23 +03:00
|
|
|
bool clickedWater = false;
|
|
|
|
bool clickedFire = false;
|
2019-09-30 15:30:46 +03:00
|
|
|
|
2019-10-04 15:32:55 +03:00
|
|
|
while (!GetAsyncKeyState('Q')) {
|
2019-09-30 15:30:46 +03:00
|
|
|
background(TX_WHITE);
|
|
|
|
|
2019-10-07 15:34:23 +03:00
|
|
|
txBitBlt(txDC(), blockBut.left, blockBut.top, 60, 60, block);
|
|
|
|
txBitBlt(txDC(), questBut.left, questBut.top, 60, 60, quest);
|
|
|
|
txBitBlt(txDC(), waterBut.left, waterBut.top, 60, 60, water);
|
|
|
|
|
|
|
|
for (int elem = 0; elem < MAP_LENGHT; elem++) {
|
2019-09-30 15:30:46 +03:00
|
|
|
|
2019-10-07 15:34:23 +03:00
|
|
|
mapParts[elem].coords.left = round((mapParts[elem].coords.left + 30) / 60) * 60;
|
|
|
|
mapParts[elem].coords.top = round((mapParts[elem].coords.top + 30) / 60) * 60;
|
2019-10-04 15:32:55 +03:00
|
|
|
|
|
|
|
if (mapParts[elem].visible) {
|
|
|
|
|
|
|
|
txBitBlt(txDC(),
|
|
|
|
mapParts[elem].coords.left,
|
|
|
|
mapParts[elem].coords.top,
|
|
|
|
60, 60,
|
|
|
|
mapParts[elem].picture
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-30 15:30:46 +03:00
|
|
|
//block "block"
|
|
|
|
if (In(txMousePos(), blockBut) && txMouseButtons() & 1) {
|
|
|
|
clickedBlock = true;
|
|
|
|
}
|
|
|
|
if (txMouseButtons() & 1 && clickedBlock) {
|
|
|
|
txBitBlt(txDC(), txMouseX() - 30, txMouseY() - 30, 60, 60, block);
|
|
|
|
|
2019-10-04 15:32:55 +03:00
|
|
|
}
|
|
|
|
if (!(txMouseButtons() & 1) && clickedBlock) {
|
|
|
|
|
2019-10-07 15:34:23 +03:00
|
|
|
if (arrElem <= MAP_LENGHT) {
|
|
|
|
mapParts[arrElem] = {
|
|
|
|
{
|
|
|
|
txMouseX() - 30, txMouseY() - 30, txMouseX() + 30, txMouseY() + 30
|
|
|
|
}, true, block, BLOCK_TYPE
|
|
|
|
};
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
//����� sprintf
|
|
|
|
//txMessageBox("You cannot add more than " + (char)MAP_LENGHT + "blocks", "Error");
|
|
|
|
}
|
|
|
|
|
2019-10-04 15:32:55 +03:00
|
|
|
arrElem++;
|
|
|
|
clickedBlock = false;
|
2019-09-30 15:30:46 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
//block "quest"
|
|
|
|
if (In(txMousePos(), questBut) && txMouseButtons() & 1) {
|
|
|
|
clickedQuest = true;
|
|
|
|
}
|
|
|
|
if (txMouseButtons() & 1 && clickedQuest) {
|
|
|
|
txBitBlt(txDC(), txMouseX() - 30, txMouseY() - 30, 60, 60, quest);
|
2019-10-04 15:32:55 +03:00
|
|
|
}
|
|
|
|
if (!(txMouseButtons() & 1) && clickedQuest) {
|
2019-09-30 15:30:46 +03:00
|
|
|
|
2019-10-04 15:32:55 +03:00
|
|
|
mapParts[arrElem] = {
|
|
|
|
{
|
|
|
|
txMouseX() - 30, txMouseY() - 30, txMouseX() + 30, txMouseY() + 30
|
|
|
|
}, true, quest, QUEST_TYPE
|
|
|
|
};
|
|
|
|
arrElem++;
|
|
|
|
|
|
|
|
clickedQuest = false;
|
|
|
|
}
|
|
|
|
|
2019-10-07 15:34:23 +03:00
|
|
|
//block "water"
|
|
|
|
if (In(txMousePos(), waterBut) && txMouseButtons() & 1) {
|
|
|
|
clickedWater = true;
|
|
|
|
}
|
|
|
|
if (txMouseButtons() & 1 && clickedWater) {
|
|
|
|
txBitBlt(txDC(), txMouseX() - 30, txMouseY() - 30, 60, 60, water);
|
|
|
|
}
|
|
|
|
if (!(txMouseButtons() & 1) && clickedWater) {
|
|
|
|
|
|
|
|
mapParts[arrElem] = {
|
|
|
|
{
|
|
|
|
txMouseX() - 30, txMouseY() - 30, txMouseX() + 30, txMouseY() + 30
|
|
|
|
}, true, water, WATER_TYPE
|
|
|
|
};
|
|
|
|
arrElem++;
|
|
|
|
|
|
|
|
clickedWater = false;
|
|
|
|
}
|
|
|
|
|
2019-10-04 15:32:55 +03:00
|
|
|
//button to complete LevelCreating
|
|
|
|
if (In(txMousePos(), doneBut) && txMouseButtons() & 1) {
|
|
|
|
while (txMouseButtons() & 1) {
|
|
|
|
txSleep(10);
|
|
|
|
}
|
|
|
|
|
|
|
|
ofstream lvlfile;
|
|
|
|
lvlfile.open("level1.fslvl");
|
|
|
|
for (int elem = 0; elem < 12; elem++) {
|
|
|
|
if (mapParts[elem].visible) {
|
|
|
|
switch(mapParts[elem].blocktype)
|
|
|
|
{
|
|
|
|
case BLOCK_TYPE:
|
2019-10-07 15:34:23 +03:00
|
|
|
lvlfile << "Block";
|
|
|
|
case QUEST_TYPE:
|
|
|
|
lvlfile << "Quest";
|
2019-10-04 15:32:55 +03:00
|
|
|
}
|
2019-10-07 15:34:23 +03:00
|
|
|
|
|
|
|
lvlfile << mapParts[elem].coords.left;
|
|
|
|
lvlfile << mapParts[elem].coords.top;
|
|
|
|
lvlfile << mapParts[elem].coords.right;
|
|
|
|
lvlfile << mapParts[elem].coords.bottom;
|
|
|
|
|
|
|
|
lvlfile << "";
|
2019-10-04 15:32:55 +03:00
|
|
|
}
|
2019-09-30 15:30:46 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
txSleep(10);
|
|
|
|
}
|
2019-09-23 15:35:44 +03:00
|
|
|
}
|
|
|
|
|