Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //--------------------------------------------------- FILE MANAGER ------------------------------------------------------------
- void FileManager::LoadFromFile(std::string fileName, std::vector<std::vector<int>> &map, std::vector<std::vector<int>> &col, std::vector<std::vector<int>> &shadow)
- {
- fileName = "Files/Config/" + fileName;
- std::ifstream openFile(fileName);
- map.clear();
- col.clear();
- if (openFile.is_open())
- {
- while (!openFile.eof())
- {
- std::string line;
- std::getline(openFile, line);
- std::vector<int> tempVector;
- if (line.find("[map]") != std::string::npos)
- {
- tempVector.clear();
- state = MAP;
- continue;
- }
- else if(line.find("[collision]") != std::string::npos)
- {
- tempVector.clear();
- state = COLLISION;
- continue;
- }
- else if (line.find("[shadows]") != std::string::npos)
- {
- tempVector.clear();
- state = SHADOW;
- continue;
- }
- std::stringstream str(line);
- while (str)
- {
- std::getline(str, line, ' ');
- if (line != "")
- {
- switch (state)
- {
- case MAP: tempVector.push_back(atoi(line.c_str())); break;
- case COLLISION: tempVector.push_back(atoi(line.c_str())); break;
- case SHADOW: tempVector.push_back(atoi(line.c_str())); break;
- }
- }
- }
- switch (state)
- {
- if (tempVector.size() > 0)
- {
- case MAP: map.push_back(tempVector); break;
- case COLLISION: col.push_back(tempVector); break;
- case SHADOW: shadow.push_back(tempVector); break;
- }
- tempVector.clear();
- }
- }
- }
- openFile.clear();
- openFile.close();
- }
- //------------------------------------------------------- MAPA ------------------------------------------------------------
- //------------------------------------------------- MAPA KOLIZJI - check --------------------------------------------------
- bool GameplayScreen::checkCollision(int pRight, int pLeft, int pTop, int pBot)
- {
- for (int y = 0; y < col.size(); y++)
- {
- for (int x = 0; x < col[y].size(); x++)
- {
- if (col[y][x] == 1)
- {
- left = x * 32;
- right = x * 32 + 32;
- top = y * 32;
- bot = y * 32 + 32;
- if (pRight < left || pLeft > right || pTop > bot || pBot < top)
- {
- std::cout << "NIE MA KOLIZJI" << std::endl;
- return false;
- }
- std::cout << "COLLISION" << std::endl;
- return true;
- }
- }
- }
- }
- //---------------------------------------------------- PLAYER UPDATE -------------------------------------------------------
- void Player::UpdatePosX(int moveSpeed)
- {
- this->left = posX - Config::getSM()->GetGame()->getPosX() + moveSpeed;
- this->right = posX - Config::getSM()->GetGame()->getPosX() + moveSpeed + spriteX;
- bool x = false;
- if (moveSpeed > 0)
- {
- if (!Config::getSM()->GetGame()->checkCollision(right,left,top,bot))
- {
- if (posX >= (Config::getFM()->getW() / 2) - spriteX && Config::getSM()->GetGame()->getMoveMap() && Config::getSM()->GetGame()->getPosX() > -1728)
- {
- Config::getSM()->GetGame()->MoveMap(-moveSpeed, 0);
- }
- else posX += moveSpeed;
- moveAnim = true;
- }
- else
- {
- UpdatePosX(moveSpeed - 1);
- if (moveSpeed > 1 && jumpState == 0)
- {
- --moveSpeed;
- }
- if (jumpState == 0)
- {
- setSpriteID(0);
- moveAnim = false;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement