Merge pull request #35 from IngCenter/DarkCat09-patch-1

Add files via upload
This commit is contained in:
Mikhail Abramov 2019-12-08 14:41:18 +04:00 committed by GitHub
commit 8423e0c1ff
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -22,6 +22,8 @@ int middleY;
int extentX; int extentX;
int extentY; int extentY;
int arrElem = 0;
bool lvlCreatingIsStarted = false; bool lvlCreatingIsStarted = false;
bool gameIsStarted = false; bool gameIsStarted = false;
@ -59,7 +61,7 @@ bool addingBlock(bool clicked, RECT blockBut, HDC pic,
int readFile(string file, MapPart gettedMapParts[]); int readFile(string file, MapPart gettedMapParts[]);
void playGame(MapPart gettedMapParts[]); void playGame(MapPart gettedMapParts[]);
bool areElemWithTheseCoordsExisting(RECT coords, MapPart mapParts[]); void checkElem(MapPart mapParts[]);
int main() int main()
{ {
@ -188,7 +190,7 @@ void drawMenu()
txSleep(50); txSleep(50);
while (!GetAsyncKeyState('Q') || !GetAsyncKeyState(VK_ESCAPE)) { while (!GetAsyncKeyState('Q') && !GetAsyncKeyState(VK_ESCAPE)) {
if (!lvlCreatingIsStarted && !gameIsStarted) { if (!lvlCreatingIsStarted && !gameIsStarted) {
if (In(txMousePos(), buttonStart.coords) && txMouseButtons() & 1) { if (In(txMousePos(), buttonStart.coords) && txMouseButtons() & 1) {
while (txMouseButtons() & 1) { while (txMouseButtons() & 1) {
@ -273,7 +275,6 @@ void loadingAnimation(int delay, int speed)
void mainFunc() void mainFunc()
{ {
int arrElem = 0;
int selectedPict = -1; int selectedPict = -1;
const int BLOCK_SIZE = 120; const int BLOCK_SIZE = 120;
@ -393,11 +394,7 @@ void mainFunc()
} }
} }
//round((mapParts[elem].coords.left + 30) / 60) * 60
//moving picture //moving picture
RECT oldCoords = mapParts[selectedPict].coords;
if (selectedPict >= 0 && txMouseButtons() & 1) { if (selectedPict >= 0 && txMouseButtons() & 1) {
txBitBlt(txDC(), txBitBlt(txDC(),
@ -413,16 +410,11 @@ void mainFunc()
(round((txMouseY() + 30) / 60) * 60) (round((txMouseY() + 30) / 60) * 60)
}; };
if (!areElemWithTheseCoordsExisting(elRectCoords, mapParts)) {
mapParts[selectedPict].coords = elRectCoords; mapParts[selectedPict].coords = elRectCoords;
checkElem(mapParts);
selectedPict = -1; selectedPict = -1;
} }
else {
mapParts[selectedPict].coords = oldCoords;
selectedPict = -1;
}
}
//button to complete LevelCreating //button to complete LevelCreating
if (In(txMousePos(), doneBut) && txMouseButtons() & 1) { if (In(txMousePos(), doneBut) && txMouseButtons() & 1) {
@ -513,15 +505,15 @@ bool addingBlock(bool clicked, RECT blockBut, HDC pic,
(round((txMouseY() + 30) / 60) * 60) (round((txMouseY() + 30) / 60) * 60)
}; };
if ((txMouseX() < txGetExtentX() - BLOCK_SIZE) && if (txMouseX() < txGetExtentX() - BLOCK_SIZE)
!(areElemWithTheseCoordsExisting(elRectCoords, mapParts)))
{ {
cout << !(areElemWithTheseCoordsExisting(elRectCoords, mapParts)) << endl;
mapParts[*arrElem] = { mapParts[*arrElem] = {
elRectCoords, true, pic, blocktype elRectCoords, true, pic, blocktype
}; };
checkElem(mapParts);
(*arrElem)++; (*arrElem)++;
} }
} }
@ -608,8 +600,33 @@ int readFile(string file, MapPart gettedMapParts[])
void playGame(MapPart gettedMapParts[]) void playGame(MapPart gettedMapParts[])
{ {
int minX = gettedMapParts[0].coords.left;
int iMin = 0;
for (int i = 0; i < arrElem; i++) {
if (gettedMapParts[i].coords.left < minX)
{
minX = gettedMapParts[i].coords.left;
iMin = i;
}
}
int player_x = gettedMapParts[iMin].coords.left;
int player_y = gettedMapParts[iMin].coords.top;
while (!GetAsyncKeyState('Q') && !GetAsyncKeyState(VK_ESCAPE)) {
background(TX_WHITE); background(TX_WHITE);
txSetColor(TX_RED, 1);
txSetFillColor(TX_RED);
txRectangle(player_x,
player_y,
player_x + BLOCK_SIZE / 4,
player_y + BLOCK_SIZE / 4);
for (int i = 0; i < MAP_LENGHT; i++) { for (int i = 0; i < MAP_LENGHT; i++) {
if (gettedMapParts[i].visible) { if (gettedMapParts[i].visible) {
@ -622,31 +639,44 @@ void playGame(MapPart gettedMapParts[])
); );
} }
} }
if (GetAsyncKeyState('W')) {
player_y += player_speed;
}
if (GetAsyncKeyState('A')) {
player_x -= player_speed;
}
if (GetAsyncKeyState('S')) {
player_y -= player_speed;
}
if (GetAsyncKeyState('D')) {
player_x += player_speed;
} }
bool areElemWithTheseCoordsExisting(RECT coords, MapPart mapParts[]) if (GetAsyncKeyState(VK_OEM_PLUS)) {
player_speed++;
}
if (GetAsyncKeyState(VK_OEM_MINUS)) {
player_speed--;
}
txSleep(50);
}
}
void checkElem(MapPart mapParts[])
{ {
RECT elemCoords; for (int elem = 0; elem < MAP_LENGHT; elem++) {
bool areElemExisting; for (int elem2 = 0; elem2 < MAP_LENGHT; elem2++) {
for (int i = 0; i < MAP_LENGHT + 1; i++) { if (elem2 != elem &&
mapParts[elem].coords.left == mapParts[elem2].coords.left &&
mapParts[elem].coords.top == mapParts[elem2].coords.top) {
elemCoords = mapParts[i].coords; mapParts[elem].coords.left = mapParts[elem].coords.left + 60;
mapParts[elem].coords.right = mapParts[elem].coords.right + 60;
if (coords.left == elemCoords.left && }
coords.top == elemCoords.top &&
coords.right == elemCoords.right &&
coords.bottom == elemCoords.bottom &&
mapParts[i].visible
) {
areElemExisting = true;
} }
else {
areElemExisting = false;
} }
} }
return areElemExisting;
}