Mario: add mushroom block
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
#include "mushroomblock.hpp"
|
||||
#include "../sprites.hpp"
|
||||
#include "../global_vars.hpp"
|
||||
#include "../objectids.hpp"
|
||||
#include "../visitors/mushroom_visitor.hpp"
|
||||
|
||||
MushroomBlock::MushroomBlock( int x, int y, std::shared_ptr< SDLPP::Renderer > &renderer ) : MarioBlock(x, y, renderer, g_terrain_texture, MUSHROOM_SRC, true, true) {
|
||||
setHidden(true);
|
||||
ensureCollision();
|
||||
setId(MUSHROOM_ID);
|
||||
auto bottom_detect = SDLPP::RectColider( 0.2, 1, 0.6, 0, MARIO_FLOOR_DETECT );
|
||||
bottom_detect.setColor("#FF0000");
|
||||
bottom_detect.setOutlineColor("#FF0000");
|
||||
bottom_detect.setMinHeight(1);
|
||||
addCollision(bottom_detect);
|
||||
addCollision(
|
||||
SDLPP::RectColider( 0, 0.25, 0.1, 0.6, MARIO_LEFT_SIDE_DETECT ) );
|
||||
addCollision(
|
||||
SDLPP::RectColider( 0.9, 0.25, 0.1, 0.6, MARIO_RIGHT_SIDE_DETECT ) );
|
||||
}
|
||||
|
||||
void MushroomBlock::custom_move(int ticks) {
|
||||
if(_parent != nullptr && !_parent->isBouncing() && !isTraveling()) {
|
||||
setHidden(false);
|
||||
travelToPos(_parent->getPos() - SDLPP::Vec2D<double>(0, BLOCK_SIZE));
|
||||
_parent = nullptr;
|
||||
} else if(_parent == nullptr && !isTraveling() && !_started_movement) {
|
||||
_started_movement = true;
|
||||
setMovement(movementSpeed/2, 0);
|
||||
}
|
||||
gravity(ticks);
|
||||
MarioBlock::custom_move(ticks);
|
||||
}
|
||||
|
||||
void MushroomBlock::setParent(MarioBlock *parent) {
|
||||
_parent = parent;
|
||||
}
|
||||
|
||||
void MushroomBlock::handleVisitor(SDLPP::Visitor &visitor) {
|
||||
if(!_started_movement) {
|
||||
return;
|
||||
}
|
||||
auto &m_visitor = dynamic_cast<MushroomVisitor&>(visitor);
|
||||
setOnGround(m_visitor.isOnGround());
|
||||
if(!m_visitor.canGoLeft() || !m_visitor.canGoRight()) {
|
||||
setMovement(-getMovement().getX(), getMovement().getY());
|
||||
}
|
||||
if(m_visitor.getDeath()) {
|
||||
destroy();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
#ifndef MUSHROOM_BLOCK_HPP
|
||||
#define MUSHROOM_BLOCK_HPP
|
||||
|
||||
#include "../blocks.hpp"
|
||||
|
||||
class MushroomBlock : public MarioBlock {
|
||||
public:
|
||||
MushroomBlock( int x, int y, std::shared_ptr< SDLPP::Renderer > &renderer );
|
||||
void custom_move(int ticks) override;
|
||||
void setParent(MarioBlock *parent);
|
||||
void handleVisitor(SDLPP::Visitor &visitor) override;
|
||||
private:
|
||||
MarioBlock *_parent = nullptr;
|
||||
bool _started_movement = false;
|
||||
};
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user