Mario: better mushroom movement
This commit is contained in:
parent
a194bfb86e
commit
f7002f0f38
@ -42,7 +42,11 @@ void MushroomBlock::handleVisitor(SDLPP::Visitor &visitor) {
|
|||||||
}
|
}
|
||||||
auto &m_visitor = dynamic_cast<MushroomVisitor&>(visitor);
|
auto &m_visitor = dynamic_cast<MushroomVisitor&>(visitor);
|
||||||
setOnGround(m_visitor.isOnGround());
|
setOnGround(m_visitor.isOnGround());
|
||||||
|
if(isOnGround()) {
|
||||||
|
setPos(getPos().getX(), m_visitor.getGroundY() - BLOCK_SIZE);
|
||||||
|
}
|
||||||
if(!m_visitor.canGoLeft() || !m_visitor.canGoRight()) {
|
if(!m_visitor.canGoLeft() || !m_visitor.canGoRight()) {
|
||||||
|
setPos(m_visitor.getValidXPos(), getPos().getY());
|
||||||
setMovement(-getMovement().getX(), getMovement().getY());
|
setMovement(-getMovement().getX(), getMovement().getY());
|
||||||
}
|
}
|
||||||
if(m_visitor.getDeath()) {
|
if(m_visitor.getDeath()) {
|
||||||
|
@ -142,6 +142,7 @@ void doInput( std::shared_ptr< SDLPP::Scene > scene ) {
|
|||||||
std::lock_guard< std::mutex > lock( render_mutex );
|
std::lock_guard< std::mutex > lock( render_mutex );
|
||||||
scene->updateScene();
|
scene->updateScene();
|
||||||
auto prev_coin_count = coin_count;
|
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++) {
|
for(size_t i = 0; i < moving_objects.size(); i++) {
|
||||||
auto visitor =
|
auto visitor =
|
||||||
getVisitor( *moving_objects[i], *scene, quit, coin_count, moving_objects );
|
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();
|
moving_objects[i]->getDoubleRect().second.getX();
|
||||||
if(rightmost_pos < 0) {
|
if(rightmost_pos < 0) {
|
||||||
moving_objects[i]->destroy();
|
moving_objects[i]->destroy();
|
||||||
std::cout << "DESTRUCTION!!!!" << std::endl;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
std::vector<uint64_t> killed_indices{};
|
std::vector<uint64_t> killed_indices{};
|
||||||
|
@ -34,11 +34,13 @@ void MushroomVisitor::visit( const SDLPP::RenderObject &obj ) {
|
|||||||
} else if ( from == MARIO_LEFT_SIDE_DETECT ) {
|
} else if ( from == MARIO_LEFT_SIDE_DETECT ) {
|
||||||
if(!left && !right) {
|
if(!left && !right) {
|
||||||
movement_blockage = obj.getPos();
|
movement_blockage = obj.getPos();
|
||||||
|
validXPos = movement_blockage.getX() + BLOCK_SIZE;
|
||||||
}
|
}
|
||||||
left = true;
|
left = true;
|
||||||
} else if (from == MARIO_RIGHT_SIDE_DETECT ) {
|
} else if (from == MARIO_RIGHT_SIDE_DETECT ) {
|
||||||
if(!left && !right) {
|
if(!left && !right) {
|
||||||
movement_blockage = obj.getPos();
|
movement_blockage = obj.getPos();
|
||||||
|
validXPos = movement_blockage.getX() - BLOCK_SIZE;
|
||||||
}
|
}
|
||||||
right = true;
|
right = true;
|
||||||
}
|
}
|
||||||
|
@ -40,10 +40,14 @@ public:
|
|||||||
bool getDeath() {
|
bool getDeath() {
|
||||||
return death;
|
return death;
|
||||||
}
|
}
|
||||||
|
double getValidXPos() {
|
||||||
|
return validXPos;
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool onGround = false;
|
bool onGround = false;
|
||||||
double groundY = 0;
|
double groundY = 0;
|
||||||
|
double validXPos = 0;
|
||||||
bool stop = false;
|
bool stop = false;
|
||||||
bool left = false;
|
bool left = false;
|
||||||
bool right = false;
|
bool right = false;
|
||||||
|
Loading…
Reference in New Issue
Block a user