Mario: mushroom interaction with Mario
This commit is contained in:
parent
7b2adac922
commit
f04dc1e23b
@ -27,6 +27,8 @@ 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 ) );
|
||||
setColiderColor("#FF0000");
|
||||
setStatic( false );
|
||||
}
|
||||
@ -69,7 +71,7 @@ void Mario::handleVisitor(SDLPP::Visitor &visitor) {
|
||||
on_ground = m_visitor.isOnGround();
|
||||
if(!jumping && on_ground) {
|
||||
resetMovementY();
|
||||
setTextureSourceRect(MARIO_STANDING_SRC);
|
||||
setBaseRect(MARIO_STANDING_SRC);
|
||||
if(getMovement().getX() != 0)
|
||||
resumeAnimation();
|
||||
// for some reason falling of the edge causes on_ground to be true, but
|
||||
@ -102,6 +104,9 @@ void Mario::handleVisitor(SDLPP::Visitor &visitor) {
|
||||
setPos( objPos.getX() - BLOCK_SIZE, getPos().getY() );
|
||||
}
|
||||
}
|
||||
if(m_visitor.hasMushroom()) {
|
||||
setType(LandType::UNDERWORLD);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -115,7 +120,7 @@ void Mario::jump() {
|
||||
slow_jump = getPos().getY() - 2*BLOCK_SIZE;
|
||||
addMovement( 0, -jump_movement );
|
||||
ticks_till_gravity = base_gravity_ticks;
|
||||
setTextureSourceRect(MARIO_JUMP_SRC);
|
||||
setBaseRect(MARIO_JUMP_SRC);
|
||||
pauseAnimation();
|
||||
}
|
||||
|
||||
@ -144,8 +149,9 @@ void Mario::custom_move( int ticks ) {
|
||||
}
|
||||
}
|
||||
|
||||
void Mario::visit(SDLPP::Visitor &/*UNUSED*/) {
|
||||
void Mario::visit(SDLPP::Visitor &visitor) {
|
||||
// TODO
|
||||
visitor.visit(*this);
|
||||
}
|
||||
|
||||
void Mario::setWorldTypeSrc(LandType::Value /*UNUSED*/) {
|
||||
|
@ -58,6 +58,9 @@ void MarioVisitor::visit( const SDLPP::RenderObject &obj ) {
|
||||
newX = obj.getDoubleRect().first.getX() +
|
||||
obj.getDoubleRect().second.getX();
|
||||
break;
|
||||
case MUSHROOM_ID:
|
||||
mushroom = true;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
@ -8,7 +8,7 @@
|
||||
|
||||
class MarioVisitor : public SDLPP::Visitor {
|
||||
public:
|
||||
MarioVisitor(bool is_jumping, SDLPP::Scene &scene, bool &quit, int &coin_count) : jumping(is_jumping), _scene(scene), _quit(quit), _coin_count(coin_count) {}
|
||||
MarioVisitor(bool is_jumping, SDLPP::Scene &scene, bool &quit, int &coin_count, std::vector< std::shared_ptr< MarioBlock > > &moving_objects) : jumping(is_jumping), _scene(scene), _quit(quit), _coin_count(coin_count), _moving_objects(moving_objects) {}
|
||||
void visit( const SDLPP::RenderObject &obj ) override;
|
||||
bool isOnGround() const {
|
||||
return onGround;
|
||||
@ -90,6 +90,16 @@ public:
|
||||
return coin_block;
|
||||
}
|
||||
|
||||
bool hasMushroom() const {
|
||||
return mushroom;
|
||||
}
|
||||
|
||||
void setMushroomBlock(std::shared_ptr<MarioBlock> &mushroom) {
|
||||
_scene.addObject(mushroom);
|
||||
_scene.setZIndex(mushroom, 1);
|
||||
_moving_objects.push_back(mushroom);
|
||||
}
|
||||
|
||||
private:
|
||||
bool onGround = false;
|
||||
double groundY = 0;
|
||||
@ -110,6 +120,8 @@ private:
|
||||
SDLPP::Scene &_scene;
|
||||
bool &_quit;
|
||||
int &_coin_count;
|
||||
bool mushroom = false;
|
||||
std::vector< std::shared_ptr< MarioBlock > > &_moving_objects;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -1,6 +1,7 @@
|
||||
#include "visitor_generator.hpp"
|
||||
#include "../objectids.hpp"
|
||||
#include "mario_visitor.hpp"
|
||||
#include "mushroom_visitor.hpp"
|
||||
|
||||
std::shared_ptr< SDLPP::Visitor >
|
||||
getVisitor( const MarioBlock &block, SDLPP::Scene &scene, bool &quit,
|
||||
@ -9,7 +10,10 @@ getVisitor( const MarioBlock &block, SDLPP::Scene &scene, bool &quit,
|
||||
std::shared_ptr< SDLPP::Visitor > result{};
|
||||
switch(block.getId()) {
|
||||
case MARIO_ID:
|
||||
result = std::static_pointer_cast<SDLPP::Visitor>(std::make_shared<MarioVisitor>(block.getMovement().getY() < 0, scene, quit, coin_count));
|
||||
result = std::static_pointer_cast<SDLPP::Visitor>(std::make_shared<MarioVisitor>(block.getMovement().getY() < 0, scene, quit, coin_count, moving_objects));
|
||||
break;
|
||||
case MUSHROOM_ID:
|
||||
result = std::static_pointer_cast<SDLPP::Visitor>(std::make_shared<MushroomVisitor>());
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user