Mario: teleport to hardcoded level
Some checks reported errors
continuous-integration/drone/push Build encountered an error

This commit is contained in:
zv0n 2022-11-13 19:52:39 +01:00
parent 41ba43ed93
commit c5283000c7
14 changed files with 171 additions and 54 deletions

View File

@ -1,5 +1,6 @@
#include "blocks.hpp" #include "blocks.hpp"
#include "global_vars.hpp" #include "global_vars.hpp"
#include "maploader.hpp"
#include "objectids.hpp" #include "objectids.hpp"
#include "sprites.hpp" #include "sprites.hpp"
#include "editor_visitor.hpp" #include "editor_visitor.hpp"
@ -200,6 +201,9 @@ bool MarioBlock::hasCoin() {
bool MarioBlock::hasMushroom() { bool MarioBlock::hasMushroom() {
return _mushroom; return _mushroom;
} }
bool MarioBlock::hasTeleport() {
return !_teleport_level.empty();
}
void MarioBlock::removeCoin() { void MarioBlock::removeCoin() {
_coins--; _coins--;
} }
@ -212,6 +216,9 @@ void MarioBlock::addMushroom() {
void MarioBlock::setCoinCount(int coins) { void MarioBlock::setCoinCount(int coins) {
_coins = coins; _coins = coins;
} }
void MarioBlock::setTeleportLevel(const std::string &level) {
_teleport_level = level;
}
void MarioBlock::setDestructible(bool destructible) { void MarioBlock::setDestructible(bool destructible) {
_destructible = destructible; _destructible = destructible;
} }
@ -309,6 +316,7 @@ const std::vector<uint64_t> possibleMods = {
BACKGROUND_MODIFIER_ID, BACKGROUND_MODIFIER_ID,
COIN_MODIFIER_ID, COIN_MODIFIER_ID,
MUSHROOM_MODIFIER_ID, MUSHROOM_MODIFIER_ID,
TELEPORT_MODIFIER_ID,
}; };
const std::vector<uint64_t> possibleCharacters = { const std::vector<uint64_t> possibleCharacters = {
@ -565,6 +573,7 @@ createBlockById(uint64_t id, int x, int y,
result = std::static_pointer_cast<MarioBlock>( result = std::static_pointer_cast<MarioBlock>(
std::make_shared<GoombaBlock>(x, y, renderer)); std::make_shared<GoombaBlock>(x, y, renderer));
break; break;
#ifdef EDITOR
case DESTRUCTIBLE_MODIFIER_ID: case DESTRUCTIBLE_MODIFIER_ID:
result = std::static_pointer_cast<MarioBlock>( result = std::static_pointer_cast<MarioBlock>(
std::make_shared<DestructibleModifierBlock>(x, y, renderer)); std::make_shared<DestructibleModifierBlock>(x, y, renderer));
@ -573,16 +582,19 @@ createBlockById(uint64_t id, int x, int y,
result = std::static_pointer_cast<MarioBlock>( result = std::static_pointer_cast<MarioBlock>(
std::make_shared<BackgroundModifierBlock>(x, y, renderer)); std::make_shared<BackgroundModifierBlock>(x, y, renderer));
break; break;
#ifdef EDITOR
case COIN_MODIFIER_ID: case COIN_MODIFIER_ID:
result = std::static_pointer_cast<MarioBlock>( result = std::static_pointer_cast<MarioBlock>(
std::make_shared<CoinEditorBlock>(x, y, renderer)); std::make_shared<CoinEditorBlock>(x, y, renderer));
break; break;
#endif
case MUSHROOM_MODIFIER_ID: case MUSHROOM_MODIFIER_ID:
result = std::static_pointer_cast<MarioBlock>( result = std::static_pointer_cast<MarioBlock>(
std::make_shared<MushroomModifierBlock>(x, y, renderer)); std::make_shared<MushroomModifierBlock>(x, y, renderer));
break; break;
case TELEPORT_MODIFIER_ID:
result = std::static_pointer_cast<MarioBlock>(
std::make_shared<TeleportModifierBlock>(x, y, renderer));
break;
#endif
#ifndef EDITOR #ifndef EDITOR
case COIN_ID: case COIN_ID:
result = std::static_pointer_cast<MarioBlock>( result = std::static_pointer_cast<MarioBlock>(
@ -678,3 +690,7 @@ void MarioBlock::harden() {
setBouncable(false); setBouncable(false);
setTextureSourceRect(HARD_SRC); setTextureSourceRect(HARD_SRC);
} }
const std::string &MarioBlock::getTeleportLevel() {
return _teleport_level;
}

View File

@ -32,10 +32,12 @@ public:
virtual void handleVisitor(SDLPP::Visitor &visitor) {} virtual void handleVisitor(SDLPP::Visitor &visitor) {}
bool hasCoin(); bool hasCoin();
bool hasMushroom(); bool hasMushroom();
bool hasTeleport();
void removeCoin(); void removeCoin();
void removeMushroom(); void removeMushroom();
void addMushroom(); void addMushroom();
void setCoinCount(int coins); void setCoinCount(int coins);
void setTeleportLevel(const std::string &level);
void setDestructible(bool destructible = true); void setDestructible(bool destructible = true);
void ensureCollision(); void ensureCollision();
bool isBouncing() const; bool isBouncing() const;
@ -44,6 +46,7 @@ public:
void checkVisibility(double rightmost_x); void checkVisibility(double rightmost_x);
bool wasVisible() const; bool wasVisible() const;
void harden(); void harden();
const std::string &getTeleportLevel();
protected: protected:
double bounce_speed = 0.5; double bounce_speed = 0.5;
@ -82,6 +85,7 @@ private:
bool _traveling = false; bool _traveling = false;
int _coins = 0; int _coins = 0;
bool _mushroom = false; bool _mushroom = false;
std::string _teleport_level = "";
bool _release_coin = false; bool _release_coin = false;
int ticks_to_bounce = 0; int ticks_to_bounce = 0;
SDLPP::Vec2D<double> og_pos = {}; SDLPP::Vec2D<double> og_pos = {};

View File

@ -464,3 +464,9 @@ MushroomModifierBlock::MushroomModifierBlock(
: MarioBlock(x, y, renderer, g_mod_texture, MOD_MUSHROOM_SRC, false) { : MarioBlock(x, y, renderer, g_mod_texture, MOD_MUSHROOM_SRC, false) {
setId(MUSHROOM_MODIFIER_ID); setId(MUSHROOM_MODIFIER_ID);
} }
TeleportModifierBlock::TeleportModifierBlock(
int x, int y, std::shared_ptr<SDLPP::Renderer> &renderer)
: MarioBlock(x, y, renderer, g_mod_texture, MOD_TELEPORT_SRC, false) {
setId(MUSHROOM_MODIFIER_ID);
}

View File

@ -340,4 +340,10 @@ public:
std::shared_ptr<SDLPP::Renderer> &renderer); std::shared_ptr<SDLPP::Renderer> &renderer);
}; };
class TeleportModifierBlock : public MarioBlock {
public:
TeleportModifierBlock(int x, int y,
std::shared_ptr<SDLPP::Renderer> &renderer);
};
#endif #endif

View File

@ -41,6 +41,8 @@ bool __left_pressed = false;
std::vector<std::shared_ptr<MarioBlock>> moving_objects = {}; std::vector<std::shared_ptr<MarioBlock>> moving_objects = {};
std::vector<SceneStruct> game_scenes{}; std::vector<SceneStruct> game_scenes{};
std::string _teleport_level = "";
std::mutex render_mutex; std::mutex render_mutex;
std::mutex gamescene_mutex; std::mutex gamescene_mutex;
@ -63,6 +65,7 @@ void handleKeyDown(SDL_Keycode key, SDLPP::Scene &scene) {
break; break;
case SDLK_s: case SDLK_s:
case SDLK_DOWN: case SDLK_DOWN:
mario->crouch();
break; break;
case SDLK_r: case SDLK_r:
scene.getRenderer().setRenderColiders( scene.getRenderer().setRenderColiders(
@ -109,6 +112,17 @@ void handleKeyUp(SDL_Keycode key) {
case SDLK_w: case SDLK_w:
case SDLK_UP: case SDLK_UP:
mario->stopJump(); mario->stopJump();
break;
case SDLK_s:
case SDLK_DOWN:
mario->uncrouch();
if(__left_pressed) {
mario->walkLeft();
}
if(__right_pressed) {
mario->walkRight();
}
break;
default: default:
break; break;
} }
@ -370,23 +384,49 @@ SceneStruct mainGameScene(const std::string &level_path) {
return ret; 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); // std::lock_guard<std::mutex> lock(render_mutex);
if(reset) {
coin_count = 0; coin_count = 0;
}
std::lock_guard<std::mutex> lock(gamescene_mutex); std::lock_guard<std::mutex> lock(gamescene_mutex);
for (auto &scene : game_scenes) { for (auto &scene : game_scenes) {
scene.scene->resetScene(); scene.scene->resetScene();
} }
game_scenes.clear(); 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)); game_scenes.push_back(mainGameScene("levels/" + level));
if(!reset) {
for(int i = 0; i < marioBig; i++) {
mario->setBig();
}
}
game_scenes.back().scene->updateSizeAndPosition(); game_scenes.back().scene->updateSizeAndPosition();
update = true; update = true;
newLoaded = true; newLoaded = true;
update_count = 2; update_count = 2;
if(reset) {
last_load_level = level; last_load_level = level;
}
g_death = false; g_death = false;
} }
void loadLevel(const std::string &level) {
loadLevel(level, true);
}
void loadLastLevel() { void loadLastLevel() {
if (last_load_level != "") { if (last_load_level != "") {
loadLevel(last_load_level); loadLevel(last_load_level);
@ -441,6 +481,10 @@ int main() {
SDL_framerateDelay(&gFPS); SDL_framerateDelay(&gFPS);
SDL_PumpEvents(); SDL_PumpEvents();
std::lock_guard<std::mutex> lock(render_mutex); std::lock_guard<std::mutex> lock(render_mutex);
if (!_teleport_level.empty()) {
loadLevel(_teleport_level, false);
_teleport_level = "";
}
if (update) { if (update) {
for (auto &scene : game_scenes) { for (auto &scene : game_scenes) {
scene.scene->updateSizeAndPosition(); scene.scene->updateSizeAndPosition();

View File

@ -152,6 +152,7 @@ void loadMapV01(std::shared_ptr<SDLPP::Scene> &scene,
bool removeCollisions = false; bool removeCollisions = false;
int coinCount = 0; int coinCount = 0;
bool mushroom = false; bool mushroom = false;
std::string teleport_level = "";
if (!editor && block.getModifierId() == DESTRUCTIBLE_MODIFIER_ID) { if (!editor && block.getModifierId() == DESTRUCTIBLE_MODIFIER_ID) {
destructible = true; destructible = true;
} }
@ -165,6 +166,9 @@ void loadMapV01(std::shared_ptr<SDLPP::Scene> &scene,
if (!editor && block.getModifierId() == MUSHROOM_MODIFIER_ID) { if (!editor && block.getModifierId() == MUSHROOM_MODIFIER_ID) {
mushroom = true; mushroom = true;
} }
if (!editor && block.getModifierId() == TELEPORT_MODIFIER_ID) {
teleport_level = "test.marmap";
}
// TODO add modifiers to createTerrainBlock // TODO add modifiers to createTerrainBlock
if (block.getTerrainId() != 0) { if (block.getTerrainId() != 0) {
auto obj = createTerrainBlock(block.getTerrainId(), auto obj = createTerrainBlock(block.getTerrainId(),
@ -175,6 +179,9 @@ void loadMapV01(std::shared_ptr<SDLPP::Scene> &scene,
if (mushroom) { if (mushroom) {
obj->addMushroom(); obj->addMushroom();
} }
if (!teleport_level.empty()) {
obj->setTeleportLevel(teleport_level);
}
if (removeCollisions) { if (removeCollisions) {
obj->removeCollisions(); obj->removeCollisions();
} }

View File

@ -36,7 +36,7 @@ Mario::Mario(int x, int y, const std::shared_ptr<SDLPP::Renderer> &renderer, std
Mario::Mario(const std::shared_ptr<SDLPP::Renderer> &renderer, std::function<void(std::shared_ptr<MarioBlock>&, bool)> addObject) Mario::Mario(const std::shared_ptr<SDLPP::Renderer> &renderer, std::function<void(std::shared_ptr<MarioBlock>&, bool)> addObject)
: Mario(0, 0, renderer, addObject) {} : Mario(0, 0, renderer, addObject) {}
void Mario::walkLeft() { void Mario::walkLeft() {
if (!controllable) { if (!controllable || isCrouching()) {
return; return;
} }
if (on_ground) if (on_ground)
@ -51,7 +51,7 @@ void Mario::walkLeft() {
} }
void Mario::walkRight() { void Mario::walkRight() {
if (!controllable) { if (!controllable || isCrouching()) {
return; return;
} }
if (on_ground) if (on_ground)
@ -71,6 +71,8 @@ void Mario::setStanding() {
} }
} }
void setTeleportLevelMain(const std::string &level);
void Mario::handleVisitor(SDLPP::Visitor &visitor) { void Mario::handleVisitor(SDLPP::Visitor &visitor) {
#ifndef EDITOR #ifndef EDITOR
// TODO - // TODO -
@ -130,6 +132,11 @@ void Mario::handleVisitor(SDLPP::Visitor &visitor) {
if (m_visitor.hasMushroom()) { if (m_visitor.hasMushroom()) {
setBig(); setBig();
} }
if (m_visitor.hasTeleport() && isCrouching()) {
std::cout << "TELEPORTING" << std::endl;
setTeleportLevelMain(m_visitor.getTeleportLevel());
std::cout << "Setted" << std::endl;
}
if (m_visitor.levelEnd() && controllable) { if (m_visitor.levelEnd() && controllable) {
if (std::abs(getPos().getX() - m_visitor.getEndPos().getX()) < if (std::abs(getPos().getX() - m_visitor.getEndPos().getX()) <
BLOCK_SIZE / 8) { BLOCK_SIZE / 8) {
@ -140,6 +147,9 @@ void Mario::handleVisitor(SDLPP::Visitor &visitor) {
if (m_visitor.isDead()) { if (m_visitor.isDead()) {
handleDeath(); handleDeath();
} }
if (m_visitor.isInstantDead()) {
setDeath();
}
#endif #endif
} }
void Mario::handleDeath() { void Mario::handleDeath() {
@ -152,7 +162,7 @@ void Mario::handleDeath() {
} }
void Mario::jump() { void Mario::jump() {
if (!controllable) { if (!controllable || isCrouching()) {
return; return;
} }
if (!on_ground) if (!on_ground)
@ -168,6 +178,19 @@ void Mario::jump() {
pauseAnimation(); pauseAnimation();
} }
void Mario::crouch() {
if(walkingLeft()) {
walkRight();
} else if(walkingRight()) {
walkLeft();
}
_crouching = true;
}
void Mario::uncrouch() {
_crouching = false;
}
#ifndef EDITOR #ifndef EDITOR
void Mario::fire() { void Mario::fire() {
if (!hasFire()) { if (!hasFire()) {

View File

@ -18,6 +18,8 @@ public:
void setStanding(); void setStanding();
void handleVisitor(SDLPP::Visitor &visitor) override; void handleVisitor(SDLPP::Visitor &visitor) override;
void jump(); void jump();
void crouch();
void uncrouch();
#ifndef EDITOR #ifndef EDITOR
void fire(); void fire();
void setAddObjFunc(std::function<void(std::shared_ptr<MarioBlock>&, bool)> func); void setAddObjFunc(std::function<void(std::shared_ptr<MarioBlock>&, bool)> func);
@ -51,6 +53,15 @@ public:
bool isJumping() const { bool isJumping() const {
return jumping; return jumping;
} }
bool isCrouching() const {
return _crouching;
}
bool walkingLeft() const {
return getMovement().getX() < 0;
}
bool walkingRight() const {
return getMovement().getX() > 0;
}
private: private:
std::function<void(std::shared_ptr<MarioBlock>&, bool)> _addObject; std::function<void(std::shared_ptr<MarioBlock>&, bool)> _addObject;
@ -64,6 +75,7 @@ private:
double jump_movement = 1.0; double jump_movement = 1.0;
bool jumping = false; bool jumping = false;
bool stop_jump = false; bool stop_jump = false;
bool _crouching = false;
double max_jump = 0; double max_jump = 0;
double min_jump = 0; double min_jump = 0;
double slow_jump = 0; double slow_jump = 0;

View File

@ -69,6 +69,7 @@
#define BACKGROUND_MODIFIER_ID 0x6002 #define BACKGROUND_MODIFIER_ID 0x6002
#define COIN_MODIFIER_ID 0x6003 #define COIN_MODIFIER_ID 0x6003
#define MUSHROOM_MODIFIER_ID 0x6004 #define MUSHROOM_MODIFIER_ID 0x6004
#define TELEPORT_MODIFIER_ID 0x6005
// character IDs // character IDs
#define MARIO_ID 0x0F #define MARIO_ID 0x0F

View File

@ -291,7 +291,9 @@ void toolMoveUpdateButtons(Button *left, Button *right, int &cur_page,
} }
void updateToolSelection(int prev_index, ToolType::Value type) { void updateToolSelection(int prev_index, ToolType::Value type) {
if(global_vars.tool.type == type) {
unsetToolColor(); unsetToolColor();
}
int cur_page = 0; int cur_page = 0;
size_t multiplier = 0; size_t multiplier = 0;
std::vector<std::shared_ptr<MarioBlock>> *tool_vec = nullptr; std::vector<std::shared_ptr<MarioBlock>> *tool_vec = nullptr;
@ -340,60 +342,33 @@ void updateToolSelection(int prev_index, ToolType::Value type) {
i++) { i++) {
tool_vec->at(i)->setHidden(false); tool_vec->at(i)->setHidden(false);
} }
if (global_vars.tool.index / multiplier == static_cast<size_t>(cur_page)) { if (global_vars.tool.type == type && global_vars.tool.index / multiplier == static_cast<size_t>(cur_page)) {
setToolColor(); setToolColor();
} }
} }
void moveToolsLeft(ToolType::Value type) {
switch (type) {
case ToolType::BLOCK:
global_vars.tool.cur_page_tools--;
updateToolSelection(global_vars.tool.cur_page_tools + 1, type);
break;
case ToolType::MOD:
global_vars.tool.cur_page_mods--;
updateToolSelection(global_vars.tool.cur_page_mods + 1, type);
break;
case ToolType::CHARACTER:
global_vars.tool.cur_page_characters--;
updateToolSelection(global_vars.tool.cur_page_characters + 1, type);
default:
break;
}
}
void moveToolsRight(ToolType::Value type) {
switch (type) {
case ToolType::BLOCK:
global_vars.tool.cur_page_tools++;
updateToolSelection(global_vars.tool.cur_page_tools - 1, type);
break;
case ToolType::MOD:
global_vars.tool.cur_page_mods++;
updateToolSelection(global_vars.tool.cur_page_mods - 1, type);
break;
case ToolType::CHARACTER:
global_vars.tool.cur_page_characters++;
updateToolSelection(global_vars.tool.cur_page_characters - 1, type);
default:
break;
}
}
void updateToolIndex(uint64_t new_index, ToolType::Value new_type) { void updateToolIndex(uint64_t new_index, ToolType::Value new_type) {
int multiplier = 0; int multiplier = 0;
int *page = nullptr; int *page = nullptr;
switch (new_type) { switch (new_type) {
case ToolType::BLOCK: case ToolType::BLOCK:
if(new_index >= global_vars.tools.size()) {
return;
}
multiplier = 2 * TOOLS_WIDTH; multiplier = 2 * TOOLS_WIDTH;
page = &global_vars.tool.cur_page_tools; page = &global_vars.tool.cur_page_tools;
break; break;
case ToolType::MOD: case ToolType::MOD:
if(new_index >= global_vars.mods.size()) {
return;
}
multiplier = 2 * MOD_WIDTH; multiplier = 2 * MOD_WIDTH;
page = &global_vars.tool.cur_page_mods; page = &global_vars.tool.cur_page_mods;
break; break;
case ToolType::CHARACTER: case ToolType::CHARACTER:
if(new_index >= global_vars.characters.size()) {
return;
}
multiplier = 2 * CHARACTER_WIDTH; multiplier = 2 * CHARACTER_WIDTH;
page = &global_vars.tool.cur_page_characters; page = &global_vars.tool.cur_page_characters;
default: default:
@ -659,7 +634,7 @@ void moveModsLeft(void *input, Button *caller) {
toolMoveLeft(caller, actual_input->other_button.get(), toolMoveLeft(caller, actual_input->other_button.get(),
global_vars.tool.cur_page_mods, global_vars.tool.max_page_mods, global_vars.tool.cur_page_mods, global_vars.tool.max_page_mods,
false); false);
updateToolSelection(global_vars.tool.cur_page_tools + 1, ToolType::MOD); updateToolSelection(global_vars.tool.cur_page_mods + 1, ToolType::MOD);
} }
void moveModsRight(void *input, Button *caller) { void moveModsRight(void *input, Button *caller) {
@ -667,7 +642,7 @@ void moveModsRight(void *input, Button *caller) {
toolMoveRight(actual_input->other_button.get(), caller, toolMoveRight(actual_input->other_button.get(), caller,
global_vars.tool.cur_page_mods, global_vars.tool.cur_page_mods,
global_vars.tool.max_page_mods, false); global_vars.tool.max_page_mods, false);
updateToolSelection(global_vars.tool.cur_page_tools - 1, ToolType::MOD); updateToolSelection(global_vars.tool.cur_page_mods - 1, ToolType::MOD);
} }
void moveCharsLeft(void *input, Button *caller) { void moveCharsLeft(void *input, Button *caller) {
@ -675,7 +650,7 @@ void moveCharsLeft(void *input, Button *caller) {
toolMoveLeft(caller, actual_input->other_button.get(), toolMoveLeft(caller, actual_input->other_button.get(),
global_vars.tool.cur_page_characters, global_vars.tool.cur_page_characters,
global_vars.tool.max_page_characters, false); global_vars.tool.max_page_characters, false);
updateToolSelection(global_vars.tool.cur_page_tools + 1, updateToolSelection(global_vars.tool.cur_page_characters + 1,
ToolType::CHARACTER); ToolType::CHARACTER);
} }
@ -684,7 +659,7 @@ void moveCharsRight(void *input, Button *caller) {
toolMoveRight(actual_input->other_button.get(), caller, toolMoveRight(actual_input->other_button.get(), caller,
global_vars.tool.cur_page_characters, global_vars.tool.cur_page_characters,
global_vars.tool.max_page_characters, false); global_vars.tool.max_page_characters, false);
updateToolSelection(global_vars.tool.cur_page_tools - 1, updateToolSelection(global_vars.tool.cur_page_characters - 1,
ToolType::CHARACTER); ToolType::CHARACTER);
} }

View File

@ -101,6 +101,7 @@ extern const SDL_Rect MOD_DESTRUCTIBLE_SRC = { 0, 0, 16, 16 };
extern const SDL_Rect MOD_BACKGROUND_SRC = { 16, 0, 16, 16 }; extern const SDL_Rect MOD_BACKGROUND_SRC = { 16, 0, 16, 16 };
extern const SDL_Rect MOD_COIN_SRC = { 32, 0, 16, 16 }; extern const SDL_Rect MOD_COIN_SRC = { 32, 0, 16, 16 };
extern const SDL_Rect MOD_MUSHROOM_SRC = { 48, 0, 16, 16 }; extern const SDL_Rect MOD_MUSHROOM_SRC = { 48, 0, 16, 16 };
extern const SDL_Rect MOD_TELEPORT_SRC = { 0, 16, 16, 16 };
const SDLPP::Vec2D<uint64_t> OVERWORLD_SHIFT = { 0, 0 }; const SDLPP::Vec2D<uint64_t> OVERWORLD_SHIFT = { 0, 0 };
const SDLPP::Vec2D<uint64_t> UNDERWORLD_SHIFT = { 274, 0 }; const SDLPP::Vec2D<uint64_t> UNDERWORLD_SHIFT = { 274, 0 };

View File

@ -103,6 +103,7 @@ extern const SDL_Rect MOD_DESTRUCTIBLE_SRC;
extern const SDL_Rect MOD_BACKGROUND_SRC; extern const SDL_Rect MOD_BACKGROUND_SRC;
extern const SDL_Rect MOD_COIN_SRC; extern const SDL_Rect MOD_COIN_SRC;
extern const SDL_Rect MOD_MUSHROOM_SRC; extern const SDL_Rect MOD_MUSHROOM_SRC;
extern const SDL_Rect MOD_TELEPORT_SRC;
//------------------ ENEMIES ------------------------- //------------------ ENEMIES -------------------------
extern const SDL_Rect GOOMBA_DEATH_SRC; extern const SDL_Rect GOOMBA_DEATH_SRC;
extern const std::vector<SDL_Rect> GOOMBA_WALK_ANIM; extern const std::vector<SDL_Rect> GOOMBA_WALK_ANIM;

View File

@ -6,13 +6,20 @@
void MarioVisitor::visit(const SDLPP::RenderObject &obj) { void MarioVisitor::visit(const SDLPP::RenderObject &obj) {
auto id = obj.getId(); auto id = obj.getId();
switch (id) { switch (id) {
case FLOOR_ID:
case BRICK_ID:
case BRICK_TOP_ID:
case PIPE_LEFT_BOTTOM_ID: case PIPE_LEFT_BOTTOM_ID:
case PIPE_RIGHT_BOTTOM_ID: case PIPE_RIGHT_BOTTOM_ID:
case PIPE_LEFT_TOP_ID: case PIPE_LEFT_TOP_ID:
case PIPE_RIGHT_TOP_ID: case PIPE_RIGHT_TOP_ID:
{
auto m_obj = dynamic_cast<const MarioBlock &>(obj);
if(m_obj.hasTeleport()) {
setTeleportLevel(m_obj.getTeleportLevel());
}
}
// fallthrough
case FLOOR_ID:
case BRICK_ID:
case BRICK_TOP_ID:
case STEP_ID: case STEP_ID:
case SIDEWAY_PIPE_END_TOP_ID: case SIDEWAY_PIPE_END_TOP_ID:
case SIDEWAY_PIPE_END_BOTTOM_ID: case SIDEWAY_PIPE_END_BOTTOM_ID:
@ -50,7 +57,7 @@ void MarioVisitor::visit(const SDLPP::RenderObject &obj) {
} }
break; break;
case DEATH_ID: case DEATH_ID:
_death = true; _instant_death = true;
break; break;
case GOOMBA_ID: case GOOMBA_ID:
if (from != MARIO_FLOOR_DETECT && from != MARIO_ENEMY_DETECT) { if (from != MARIO_FLOOR_DETECT && from != MARIO_ENEMY_DETECT) {

View File

@ -21,6 +21,9 @@ public:
bool isDead() const { bool isDead() const {
return _death; return _death;
} }
bool isInstantDead() const {
return _instant_death;
}
bool isStopped() const { bool isStopped() const {
return stop; return stop;
} }
@ -124,6 +127,15 @@ public:
bool hasStar() const { bool hasStar() const {
return _has_star; return _has_star;
} }
bool hasTeleport() const {
return !teleport_level.empty();
}
const std::string &getTeleportLevel() const {
return teleport_level;
}
void setTeleportLevel(const std::string &level) {
teleport_level = level;
}
private: private:
bool onGround = false; bool onGround = false;
@ -151,6 +163,8 @@ private:
bool _is_big = false; bool _is_big = false;
bool _has_star = false; bool _has_star = false;
bool _death = false; bool _death = false;
bool _instant_death = false;
std::string teleport_level = "";
}; };
#endif #endif