88 lines
2.7 KiB
C++
88 lines
2.7 KiB
C++
|
#include "turtle_visitor.hpp"
|
||
|
#include "../../sdlpp/sdlpp_renderobject.hpp"
|
||
|
#include "../objectids.hpp"
|
||
|
#include "../sprites.hpp"
|
||
|
#include "../mario.hpp"
|
||
|
#include "../blocks/turtleblock.hpp"
|
||
|
|
||
|
void TurtleVisitor::visit(const SDLPP::RenderObject &obj) {
|
||
|
auto id = obj.getId();
|
||
|
auto marioBlock = reinterpret_cast<const MarioBlock&>(obj);
|
||
|
switch (id) {
|
||
|
case FLOOR_ID:
|
||
|
case BRICK_ID:
|
||
|
case BRICK_TOP_ID:
|
||
|
if(marioBlock.isBouncing()) {
|
||
|
bounce = true;
|
||
|
instant_death = true;
|
||
|
return;
|
||
|
}
|
||
|
case PIPE_LEFT_BOTTOM_ID:
|
||
|
case PIPE_RIGHT_BOTTOM_ID:
|
||
|
case PIPE_LEFT_TOP_ID:
|
||
|
case PIPE_RIGHT_TOP_ID:
|
||
|
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:
|
||
|
if (from == NPC_FLOOR_DETECT) {
|
||
|
onGround = true;
|
||
|
groundY = obj.getPos().getY();
|
||
|
} else if (from == NPC_LEFT_SIDE_DETECT) {
|
||
|
if (!left && !right) {
|
||
|
movement_blockage = obj.getPos();
|
||
|
validXPos = movement_blockage.getX() + BLOCK_SIZE;
|
||
|
}
|
||
|
left = true;
|
||
|
} else if (from == NPC_RIGHT_SIDE_DETECT) {
|
||
|
if (!left && !right) {
|
||
|
movement_blockage = obj.getPos();
|
||
|
validXPos = movement_blockage.getX() - BLOCK_SIZE;
|
||
|
}
|
||
|
right = true;
|
||
|
}
|
||
|
break;
|
||
|
case DEATH_ID:
|
||
|
instant_death = true;
|
||
|
break;
|
||
|
case TURTLE_ID:
|
||
|
{
|
||
|
auto &turtle = dynamic_cast<const TurtleBlock &>(obj);
|
||
|
if ((from == NPC_LEFT_SIDE_DETECT || from == NPC_RIGHT_SIDE_DETECT) && turtle.isShell()) {
|
||
|
switch_movement = true;
|
||
|
next_movement = turtle.getMovementAfterSwitch();
|
||
|
if(from == NPC_LEFT_SIDE_DETECT) {
|
||
|
valid_turtle_hit_pos = obj.getPos().getX() + BLOCK_SIZE;
|
||
|
} else {
|
||
|
valid_turtle_hit_pos = obj.getPos().getX() - BLOCK_SIZE;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
break;
|
||
|
case MARIO_ID:
|
||
|
{
|
||
|
auto &mario = dynamic_cast<const Mario &>(obj);
|
||
|
if (from == NPC_TOP_DETECT && obj.getPos().getY() <= turtle_pos.getY() - 0.5*BLOCK_SIZE && !mario.isJumping()) {
|
||
|
death = true;
|
||
|
}
|
||
|
}
|
||
|
break;
|
||
|
case FIREBALL_ID:
|
||
|
instant_death = true;
|
||
|
break;
|
||
|
default:
|
||
|
break;
|
||
|
}
|
||
|
}
|