game/mario/visitors/visitor_generator.cpp
2023-03-10 16:45:26 +01:00

46 lines
1.5 KiB
C++

#include "visitor_generator.hpp"
#include "../objectids.hpp"
#include "mario_visitor.hpp"
#include "mushroom_visitor.hpp"
#include "goomba_visitor.hpp"
#include "turtle_visitor.hpp"
#include "projectile_visitor.hpp"
#include "../mario.hpp"
std::shared_ptr<SDLPP::Visitor>
getVisitor(const MarioBlock &block, SDLPP::Scene &scene,
int &coin_count,
std::vector<std::shared_ptr<MarioBlock>> &moving_objects) {
std::shared_ptr<SDLPP::Visitor> result{};
switch (block.getId()) {
case MARIO_ID:
{
auto &mario = dynamic_cast<const Mario &>(block);
result = std::static_pointer_cast<SDLPP::Visitor>(
std::make_shared<MarioVisitor>(block.getMovement().getY() < 0,
scene, coin_count,
moving_objects, mario.isBig(), mario.hasStar()));
}
break;
case MUSHROOM_ID:
result = std::static_pointer_cast<SDLPP::Visitor>(
std::make_shared<MushroomVisitor>());
break;
case GOOMBA_ID:
result = std::static_pointer_cast<SDLPP::Visitor>(
std::make_shared<GoombaVisitor>(block.getPos()));
break;
case TURTLE_ID:
result = std::static_pointer_cast<SDLPP::Visitor>(
std::make_shared<TurtleVisitor>(block.getPos()));
break;
case FIREBALL_ID:
result = std::static_pointer_cast<SDLPP::Visitor>(
std::make_shared<ProjectileVisitor>());
break;
default:
break;
}
return result;
}