From a7c05ad64db4323b4851fba11050914b6f2f97cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D0=BD=D0=B4=D1=80=D0=B5=D0=B9?= <50486086+DarkCat09@users.noreply.github.com> Date: Mon, 2 Dec 2019 15:42:11 +0300 Subject: [PATCH] Add files via upload Edited main.cpp and Replaced level for example. --- FallSimulation.cpp | 124 +++++++++++++++++++++++++++------------------ level1.fslvl | 15 ++++-- 2 files changed, 87 insertions(+), 52 deletions(-) diff --git a/FallSimulation.cpp b/FallSimulation.cpp index a307b0d..61372bf 100644 --- a/FallSimulation.cpp +++ b/FallSimulation.cpp @@ -54,8 +54,7 @@ void mainFunc(); bool addingBlock(bool clicked, RECT blockBut, HDC pic, int blocktype, int* arrElem, MapPart mapParts[]); -void addingStone(int* arrElem, MapPart mapParts[]); -int findElem(int* arrElem, RECT expCoords); +int readFile(string file, MapPart gettedMapParts[]); int main() { @@ -221,61 +220,25 @@ void drawMenu() system("start help\\index.html"); } - /* + if (In(txMousePos(), buttonPlay.coords) && txMouseButtons() & 1) { - MapPart gettedMapParts = readFile("level1.fslvl"); + MapPart gettedMapParts[MAP_LENGHT + 1]; + int arrElem = readFile("level1.fslvl", gettedMapParts); for (int i = 0; i < MAP_LENGHT; i++) { - if (gettedMapParts.visible[i]) { + if (gettedMapParts[i].visible) { - switch (gettedMapParts[i].blocktype) - { - default: - txBitBlt(txDC(), - gettedMapParts[i].coords.left, - gettedMapParts[i].coords.top, - 60, 60, - block - ); - - case BLOCK_TYPE: - txBitBlt(txDC(), - gettedMapParts[i].coords.left, - gettedMapParts[i].coords.top, - 60, 60, - block - ); - - case QUEST_TYPE: - txBitBlt(txDC(), - gettedMapParts[i].coords.left, - gettedMapParts[i].coords.top, - 60, 60, - quest - ); - - case WATER_TYPE: - txBitBlt(txDC(), - gettedMapParts[i].coords.left, - gettedMapParts[i].coords.top, - 60, 60, - water - ); - - case FIRE_TYPE: - txBitBlt(txDC(), - gettedMapParts[i].coords.left, - gettedMapParts[i].coords.top, - 60, 60, - fire - ); - } + txBitBlt(txDC(), + gettedMapParts[i].coords.left, + gettedMapParts[i].coords.top, + 60, 60, + gettedMapParts[i].picture + ); } } } - */ } txSleep(10); @@ -544,3 +507,68 @@ bool addingBlock(bool clicked, RECT blockBut, HDC pic, return clicked; } +int readFile(string file, MapPart gettedMapParts[]) +{ + for (int i = 0; i < MAP_LENGHT; i++) { + + gettedMapParts[i].visible = false; + } + + int arrElem = 0; + + ifstream lvlfile(file); + string buff; + + while (lvlfile.good()) { + + getline(lvlfile, buff); + + if (buff.size() > 5) { + int posComma = buff.find(","); + int posComma2 = buff.find(",", posComma + 1); + int posComma3 = buff.find(",", posComma2 + 1); + int posComma4 = buff.find(",", posComma3 + 1); + + string buff1 = buff.substr(0, posComma); + string buff2 = buff.substr(posComma + 1, posComma2 - posComma - 1); + string buff3 = buff.substr(posComma2 + 1, posComma3 - posComma2 - 1); + string buff4 = buff.substr(posComma3 + 1, posComma4 - posComma3 - 1); + string buff5 = buff.substr(posComma4 + 1, buff.size() - posComma4 - 1); + + gettedMapParts[arrElem].coords = { + atoi(buff2.c_str()), atoi(buff3.c_str()), + atoi(buff4.c_str()), atoi(buff5.c_str()) + }; + + gettedMapParts[arrElem].visible = true; + + if (buff1 == "Block") { + gettedMapParts[arrElem].blocktype = BLOCK_TYPE; + gettedMapParts[arrElem].picture = block; + } + else if (buff1 == "Quest") { + gettedMapParts[arrElem].blocktype = QUEST_TYPE; + gettedMapParts[arrElem].picture = quest; + } + else if (buff1 == "Water") { + gettedMapParts[arrElem].blocktype = WATER_TYPE; + gettedMapParts[arrElem].picture = water; + } + else if (buff1 == "Fire") { + gettedMapParts[arrElem].blocktype = FIRE_TYPE; + gettedMapParts[arrElem].picture = fire; + } + else { + gettedMapParts[arrElem].blocktype = 0; + gettedMapParts[arrElem].visible = false; + } + + arrElem++; + } + } + + lvlfile.close(); + + return arrElem; +} + diff --git a/level1.fslvl b/level1.fslvl index 2e576a5..4059d5f 100644 --- a/level1.fslvl +++ b/level1.fslvl @@ -1,4 +1,11 @@ -Block,1200,60,1236,115 -Block,900,120,953,199 -Block,1200,60,1281,98 -Block,720,300,789,348 +Block,300,180,360,240 +Block,120,300,180,360 +Block,480,240,540,300 +Block,960,300,1020,360 +Quest,840,240,900,300 +Fire,840,300,900,360 +Water,480,360,540,420 +Block,720,240,780,300 +Quest,600,240,660,300 +Water,420,360,480,420 +Water,540,360,600,420