Mario: top collision detection
This commit is contained in:
parent
8672830db8
commit
bea479bf72
@ -41,7 +41,7 @@ void loadMap( std::shared_ptr< SDLPP::Scene > &scene,
|
||||
}
|
||||
}
|
||||
bool collision = false;
|
||||
if ( id == FLOOR_ID ) {
|
||||
if ( id == FLOOR_ID || id == BRICK_ID || id == BRICK_TOP_ID ) {
|
||||
collision = true;
|
||||
}
|
||||
// TODO add modifiers to createTerrainBlock
|
||||
|
@ -73,6 +73,9 @@ void Mario::handleVisitor(MarioVisitor &visitor, SDLPP::Vec2D<double> previous_p
|
||||
setPos(getPos().getX(), visitor.getGroundY() - BLOCK_SIZE);
|
||||
}
|
||||
}
|
||||
if(visitor.topBlock() && getMovement().getY() < 0) {
|
||||
resetMovementY();
|
||||
}
|
||||
// make sure Mario isn't stuck inside a wall
|
||||
if ( visitor.isStopped() ||
|
||||
( !visitor.canGoLeft() && previous_position.getX() > getPos().getX() ) ||
|
||||
|
@ -6,6 +6,8 @@ void MarioVisitor::visit( const SDLPP::RenderObject &obj ) {
|
||||
auto id = obj.getId();
|
||||
switch ( id ) {
|
||||
case FLOOR_ID:
|
||||
case BRICK_ID:
|
||||
case BRICK_TOP_ID:
|
||||
if ( from == MARIO_FLOOR_DETECT ) {
|
||||
onGround = true;
|
||||
groundY = obj.getPos().getY();
|
||||
@ -13,6 +15,8 @@ void MarioVisitor::visit( const SDLPP::RenderObject &obj ) {
|
||||
left = true;
|
||||
} else if (from == MARIO_RIGHT_SIDE_DETECT ) {
|
||||
right = true;
|
||||
} else if (from == MARIO_TOP_DETECT) {
|
||||
top_hit = true;
|
||||
}
|
||||
break;
|
||||
case DEATH_ID:
|
||||
|
@ -41,6 +41,9 @@ public:
|
||||
double getGroundY() {
|
||||
return groundY;
|
||||
}
|
||||
bool topBlock() {
|
||||
return top_hit;
|
||||
}
|
||||
|
||||
private:
|
||||
bool onGround = false;
|
||||
@ -52,6 +55,7 @@ private:
|
||||
bool left = false;
|
||||
bool right = false;
|
||||
uint64_t _type = 0;
|
||||
bool top_hit = false;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user