Mario: mushroom interaction with Mario
This commit is contained in:
@@ -58,6 +58,9 @@ void MarioVisitor::visit( const SDLPP::RenderObject &obj ) {
|
||||
newX = obj.getDoubleRect().first.getX() +
|
||||
obj.getDoubleRect().second.getX();
|
||||
break;
|
||||
case MUSHROOM_ID:
|
||||
mushroom = true;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
|
||||
class MarioVisitor : public SDLPP::Visitor {
|
||||
public:
|
||||
MarioVisitor(bool is_jumping, SDLPP::Scene &scene, bool &quit, int &coin_count) : jumping(is_jumping), _scene(scene), _quit(quit), _coin_count(coin_count) {}
|
||||
MarioVisitor(bool is_jumping, SDLPP::Scene &scene, bool &quit, int &coin_count, std::vector< std::shared_ptr< MarioBlock > > &moving_objects) : jumping(is_jumping), _scene(scene), _quit(quit), _coin_count(coin_count), _moving_objects(moving_objects) {}
|
||||
void visit( const SDLPP::RenderObject &obj ) override;
|
||||
bool isOnGround() const {
|
||||
return onGround;
|
||||
@@ -90,6 +90,16 @@ public:
|
||||
return coin_block;
|
||||
}
|
||||
|
||||
bool hasMushroom() const {
|
||||
return mushroom;
|
||||
}
|
||||
|
||||
void setMushroomBlock(std::shared_ptr<MarioBlock> &mushroom) {
|
||||
_scene.addObject(mushroom);
|
||||
_scene.setZIndex(mushroom, 1);
|
||||
_moving_objects.push_back(mushroom);
|
||||
}
|
||||
|
||||
private:
|
||||
bool onGround = false;
|
||||
double groundY = 0;
|
||||
@@ -110,6 +120,8 @@ private:
|
||||
SDLPP::Scene &_scene;
|
||||
bool &_quit;
|
||||
int &_coin_count;
|
||||
bool mushroom = false;
|
||||
std::vector< std::shared_ptr< MarioBlock > > &_moving_objects;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#include "visitor_generator.hpp"
|
||||
#include "../objectids.hpp"
|
||||
#include "mario_visitor.hpp"
|
||||
#include "mushroom_visitor.hpp"
|
||||
|
||||
std::shared_ptr< SDLPP::Visitor >
|
||||
getVisitor( const MarioBlock &block, SDLPP::Scene &scene, bool &quit,
|
||||
@@ -9,7 +10,10 @@ getVisitor( const MarioBlock &block, SDLPP::Scene &scene, bool &quit,
|
||||
std::shared_ptr< SDLPP::Visitor > result{};
|
||||
switch(block.getId()) {
|
||||
case MARIO_ID:
|
||||
result = std::static_pointer_cast<SDLPP::Visitor>(std::make_shared<MarioVisitor>(block.getMovement().getY() < 0, scene, quit, coin_count));
|
||||
result = std::static_pointer_cast<SDLPP::Visitor>(std::make_shared<MarioVisitor>(block.getMovement().getY() < 0, scene, quit, coin_count, moving_objects));
|
||||
break;
|
||||
case MUSHROOM_ID:
|
||||
result = std::static_pointer_cast<SDLPP::Visitor>(std::make_shared<MushroomVisitor>());
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user