Mario: jumping sprite + head bump colider
This commit is contained in:
parent
088fb4d15a
commit
8672830db8
@ -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 ) );
|
||||
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() {
|
||||
if(on_ground)
|
||||
resumeAnimation();
|
||||
addMovement( -side_movement, 0 );
|
||||
if ( getMovement().getX() < 0 && faces_right ) {
|
||||
@ -29,6 +32,7 @@ void Mario::walkLeft() {
|
||||
}
|
||||
|
||||
void Mario::walkRight() {
|
||||
if(on_ground)
|
||||
resumeAnimation();
|
||||
addMovement( side_movement, 0 );
|
||||
if ( getMovement().getX() > 0 && !faces_right ) {
|
||||
@ -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;
|
||||
}
|
||||
|
@ -17,7 +17,7 @@ public:
|
||||
virtual void custom_move( int ticks ) override;
|
||||
private:
|
||||
bool faces_right = true;
|
||||
double side_movement = 0.32;
|
||||
double side_movement = 0.39;
|
||||
double jump_movement = 1.0;
|
||||
bool jumping = false;
|
||||
bool stop_jump = false;
|
||||
|
@ -73,6 +73,7 @@
|
||||
#define MARIO_FLOOR_DETECT 0x2001
|
||||
#define MARIO_LEFT_SIDE_DETECT 0x2002
|
||||
#define MARIO_RIGHT_SIDE_DETECT 0x2003
|
||||
#define MARIO_TOP_DETECT 0x2004
|
||||
|
||||
#define EDITOR_EDIT_SQUARE 0xF001
|
||||
#define EDITOR_MOUSE_ID 0xF002
|
||||
|
Loading…
Reference in New Issue
Block a user