Mario: mario detects enemies and bounces when he kills them/dies when they kill him
This commit is contained in:
parent
45ac4dad64
commit
94bf4fc39d
@ -27,10 +27,10 @@ Mario::Mario(int x, int y, const std::shared_ptr< SDLPP::Renderer > &renderer) :
|
|||||||
SDLPP::RectColider( 0.9, 0, 0.1, 0.1, MARIO_TOP_LEFT_DETECT ) );
|
SDLPP::RectColider( 0.9, 0, 0.1, 0.1, MARIO_TOP_LEFT_DETECT ) );
|
||||||
top_collision = std::make_shared<SDLPP::RectColider>( 0.5, 0, 0.2, 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 );
|
addCollision( top_collision );
|
||||||
addCollision(
|
addCollision( SDLPP::RectColider( 0, 1, 1, 0.2, MARIO_ENEMY_DETECT ) );
|
||||||
SDLPP::RectColider( 0, 0, 1, 1, MARIO_ID ) );
|
|
||||||
setColiderColor("#FF0000");
|
setColiderColor("#FF0000");
|
||||||
setStatic( false );
|
setStatic( false );
|
||||||
|
bounce_speed *= 4;
|
||||||
}
|
}
|
||||||
Mario::Mario(const std::shared_ptr< SDLPP::Renderer > &renderer) : Mario(0, 0, renderer) {}
|
Mario::Mario(const std::shared_ptr< SDLPP::Renderer > &renderer) : Mario(0, 0, renderer) {}
|
||||||
void Mario::walkLeft() {
|
void Mario::walkLeft() {
|
||||||
@ -88,6 +88,9 @@ void Mario::handleVisitor(SDLPP::Visitor &visitor) {
|
|||||||
resetMovementY();
|
resetMovementY();
|
||||||
stop_jump = true;
|
stop_jump = true;
|
||||||
}
|
}
|
||||||
|
if(m_visitor.shouldBounce()) {
|
||||||
|
addMovement(0, -bounce_speed);
|
||||||
|
}
|
||||||
// make sure Mario isn't stuck inside a wall
|
// make sure Mario isn't stuck inside a wall
|
||||||
// TODO more readable function names
|
// TODO more readable function names
|
||||||
if ( m_visitor.isStopped() ) {
|
if ( m_visitor.isStopped() ) {
|
||||||
@ -129,6 +132,7 @@ void Mario::stopJump() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Mario::custom_move( int ticks ) {
|
void Mario::custom_move( int ticks ) {
|
||||||
|
MarioBlock::custom_move(ticks);
|
||||||
if(!jumping && on_ground)
|
if(!jumping && on_ground)
|
||||||
return;
|
return;
|
||||||
if(getMovement().getY() >= 1.0625 * jump_movement)
|
if(getMovement().getY() >= 1.0625 * jump_movement)
|
||||||
@ -155,5 +159,6 @@ void Mario::visit(SDLPP::Visitor &visitor) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Mario::setWorldTypeSrc(LandType::Value /*UNUSED*/) {
|
void Mario::setWorldTypeSrc(LandType::Value /*UNUSED*/) {
|
||||||
|
MarioBlock::setWorldTypeSrc(LandType::OVERWORLD);
|
||||||
// TODO
|
// TODO
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,7 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
bool faces_right = true;
|
bool faces_right = true;
|
||||||
double side_movement = 0.39;
|
double side_movement = 0.19;
|
||||||
double jump_movement = 1.0;
|
double jump_movement = 1.0;
|
||||||
bool jumping = false;
|
bool jumping = false;
|
||||||
bool stop_jump = false;
|
bool stop_jump = false;
|
||||||
|
@ -53,6 +53,14 @@ void MarioVisitor::visit( const SDLPP::RenderObject &obj ) {
|
|||||||
death = true;
|
death = true;
|
||||||
_quit = true;
|
_quit = true;
|
||||||
break;
|
break;
|
||||||
|
case GOOMBA_ID:
|
||||||
|
if(from != MARIO_FLOOR_DETECT && from != MARIO_ENEMY_DETECT) {
|
||||||
|
death = true;
|
||||||
|
_quit = true;
|
||||||
|
} else {
|
||||||
|
_bounce = true;
|
||||||
|
}
|
||||||
|
break;
|
||||||
case STOP_MOVEMENT:
|
case STOP_MOVEMENT:
|
||||||
stop = true;
|
stop = true;
|
||||||
newX = obj.getDoubleRect().first.getX() +
|
newX = obj.getDoubleRect().first.getX() +
|
||||||
|
@ -100,6 +100,10 @@ public:
|
|||||||
_moving_objects.push_back(mushroom);
|
_moving_objects.push_back(mushroom);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool shouldBounce() {
|
||||||
|
return _bounce;
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool onGround = false;
|
bool onGround = false;
|
||||||
double groundY = 0;
|
double groundY = 0;
|
||||||
@ -122,6 +126,7 @@ private:
|
|||||||
int &_coin_count;
|
int &_coin_count;
|
||||||
bool mushroom = false;
|
bool mushroom = false;
|
||||||
std::vector< std::shared_ptr< MarioBlock > > &_moving_objects;
|
std::vector< std::shared_ptr< MarioBlock > > &_moving_objects;
|
||||||
|
bool _bounce = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user