Mario: proper position when standing on ground

This commit is contained in:
zv0n 2021-05-22 22:36:53 +02:00
parent d04cbea02d
commit 0358aa36c7
3 changed files with 11 additions and 4 deletions

View File

@ -156,6 +156,7 @@ void doInput( std::shared_ptr< SDLPP::Scene > scene ) {
mario->setMovement( mario->getMovement().getX(), FALL_MOVEMENT );
} else {
mario->resetMovementY();
mario->setPos(mario->getPos().getX(), mv.getGroundY() - BLOCK_SIZE);
}
if ( mv.isStopped() ||
( !mv.canGoLeft() && prevPos.getX() > mario->getPos().getX() ) ||
@ -211,7 +212,7 @@ int main() {
mario->setMovement( 0, 0 );
mario->setMovementSpeed( 0.4 );
mario->addCollision(
SDLPP::RectColider( 0.21, 0.85, 0.65, 0.16, MARIO_FLOOR_DETECT ) );
SDLPP::RectColider( 0.21, 0.85, 0.65, 0.25, MARIO_FLOOR_DETECT ) );
mario->addCollision(
SDLPP::RectColider( 0, 0.1, 0.1, 0.8, MARIO_LEFT_SIDE_DETECT ) );
mario->addCollision(

View File

@ -6,12 +6,14 @@ void MarioVisitor::visit( const SDLPP::RenderObject &obj ) {
auto id = obj.getId();
switch ( id ) {
case FLOOR_ID:
if ( from == MARIO_FLOOR_DETECT )
if ( from == MARIO_FLOOR_DETECT ) {
onGround = true;
else if ( from == MARIO_LEFT_SIDE_DETECT )
groundY = obj.getPos().getY();
} else if ( from == MARIO_LEFT_SIDE_DETECT ) {
left = true;
else if (from == MARIO_RIGHT_SIDE_DETECT )
} else if (from == MARIO_RIGHT_SIDE_DETECT ) {
right = true;
}
break;
case DEATH_ID:
death = true;

View File

@ -38,9 +38,13 @@ public:
bool canGoRight() {
return !right;
}
double getGroundY() {
return groundY;
}
private:
bool onGround = false;
double groundY = 0;
bool death = false;
bool stop = false;
double newX;