Mario: add bouncing

This commit is contained in:
2021-05-25 22:05:50 +02:00
parent 0c4f2482c7
commit 6fe283bb34
4 changed files with 47 additions and 4 deletions
+6 -2
View File
@@ -21,8 +21,8 @@ Mario::Mario(const std::shared_ptr< SDLPP::Renderer > &renderer) : SDLPP::Rectan
SDLPP::RectColider( 0.05, 0, 0.1, 0.1, MARIO_TOP_LEFT_DETECT ) );
addCollision(
SDLPP::RectColider( 0.85, 0, 0.1, 0.1, MARIO_TOP_LEFT_DETECT ) );
addCollision(
SDLPP::RectColider( 0.35, 0, 0.3, 0.15, MARIO_TOP_DETECT ) );
top_collision = std::make_shared<SDLPP::RectColider>( 0.5, 0, 0.2, 0.15, MARIO_TOP_DETECT );
addCollision( top_collision );
setStatic( false );
}
void Mario::walkLeft() {
@@ -31,6 +31,8 @@ void Mario::walkLeft() {
addMovement( -side_movement, 0 );
if ( getMovement().getX() < 0 && faces_right ) {
flipHorizontally();
top_collision->setPos(0.3, 0);
updateSizeAndPosition();
faces_right = false;
}
}
@@ -41,6 +43,8 @@ void Mario::walkRight() {
addMovement( side_movement, 0 );
if ( getMovement().getX() > 0 && !faces_right ) {
flipHorizontally();
top_collision->setPos(0.5, 0);
updateSizeAndPosition();
faces_right = true;
}
}