Mario: teleport to hardcoded level

This commit is contained in:
2022-11-13 19:52:39 +01:00
parent 41ba43ed93
commit c5283000c7
14 changed files with 171 additions and 54 deletions
+47 -3
View File
@@ -41,6 +41,8 @@ bool __left_pressed = false;
std::vector<std::shared_ptr<MarioBlock>> moving_objects = {};
std::vector<SceneStruct> game_scenes{};
std::string _teleport_level = "";
std::mutex render_mutex;
std::mutex gamescene_mutex;
@@ -63,6 +65,7 @@ void handleKeyDown(SDL_Keycode key, SDLPP::Scene &scene) {
break;
case SDLK_s:
case SDLK_DOWN:
mario->crouch();
break;
case SDLK_r:
scene.getRenderer().setRenderColiders(
@@ -109,6 +112,17 @@ void handleKeyUp(SDL_Keycode key) {
case SDLK_w:
case SDLK_UP:
mario->stopJump();
break;
case SDLK_s:
case SDLK_DOWN:
mario->uncrouch();
if(__left_pressed) {
mario->walkLeft();
}
if(__right_pressed) {
mario->walkRight();
}
break;
default:
break;
}
@@ -370,23 +384,49 @@ SceneStruct mainGameScene(const std::string &level_path) {
return ret;
}
void loadLevel(const std::string &level) {
void setTeleportLevelMain(const std::string &level) {
std::cout << "Setting: " << level << std::endl;
_teleport_level = level;
}
void loadLevel(const std::string &level, bool reset) {
// std::lock_guard<std::mutex> lock(render_mutex);
coin_count = 0;
if(reset) {
coin_count = 0;
}
std::lock_guard<std::mutex> lock(gamescene_mutex);
for (auto &scene : game_scenes) {
scene.scene->resetScene();
}
game_scenes.clear();
int marioBig = 0;
if(!reset) {
if(mario->hasFire()) {
marioBig = 2;
} else if (mario->isBig()) {
marioBig = 1;
}
}
game_scenes.push_back(mainGameScene("levels/" + level));
if(!reset) {
for(int i = 0; i < marioBig; i++) {
mario->setBig();
}
}
game_scenes.back().scene->updateSizeAndPosition();
update = true;
newLoaded = true;
update_count = 2;
last_load_level = level;
if(reset) {
last_load_level = level;
}
g_death = false;
}
void loadLevel(const std::string &level) {
loadLevel(level, true);
}
void loadLastLevel() {
if (last_load_level != "") {
loadLevel(last_load_level);
@@ -441,6 +481,10 @@ int main() {
SDL_framerateDelay(&gFPS);
SDL_PumpEvents();
std::lock_guard<std::mutex> lock(render_mutex);
if (!_teleport_level.empty()) {
loadLevel(_teleport_level, false);
_teleport_level = "";
}
if (update) {
for (auto &scene : game_scenes) {
scene.scene->updateSizeAndPosition();