2021-04-25 20:42:55 +00:00
|
|
|
#include "mario_visitor.hpp"
|
2021-08-04 22:32:17 +00:00
|
|
|
#include "../../sdlpp/sdlpp_renderobject.hpp"
|
|
|
|
#include "../objectids.hpp"
|
|
|
|
#include "../sprites.hpp"
|
2021-04-25 20:42:55 +00:00
|
|
|
|
2021-10-18 08:10:43 +00:00
|
|
|
void MarioVisitor::visit(const SDLPP::RenderObject &obj) {
|
2021-04-25 20:42:55 +00:00
|
|
|
auto id = obj.getId();
|
2021-10-18 08:10:43 +00:00
|
|
|
switch (id) {
|
2021-05-31 16:54:59 +00:00
|
|
|
case PIPE_LEFT_TOP_ID:
|
|
|
|
case PIPE_RIGHT_TOP_ID:
|
2022-11-19 21:53:24 +00:00
|
|
|
teleport_bottom = true;
|
|
|
|
// fallthrough
|
|
|
|
case PIPE_LEFT_BOTTOM_ID:
|
|
|
|
case PIPE_RIGHT_BOTTOM_ID:
|
2022-11-13 18:52:39 +00:00
|
|
|
{
|
|
|
|
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:
|
2021-05-31 16:54:59 +00:00
|
|
|
case STEP_ID:
|
|
|
|
case SIDEWAY_PIPE_END_TOP_ID:
|
|
|
|
case SIDEWAY_PIPE_END_BOTTOM_ID:
|
|
|
|
case SIDEWAY_PIPE_MIDDLE_BOTTOM_ID:
|
|
|
|
case SIDEWAY_PIPE_MIDDLE_TOP_ID:
|
|
|
|
case SIDEWAY_PIPE_CONNECTOR_BOTTOM_ID:
|
|
|
|
case SIDEWAY_PIPE_CONNECTOR_TOP_ID:
|
|
|
|
case TREE_PLATFORM_TOP_LEFT_ID:
|
|
|
|
case TREE_PLATFORM_TOP_RIGHT_ID:
|
|
|
|
case MUSHROOM_PLATFORM_TOP_MIDDLE_ID:
|
|
|
|
case MUSHROOM_PLATFORM_TOP_LEFT_ID:
|
|
|
|
case MUSHROOM_PLATFORM_TOP_RIGHT_ID:
|
|
|
|
case CANNON_TOWER_ID:
|
|
|
|
case CANNON_PEDESTAL_ID:
|
|
|
|
case CANNON_ID:
|
2021-10-18 08:10:43 +00:00
|
|
|
if (from == MARIO_FLOOR_DETECT) {
|
2021-04-25 20:42:55 +00:00
|
|
|
onGround = true;
|
2021-05-22 20:36:53 +00:00
|
|
|
groundY = obj.getPos().getY();
|
2021-10-18 08:10:43 +00:00
|
|
|
} else if (from == MARIO_LEFT_SIDE_DETECT) {
|
|
|
|
if (!left && !right) {
|
2021-05-25 22:46:19 +00:00
|
|
|
movement_blockage = obj.getPos();
|
2021-08-04 22:32:17 +00:00
|
|
|
}
|
2021-04-29 10:33:31 +00:00
|
|
|
left = true;
|
2021-10-18 08:10:43 +00:00
|
|
|
} else if (from == MARIO_RIGHT_SIDE_DETECT) {
|
|
|
|
if (!left && !right) {
|
2021-05-25 22:46:19 +00:00
|
|
|
movement_blockage = obj.getPos();
|
2021-08-04 22:32:17 +00:00
|
|
|
}
|
2021-04-29 10:33:31 +00:00
|
|
|
right = true;
|
2021-05-23 21:57:29 +00:00
|
|
|
} else if (from == MARIO_TOP_DETECT) {
|
|
|
|
top_hit = true;
|
2021-10-18 08:10:43 +00:00
|
|
|
} else if (from == MARIO_TOP_LEFT_DETECT ||
|
|
|
|
from == MARIO_TOP_RIGHT_DETECT) {
|
2021-05-25 10:26:04 +00:00
|
|
|
rightleftpos = obj.getPos();
|
|
|
|
top_left_right = true;
|
2021-05-22 20:36:53 +00:00
|
|
|
}
|
2021-04-26 19:59:21 +00:00
|
|
|
break;
|
|
|
|
case DEATH_ID:
|
2022-11-13 18:52:39 +00:00
|
|
|
_instant_death = true;
|
2021-04-26 19:59:21 +00:00
|
|
|
break;
|
2021-08-08 19:40:00 +00:00
|
|
|
case GOOMBA_ID:
|
2021-10-18 08:10:43 +00:00
|
|
|
if (from != MARIO_FLOOR_DETECT && from != MARIO_ENEMY_DETECT) {
|
2022-09-22 18:16:46 +00:00
|
|
|
_death = true;
|
2022-09-25 17:44:28 +00:00
|
|
|
} else if (from == MARIO_FLOOR_DETECT || from == MARIO_ENEMY_DETECT) {
|
2021-08-08 19:40:00 +00:00
|
|
|
_bounce = true;
|
|
|
|
}
|
|
|
|
break;
|
2021-04-26 19:59:21 +00:00
|
|
|
case STOP_MOVEMENT:
|
|
|
|
stop = true;
|
|
|
|
newX = obj.getDoubleRect().first.getX() +
|
|
|
|
obj.getDoubleRect().second.getX();
|
|
|
|
break;
|
2021-08-07 19:42:51 +00:00
|
|
|
case MUSHROOM_ID:
|
|
|
|
mushroom = true;
|
|
|
|
break;
|
2022-09-23 14:46:50 +00:00
|
|
|
case POLE_BOTTOM_ID:
|
|
|
|
case POLE_TOP_ID:
|
|
|
|
case FLAG_ID:
|
|
|
|
_end = true;
|
|
|
|
endPos = obj.getPos();
|
|
|
|
break;
|
2021-04-26 19:59:21 +00:00
|
|
|
default:
|
|
|
|
break;
|
2021-04-25 20:42:55 +00:00
|
|
|
}
|
|
|
|
}
|