Mario: better mushroom movement

This commit is contained in:
zvon 2021-08-07 22:17:27 +02:00
parent a194bfb86e
commit f7002f0f38
4 changed files with 11 additions and 1 deletions

View File

@ -42,7 +42,11 @@ void MushroomBlock::handleVisitor(SDLPP::Visitor &visitor) {
}
auto &m_visitor = dynamic_cast<MushroomVisitor&>(visitor);
setOnGround(m_visitor.isOnGround());
if(isOnGround()) {
setPos(getPos().getX(), m_visitor.getGroundY() - BLOCK_SIZE);
}
if(!m_visitor.canGoLeft() || !m_visitor.canGoRight()) {
setPos(m_visitor.getValidXPos(), getPos().getY());
setMovement(-getMovement().getX(), getMovement().getY());
}
if(m_visitor.getDeath()) {

View File

@ -142,6 +142,7 @@ void doInput( std::shared_ptr< SDLPP::Scene > scene ) {
std::lock_guard< std::mutex > lock( render_mutex );
scene->updateScene();
auto prev_coin_count = coin_count;
// TODO only start doing visits once the object has been on screen at least once
for(size_t i = 0; i < moving_objects.size(); i++) {
auto visitor =
getVisitor( *moving_objects[i], *scene, quit, coin_count, moving_objects );
@ -151,7 +152,6 @@ void doInput( std::shared_ptr< SDLPP::Scene > scene ) {
moving_objects[i]->getDoubleRect().second.getX();
if(rightmost_pos < 0) {
moving_objects[i]->destroy();
std::cout << "DESTRUCTION!!!!" << std::endl;
}
}
std::vector<uint64_t> killed_indices{};

View File

@ -34,11 +34,13 @@ void MushroomVisitor::visit( const SDLPP::RenderObject &obj ) {
} else if ( from == MARIO_LEFT_SIDE_DETECT ) {
if(!left && !right) {
movement_blockage = obj.getPos();
validXPos = movement_blockage.getX() + BLOCK_SIZE;
}
left = true;
} else if (from == MARIO_RIGHT_SIDE_DETECT ) {
if(!left && !right) {
movement_blockage = obj.getPos();
validXPos = movement_blockage.getX() - BLOCK_SIZE;
}
right = true;
}

View File

@ -40,10 +40,14 @@ public:
bool getDeath() {
return death;
}
double getValidXPos() {
return validXPos;
}
private:
bool onGround = false;
double groundY = 0;
double validXPos = 0;
bool stop = false;
bool left = false;
bool right = false;