game/mario/visitors/goomba_visitor.cpp

82 lines
2.4 KiB
C++
Raw Permalink Normal View History

2021-08-08 19:45:05 +00:00
#include "goomba_visitor.hpp"
#include "../../sdlpp/sdlpp_renderobject.hpp"
#include "../objectids.hpp"
#include "../sprites.hpp"
2022-09-25 17:44:28 +00:00
#include "../mario.hpp"
2023-03-10 15:45:26 +00:00
#include "../blocks/turtleblock.hpp"
2021-08-08 19:45:05 +00:00
2021-10-18 08:10:43 +00:00
void GoombaVisitor::visit(const SDLPP::RenderObject &obj) {
2021-08-08 19:45:05 +00:00
auto id = obj.getId();
auto marioBlock = reinterpret_cast<const MarioBlock&>(obj);
2021-10-18 08:10:43 +00:00
switch (id) {
2021-08-08 19:45:05 +00:00
case FLOOR_ID:
case BRICK_ID:
case BRICK_TOP_ID:
if(marioBlock.isBouncing()) {
bounce = true;
death = true;
return;
}
2021-08-08 19:45:05 +00:00
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:
2021-10-18 08:10:43 +00:00
if (from == NPC_FLOOR_DETECT) {
2021-08-08 19:45:05 +00:00
onGround = true;
groundY = obj.getPos().getY();
2021-10-18 08:10:43 +00:00
} else if (from == NPC_LEFT_SIDE_DETECT) {
if (!left && !right) {
2021-08-08 19:45:05 +00:00
movement_blockage = obj.getPos();
validXPos = movement_blockage.getX() + BLOCK_SIZE;
}
left = true;
2021-10-18 08:10:43 +00:00
} else if (from == NPC_RIGHT_SIDE_DETECT) {
if (!left && !right) {
2021-08-08 19:45:05 +00:00
movement_blockage = obj.getPos();
validXPos = movement_blockage.getX() - BLOCK_SIZE;
}
right = true;
}
break;
case DEATH_ID:
2023-03-10 15:45:26 +00:00
instant_death = true;
break;
case TURTLE_ID:
{
auto &turtle = dynamic_cast<const TurtleBlock &>(obj);
if(turtle.isShell() && turtle.getMovement().getX() != 0) {
death = true;
}
}
2021-08-08 19:45:05 +00:00
break;
case MARIO_ID:
2022-09-25 17:44:28 +00:00
{
auto &mario = dynamic_cast<const Mario &>(obj);
if (from == NPC_TOP_DETECT && obj.getPos().getY() <= goomba_pos.getY() - BLOCK_SIZE && !mario.isJumping()) {
death = true;
}
2021-08-08 19:45:05 +00:00
}
break;
2022-11-12 20:32:18 +00:00
case FIREBALL_ID:
instant_death = true;
break;
2021-08-08 19:45:05 +00:00
default:
break;
}
}