#ifndef MARIO_VISITOR_H #define MARIO_VISITOR_H #include "../../sdlpp/sdlpp_visitor.hpp" #include "../../sdlpp/sdlpp_geometry.hpp" #include "../../sdlpp/sdlpp_scene.hpp" #include "../blocks.hpp" class MarioVisitor : public SDLPP::Visitor { public: 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; } bool isDead() const { return death; } bool isStopped() const { return stop; } double newXPos() const { return newX; } void setFromId( uint64_t id ) override { from = id; } uint64_t getFromId() const override { return from; } void setVisitorType( uint64_t type ) override { _type = type; } uint64_t getVisitorType() const override { return _type; } bool canGoLeft() const { return !left; } bool canGoRight() const { return !right; } double getGroundY() const { return groundY; } bool topBlock() const { return top_hit; } bool moveTop() const { return top_left_right && !top_hit; } const SDLPP::Vec2D &getRightLeftPos() { return rightleftpos; } bool canDestroy() const { return jumping && !top_hit; } const SDLPP::Vec2D &getMovementBlockage() { return movement_blockage; } double getStopX() const { return newX; } void setCoin() { // TODO remove coin? coin = true; _coin_count++; } bool hasCoin() const { return coin; } void setCoinBlock(std::shared_ptr &coin) { // TODO remove coin_block? coin_block = coin; _scene.addObject(coin); _scene.moveZJustAboveBackground(coin); } bool hasCoinBlock() { return coin_block != nullptr; } std::shared_ptr &getCoinBlock() { return coin_block; } bool hasMushroom() const { return mushroom; } void setMushroomBlock(std::shared_ptr &mushroom) { _scene.addObject(mushroom); _scene.moveZJustAboveBackground(mushroom); _moving_objects.push_back(mushroom); } private: bool onGround = false; double groundY = 0; bool death = false; bool stop = false; double newX{}; uint64_t from = -1; bool left = false; bool right = false; uint64_t _type = 0; bool top_hit = false; SDLPP::Vec2D rightleftpos; bool top_left_right = false; bool jumping; bool coin = false; SDLPP::Vec2D movement_blockage; std::shared_ptr coin_block = nullptr; SDLPP::Scene &_scene; bool &_quit; int &_coin_count; bool mushroom = false; std::vector< std::shared_ptr< MarioBlock > > &_moving_objects; }; #endif