Mario: jumping sprite + head bump colider

This commit is contained in:
zv0n 2021-05-23 23:45:45 +02:00
parent 088fb4d15a
commit 8672830db8
3 changed files with 13 additions and 4 deletions

View File

@ -17,9 +17,12 @@ Mario::Mario(const std::shared_ptr< SDLPP::Renderer > &renderer) : SDLPP::Rectan
SDLPP::RectColider( 0, 0.1, 0.1, 0.8, MARIO_LEFT_SIDE_DETECT ) ); SDLPP::RectColider( 0, 0.1, 0.1, 0.8, MARIO_LEFT_SIDE_DETECT ) );
addCollision( addCollision(
SDLPP::RectColider( 0.9, 0.1, 0.1, 0.8, MARIO_RIGHT_SIDE_DETECT ) ); 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 ); setStatic( false );
} }
void Mario::walkLeft() { void Mario::walkLeft() {
if(on_ground)
resumeAnimation(); resumeAnimation();
addMovement( -side_movement, 0 ); addMovement( -side_movement, 0 );
if ( getMovement().getX() < 0 && faces_right ) { if ( getMovement().getX() < 0 && faces_right ) {
@ -29,6 +32,7 @@ void Mario::walkLeft() {
} }
void Mario::walkRight() { void Mario::walkRight() {
if(on_ground)
resumeAnimation(); resumeAnimation();
addMovement( side_movement, 0 ); addMovement( side_movement, 0 );
if ( getMovement().getX() > 0 && !faces_right ) { if ( getMovement().getX() > 0 && !faces_right ) {
@ -60,6 +64,9 @@ void Mario::handleVisitor(MarioVisitor &visitor, SDLPP::Vec2D<double> previous_p
on_ground = visitor.isOnGround(); on_ground = visitor.isOnGround();
if(!jumping && on_ground) { if(!jumping && on_ground) {
resetMovementY(); resetMovementY();
setTextureSourceRect(MARIO_STANDING_SRC);
if(getMovement().getX() != 0)
resumeAnimation();
// for some reason falling of the edge causes on_ground to be true, but // for some reason falling of the edge causes on_ground to be true, but
// visitor ground_y is 0 // visitor ground_y is 0
if(visitor.getGroundY() != 0) { if(visitor.getGroundY() != 0) {
@ -84,6 +91,8 @@ void Mario::jump() {
slow_jump = getPos().getY() - 2*BLOCK_SIZE; slow_jump = getPos().getY() - 2*BLOCK_SIZE;
addMovement( 0, -jump_movement ); addMovement( 0, -jump_movement );
ticks_till_gravity = base_gravity_ticks; ticks_till_gravity = base_gravity_ticks;
setTextureSourceRect(MARIO_JUMP_SRC);
pauseAnimation();
} }
void Mario::stopJump() { void Mario::stopJump() {
@ -109,5 +118,4 @@ void Mario::custom_move( int ticks ) {
} }
ticks_till_gravity += base_gravity_ticks; ticks_till_gravity += base_gravity_ticks;
} }
std::cout << getMovement().getY() << std::endl;
} }

View File

@ -17,7 +17,7 @@ public:
virtual void custom_move( int ticks ) override; virtual void custom_move( int ticks ) override;
private: private:
bool faces_right = true; bool faces_right = true;
double side_movement = 0.32; double side_movement = 0.39;
double jump_movement = 1.0; double jump_movement = 1.0;
bool jumping = false; bool jumping = false;
bool stop_jump = false; bool stop_jump = false;

View File

@ -73,6 +73,7 @@
#define MARIO_FLOOR_DETECT 0x2001 #define MARIO_FLOOR_DETECT 0x2001
#define MARIO_LEFT_SIDE_DETECT 0x2002 #define MARIO_LEFT_SIDE_DETECT 0x2002
#define MARIO_RIGHT_SIDE_DETECT 0x2003 #define MARIO_RIGHT_SIDE_DETECT 0x2003
#define MARIO_TOP_DETECT 0x2004
#define EDITOR_EDIT_SQUARE 0xF001 #define EDITOR_EDIT_SQUARE 0xF001
#define EDITOR_MOUSE_ID 0xF002 #define EDITOR_MOUSE_ID 0xF002