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