Mario: proper position when standing on ground
This commit is contained in:
parent
d04cbea02d
commit
0358aa36c7
@ -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(
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user