Mario: jumping sprite + head bump colider
This commit is contained in:
+11
-3
@@ -17,10 +17,13 @@ Mario::Mario(const std::shared_ptr< SDLPP::Renderer > &renderer) : SDLPP::Rectan
|
||||
SDLPP::RectColider( 0, 0.1, 0.1, 0.8, MARIO_LEFT_SIDE_DETECT ) );
|
||||
addCollision(
|
||||
SDLPP::RectColider( 0.9, 0.1, 0.1, 0.8, MARIO_RIGHT_SIDE_DETECT ) );
|
||||
addCollision(
|
||||
SDLPP::RectColider( 0.21, 0, 0.65, 0.15, MARIO_TOP_DETECT ) );
|
||||
setStatic( false );
|
||||
}
|
||||
void Mario::walkLeft() {
|
||||
resumeAnimation();
|
||||
if(on_ground)
|
||||
resumeAnimation();
|
||||
addMovement( -side_movement, 0 );
|
||||
if ( getMovement().getX() < 0 && faces_right ) {
|
||||
flipHorizontally();
|
||||
@@ -29,7 +32,8 @@ void Mario::walkLeft() {
|
||||
}
|
||||
|
||||
void Mario::walkRight() {
|
||||
resumeAnimation();
|
||||
if(on_ground)
|
||||
resumeAnimation();
|
||||
addMovement( side_movement, 0 );
|
||||
if ( getMovement().getX() > 0 && !faces_right ) {
|
||||
flipHorizontally();
|
||||
@@ -60,6 +64,9 @@ void Mario::handleVisitor(MarioVisitor &visitor, SDLPP::Vec2D<double> previous_p
|
||||
on_ground = visitor.isOnGround();
|
||||
if(!jumping && on_ground) {
|
||||
resetMovementY();
|
||||
setTextureSourceRect(MARIO_STANDING_SRC);
|
||||
if(getMovement().getX() != 0)
|
||||
resumeAnimation();
|
||||
// for some reason falling of the edge causes on_ground to be true, but
|
||||
// visitor ground_y is 0
|
||||
if(visitor.getGroundY() != 0) {
|
||||
@@ -84,6 +91,8 @@ void Mario::jump() {
|
||||
slow_jump = getPos().getY() - 2*BLOCK_SIZE;
|
||||
addMovement( 0, -jump_movement );
|
||||
ticks_till_gravity = base_gravity_ticks;
|
||||
setTextureSourceRect(MARIO_JUMP_SRC);
|
||||
pauseAnimation();
|
||||
}
|
||||
|
||||
void Mario::stopJump() {
|
||||
@@ -109,5 +118,4 @@ void Mario::custom_move( int ticks ) {
|
||||
}
|
||||
ticks_till_gravity += base_gravity_ticks;
|
||||
}
|
||||
std::cout << getMovement().getY() << std::endl;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user