Skip to content

Commit

Permalink
master: Fixed LevelEditor (sort of) + Fixed turn around bug on first …
Browse files Browse the repository at this point in the history
…action
  • Loading branch information
KevinBrok committed Nov 22, 2021
1 parent 0b16b0a commit 87b3752
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 32 deletions.
11 changes: 9 additions & 2 deletions sdmg/engine/MovableGameObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -476,8 +476,15 @@ namespace sdmg {
return _state == State::FALLING || _state == State::FALLINGLEFT || _state == State::FALLINGRIGHT;
}

MovableGameObject::Direction MovableGameObject::getDirection() { return _direction; }
void MovableGameObject::setDirection(Direction direction) { _direction = direction; }
MovableGameObject::Direction MovableGameObject::getDirection()
{
return _direction;
}

void MovableGameObject::setDirection(Direction direction)
{
_direction = direction;
}

float MovableGameObject::getAttackWidth()
{
Expand Down
2 changes: 1 addition & 1 deletion sdmg/engine/MovableGameObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ namespace sdmg {
float _midAttackY, _longAttackY;
std::vector<std::function<void(MovableGameObject *gameObject)>> _stateChangedCallbacks;
std::vector<std::function<void(MovableGameObject *gameObject)>> _hitCallbacks;
bool _shouldTurnArround;
bool _shouldTurnArround = false;

void triggerStateChangedCallbacks();
protected:
Expand Down
38 changes: 15 additions & 23 deletions sdmg/gamestates/LevelSelectionState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,31 +60,23 @@ namespace sdmg

std::ifstream ifile("assets/levels/" + levelFolder + "/data");

if (!ifile.fail())
try
{
try
if (levelFolder != "tutorial")
{
if (levelFolder != "tutorial")
auto json = engine::util::FileManager::getInstance().loadFileContentsAsJson("assets/levels/" + levelFolder + "/data");

if (game.getGameMode() != GameBase::GameMode::Edit || json["editable"].get<bool>())
{
auto json = engine::util::FileManager::getInstance().loadFileContentsAsJson("assets/levels/" + levelFolder + "/data");
bool showLevel = true;
if (ProgressManager::getInstance().isUnlockableLevel(levelFolder))
showLevel = ProgressManager::getInstance().isUnlockedLevel(levelFolder);

if (game.getGameMode() != GameBase::GameMode::Edit || json["editable"].get<bool>())
if (showLevel)
{
bool showLevel = true;
if (ProgressManager::getInstance().isUnlockableLevel(levelFolder))
showLevel = ProgressManager::getInstance().isUnlockedLevel(levelFolder);

if (showLevel)
{
game.getEngine()->getDrawEngine()->load(levelFolder + "_preview", "assets/levels/" + levelFolder + "/preview_big");
std::string name = json["name"].get<std::string>();
game.getEngine()->getDrawEngine()->loadText(levelFolder + "_title", name, { 255, 255, 255 }, "trebucbd", 48);
}
else
{
_levels->erase(std::remove(_levels->begin(), _levels->end(), levelFolder), _levels->end());
i--;
}
game.getEngine()->getDrawEngine()->load(levelFolder + "_preview", "assets/levels/" + levelFolder + "/preview_big");
std::string name = json["name"].get<std::string>();
game.getEngine()->getDrawEngine()->loadText(levelFolder + "_title", name, { 255, 255, 255 }, "trebucbd", 48);
}
else
{
Expand All @@ -98,17 +90,17 @@ namespace sdmg
i--;
}
}
catch (...)
else
{
_levels->erase(std::remove(_levels->begin(), _levels->end(), levelFolder), _levels->end());
i--;
std::cout << "LevelSelection: Error bij laden " + levelFolder;
}
}
else
catch (...)
{
_levels->erase(std::remove(_levels->begin(), _levels->end(), levelFolder), _levels->end());
i--;
std::cout << "LevelSelection: Error bij laden " + levelFolder;
}
}

Expand Down
6 changes: 5 additions & 1 deletion sdmg/gamestates/LoadingSinglePlayerState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,11 @@ namespace sdmg
platform->setSize(jsonPlatform["size"]["width"].get<float>(), jsonPlatform["size"]["height"].get<float>());
platform->setLocation(jsonPlatform["location"]["x"].get<float>(), jsonPlatform["location"]["y"].get<float>());
pe->addBody(platform, jsonPlatform["bodyPadding"]["x"].get<float>(), jsonPlatform["bodyPadding"]["y"].get<float>());
platform->setCanMoveThroughIt(jsonPlatform.contains("canMoveThroughIt"));

if (jsonPlatform.contains("canMoveThroughIt"))
platform->setCanMoveThroughIt(false);
else
platform->setCanMoveThroughIt(true);

_game->getWorld()->addPlatform(platform);

Expand Down
6 changes: 5 additions & 1 deletion sdmg/gamestates/LoadingState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,11 @@ namespace sdmg
platform->setSize(platformObj["size"]["width"].get<float>(), platformObj["size"]["height"].get<float>());
platform->setLocation(platformObj["location"]["x"].get<float>(), platformObj["location"]["y"].get<float>());
pe->addBody(platform, platformObj["bodyPadding"]["x"].get<float>(), platformObj["bodyPadding"]["y"].get<float>());
platform->setCanMoveThroughIt(platformObj.contains("canMoveThroughIt"));

if (platformObj.contains("canMoveThroughIt"))
platform->setCanMoveThroughIt(false);
else
platform->setCanMoveThroughIt(true);

_game->getWorld()->addPlatform(platform);
if (platformObj.contains("image"))
Expand Down
6 changes: 5 additions & 1 deletion sdmg/gamestates/LoadingSurvivalState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,11 @@ namespace sdmg
platform->setSize(jsonPlatform["size"]["width"].get<float>(), jsonPlatform["size"]["height"].get<float>());
platform->setLocation(jsonPlatform["location"]["x"].get<float>(), jsonPlatform["location"]["y"].get<float>());
pe->addBody(platform, jsonPlatform["bodyPadding"]["x"].get<float>(), jsonPlatform["bodyPadding"]["y"].get<float>());
platform->setCanMoveThroughIt(jsonPlatform.contains("canMoveThroughIt"));

if (jsonPlatform.contains("canMoveThroughIt"))
platform->setCanMoveThroughIt(false);
else
platform->setCanMoveThroughIt(true);

_game->getWorld()->addPlatform(platform);

Expand Down
5 changes: 2 additions & 3 deletions sdmg/helperclasses/Editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -374,14 +374,13 @@ namespace sdmg
_height = textSurface->h;
SDL_FreeSurface(textSurface);


std::vector<std::string> files = util::FileManager::getInstance().getFiles(_editor->PLATFORM_FOLDER + _name + "/");

for (auto file : files)
{
if (file.size() > 6 && file.substr(file.size() - 6, 6) == ".block")
if (file != "preview")
{
_blocks.insert(std::make_pair(file.substr(0, file.size() - 6), IMG_Load((_editor->PLATFORM_FOLDER + _name + "/" + file).c_str())));
_blocks.insert(std::make_pair(file.substr(0, file.size() - 6), IMG_Load((_editor->PLATFORM_FOLDER + _name + "/" + file + ".block").c_str())));
}
}

Expand Down

0 comments on commit 87b3752

Please sign in to comment.