From 3cde73d1edd1c6fe189d2dbfc0b6004f0b3e1143 Mon Sep 17 00:00:00 2001 From: zv0n Date: Fri, 11 Nov 2022 19:47:35 +0100 Subject: [PATCH] Add fire mario mode --- mario/blocks.cpp | 13 ++++++++++++- mario/blocks.hpp | 1 + mario/blocks/mushroomblock.cpp | 9 ++++++++- mario/blocks/mushroomblock.hpp | 2 ++ mario/mario.cpp | 24 ++++++++++++++---------- mario/sprites.cpp | 10 ++++++++++ mario/sprites.hpp | 8 ++++++++ 7 files changed, 55 insertions(+), 12 deletions(-) diff --git a/mario/blocks.cpp b/mario/blocks.cpp index d3dd4ff..1a3e4cc 100644 --- a/mario/blocks.cpp +++ b/mario/blocks.cpp @@ -45,7 +45,7 @@ void MarioBlock::visit(SDLPP::Visitor &visitor) { if (visitor.getFromId() == MARIO_TOP_DETECT) { auto &mario_visitor = dynamic_cast(visitor); if (mario_visitor.canDestroy()) { - if ((_destructible && !hasCoin()) || (_can_be_destroyed && mario_visitor.isBig() && !hasCoin())) { + if ((_destructible && !hasCoin() && !hasMushroom()) || (_can_be_destroyed && mario_visitor.isBig() && !hasCoin() && !hasMushroom())) { destroy(); } else if (_bouncable) { BounceVisitor bv; @@ -77,7 +77,11 @@ void MarioBlock::visit(SDLPP::Visitor &visitor) { createTerrainBlock(MUSHROOM_ID, LandType::OVERWORLD, renderer); mushroom->setPos(getPos()); std::dynamic_pointer_cast(mushroom)->setParent(this); + std::dynamic_pointer_cast(mushroom)->setFireFlower(mario_visitor.isBig()); dynamic_cast(visitor).setMushroomBlock(mushroom); + if(mario_visitor.isBig()) { + harden(); + } } } } @@ -667,3 +671,10 @@ void MarioBlock::checkVisibility(double rightmost_x) { bool MarioBlock::wasVisible() const { return _was_visible; } + +void MarioBlock::harden() { + _can_be_destroyed = false; + setDestructible(false); + setBouncable(false); + setTextureSourceRect(HARD_SRC); +} diff --git a/mario/blocks.hpp b/mario/blocks.hpp index 6b791f0..5aca5f4 100644 --- a/mario/blocks.hpp +++ b/mario/blocks.hpp @@ -43,6 +43,7 @@ public: void setBaseRect(SDL_Rect rect); void checkVisibility(double rightmost_x); bool wasVisible() const; + void harden(); protected: double bounce_speed = 0.5; diff --git a/mario/blocks/mushroomblock.cpp b/mario/blocks/mushroomblock.cpp index 585688b..2e60b40 100644 --- a/mario/blocks/mushroomblock.cpp +++ b/mario/blocks/mushroomblock.cpp @@ -28,7 +28,9 @@ void MushroomBlock::custom_move(int ticks) { _parent = nullptr; } else if (_parent == nullptr && !isTraveling() && !_started_movement) { _started_movement = true; - setMovement(movementSpeed / 4, 0); + if(!_fire_flower) { + setMovement(movementSpeed / 4, 0); + } } gravity(ticks); MarioBlock::custom_move(ticks); @@ -55,3 +57,8 @@ void MushroomBlock::handleVisitor(SDLPP::Visitor &visitor) { destroy(); } } + +void MushroomBlock::setFireFlower(bool fire_flower) { + setTextureSourceRect(fire_flower ? FIRE_FLOWER_SRC : MUSHROOM_SRC); + _fire_flower = fire_flower; +} diff --git a/mario/blocks/mushroomblock.hpp b/mario/blocks/mushroomblock.hpp index d268ce0..fb2323f 100644 --- a/mario/blocks/mushroomblock.hpp +++ b/mario/blocks/mushroomblock.hpp @@ -9,10 +9,12 @@ public: void custom_move(int ticks) override; void setParent(MarioBlock *parent); void handleVisitor(SDLPP::Visitor &visitor) override; + void setFireFlower(bool fire_flower); private: MarioBlock *_parent = nullptr; bool _started_movement = false; + bool _fire_flower = false; }; #endif diff --git a/mario/mario.cpp b/mario/mario.cpp index 668630d..f5522ec 100644 --- a/mario/mario.cpp +++ b/mario/mario.cpp @@ -88,7 +88,8 @@ void Mario::handleVisitor(SDLPP::Visitor &visitor) { // for some reason falling of the edge causes on_ground to be true, but // visitor ground_y is 0 if (m_visitor.getGroundY() != 0) { - setPos(getPos().getX(), m_visitor.getGroundY() - getDoubleRect().second.getY()); + setPos(getPos().getX(), + m_visitor.getGroundY() - getDoubleRect().second.getY()); } } // if we just left ground gravity didn't work in custom_move @@ -217,15 +218,18 @@ void Mario::setBig() { setFireFlag(); } else { setBigFlag(); - setSize({BLOCK_SIZE, 2 * BLOCK_SIZE}); - setBaseRect(isJumping() ? MARIO_JUMP_BIG_SRC : MARIO_STANDING_BIG_SRC); - setAnimationFrames(MARIO_WALK_BIG_ANIM); - standing_src = &MARIO_STANDING_BIG_SRC; - death_src = &MARIO_DEATH_BIG_SRC; - change_dir_src = &MARIO_CHANGE_DIR_BIG_SRC; - jump_src = &MARIO_JUMP_BIG_SRC; - walk_anim = &MARIO_WALK_BIG_ANIM; + setSize({ BLOCK_SIZE, 2 * BLOCK_SIZE }); } + setBaseRect(isJumping() + ? (hasFire() ? MARIO_JUMP_FIRE_SRC : MARIO_JUMP_BIG_SRC) + : (hasFire() ? MARIO_STANDING_FIRE_SRC + : MARIO_STANDING_BIG_SRC)); + setAnimationFrames(hasFire() ? MARIO_WALK_FIRE_ANIM : MARIO_WALK_BIG_ANIM); + standing_src = hasFire() ? &MARIO_STANDING_FIRE_SRC : &MARIO_STANDING_BIG_SRC; + death_src = hasFire() ? &MARIO_DEATH_FIRE_SRC : &MARIO_DEATH_BIG_SRC; + change_dir_src = hasFire() ? &MARIO_CHANGE_DIR_FIRE_SRC : &MARIO_CHANGE_DIR_BIG_SRC; + jump_src = hasFire() ? &MARIO_JUMP_FIRE_SRC : &MARIO_JUMP_BIG_SRC; + walk_anim = hasFire() ? &MARIO_WALK_FIRE_ANIM : &MARIO_WALK_BIG_ANIM; } void Mario::unsetBig() { @@ -233,7 +237,7 @@ void Mario::unsetBig() { unsetFireFlag(); } else { unsetBigFlag(); - setSize({BLOCK_SIZE, BLOCK_SIZE}); + setSize({ BLOCK_SIZE, BLOCK_SIZE }); setBaseRect(isJumping() ? MARIO_JUMP_SRC : MARIO_STANDING_SRC); setAnimationFrames(MARIO_WALK_ANIM); standing_src = &MARIO_STANDING_SRC; diff --git a/mario/sprites.cpp b/mario/sprites.cpp index 71e054e..92b3dac 100644 --- a/mario/sprites.cpp +++ b/mario/sprites.cpp @@ -20,6 +20,14 @@ const std::vector MARIO_WALK_BIG_ANIM = { { 43, 26, 16, 32 }, const SDL_Rect MARIO_CHANGE_DIR_BIG_SRC = { 98, 26, 16, 32 }; const SDL_Rect MARIO_JUMP_BIG_SRC = { 119, 26, 16, 32 }; +const SDL_Rect MARIO_STANDING_FIRE_SRC = { 1, 157, 16, 32 }; +const SDL_Rect MARIO_DEATH_FIRE_SRC = { 22, 157, 16, 32 }; +const std::vector MARIO_WALK_FIRE_ANIM = { { 43, 157, 16, 32 }, + { 60, 157, 16, 32 }, + { 77, 157, 16, 32 } }; +const SDL_Rect MARIO_CHANGE_DIR_FIRE_SRC = { 98, 157, 16, 32 }; +const SDL_Rect MARIO_JUMP_FIRE_SRC = { 119, 157, 16, 32 }; + const SDL_Rect FLOOR_SRC = { 1, 131, 16, 16 }; const SDL_Rect HILL_INCLINE_SRC = { 137, 97, 16, 16 }; const SDL_Rect HILL_DECLINE_SRC = { 205, 97, 16, 16 }; @@ -80,6 +88,8 @@ const SDL_Rect CANNON_PEDESTAL_SRC = { 256, 29, 16, 16 }; const SDL_Rect CANNON_SRC = { 256, 12, 16, 16 }; const SDL_Rect COIN_SRC = { 549, 202, 16, 16 }; const SDL_Rect MUSHROOM_SRC = { 69, 12, 16, 16 }; +const SDL_Rect FIRE_FLOWER_SRC = { 1, 12, 16, 16 }; +const SDL_Rect HARD_SRC = { 69, 63, 16, 16 }; extern const SDL_Rect MOD_DESTRUCTIBLE_SRC = { 0, 0, 16, 16 }; extern const SDL_Rect MOD_BACKGROUND_SRC = { 16, 0, 16, 16 }; diff --git a/mario/sprites.hpp b/mario/sprites.hpp index 90c9f89..d2dcbc2 100644 --- a/mario/sprites.hpp +++ b/mario/sprites.hpp @@ -26,6 +26,12 @@ extern const SDL_Rect MARIO_DEATH_BIG_SRC; extern const std::vector MARIO_WALK_BIG_ANIM; extern const SDL_Rect MARIO_CHANGE_DIR_BIG_SRC; extern const SDL_Rect MARIO_JUMP_BIG_SRC; +//------------------ FIRE MARIO ---------------------- +extern const SDL_Rect MARIO_STANDING_FIRE_SRC; +extern const SDL_Rect MARIO_DEATH_FIRE_SRC; +extern const std::vector MARIO_WALK_FIRE_ANIM; +extern const SDL_Rect MARIO_CHANGE_DIR_FIRE_SRC; +extern const SDL_Rect MARIO_JUMP_FIRE_SRC; //------------------ TERRAIN ------------------------ extern const SDL_Rect FLOOR_SRC; @@ -88,6 +94,8 @@ extern const SDL_Rect CANNON_PEDESTAL_SRC; extern const SDL_Rect CANNON_SRC; extern const SDL_Rect COIN_SRC; extern const SDL_Rect MUSHROOM_SRC; +extern const SDL_Rect FIRE_FLOWER_SRC; +extern const SDL_Rect HARD_SRC; //------------------ MODIFIERS ---------------------- extern const SDL_Rect MOD_DESTRUCTIBLE_SRC; extern const SDL_Rect MOD_BACKGROUND_SRC;