This commit is contained in:
parent
d89712ebab
commit
3cde73d1ed
@ -45,7 +45,7 @@ void MarioBlock::visit(SDLPP::Visitor &visitor) {
|
||||
if (visitor.getFromId() == MARIO_TOP_DETECT) {
|
||||
auto &mario_visitor = dynamic_cast<MarioVisitor &>(visitor);
|
||||
if (mario_visitor.canDestroy()) {
|
||||
if ((_destructible && !hasCoin()) || (_can_be_destroyed && mario_visitor.isBig() && !hasCoin())) {
|
||||
if ((_destructible && !hasCoin() && !hasMushroom()) || (_can_be_destroyed && mario_visitor.isBig() && !hasCoin() && !hasMushroom())) {
|
||||
destroy();
|
||||
} else if (_bouncable) {
|
||||
BounceVisitor bv;
|
||||
@ -77,7 +77,11 @@ void MarioBlock::visit(SDLPP::Visitor &visitor) {
|
||||
createTerrainBlock(MUSHROOM_ID, LandType::OVERWORLD, renderer);
|
||||
mushroom->setPos(getPos());
|
||||
std::dynamic_pointer_cast<MushroomBlock>(mushroom)->setParent(this);
|
||||
std::dynamic_pointer_cast<MushroomBlock>(mushroom)->setFireFlower(mario_visitor.isBig());
|
||||
dynamic_cast<MarioVisitor &>(visitor).setMushroomBlock(mushroom);
|
||||
if(mario_visitor.isBig()) {
|
||||
harden();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -667,3 +671,10 @@ void MarioBlock::checkVisibility(double rightmost_x) {
|
||||
bool MarioBlock::wasVisible() const {
|
||||
return _was_visible;
|
||||
}
|
||||
|
||||
void MarioBlock::harden() {
|
||||
_can_be_destroyed = false;
|
||||
setDestructible(false);
|
||||
setBouncable(false);
|
||||
setTextureSourceRect(HARD_SRC);
|
||||
}
|
||||
|
@ -43,6 +43,7 @@ public:
|
||||
void setBaseRect(SDL_Rect rect);
|
||||
void checkVisibility(double rightmost_x);
|
||||
bool wasVisible() const;
|
||||
void harden();
|
||||
|
||||
protected:
|
||||
double bounce_speed = 0.5;
|
||||
|
@ -28,8 +28,10 @@ void MushroomBlock::custom_move(int ticks) {
|
||||
_parent = nullptr;
|
||||
} else if (_parent == nullptr && !isTraveling() && !_started_movement) {
|
||||
_started_movement = true;
|
||||
if(!_fire_flower) {
|
||||
setMovement(movementSpeed / 4, 0);
|
||||
}
|
||||
}
|
||||
gravity(ticks);
|
||||
MarioBlock::custom_move(ticks);
|
||||
}
|
||||
@ -55,3 +57,8 @@ void MushroomBlock::handleVisitor(SDLPP::Visitor &visitor) {
|
||||
destroy();
|
||||
}
|
||||
}
|
||||
|
||||
void MushroomBlock::setFireFlower(bool fire_flower) {
|
||||
setTextureSourceRect(fire_flower ? FIRE_FLOWER_SRC : MUSHROOM_SRC);
|
||||
_fire_flower = fire_flower;
|
||||
}
|
||||
|
@ -9,10 +9,12 @@ public:
|
||||
void custom_move(int ticks) override;
|
||||
void setParent(MarioBlock *parent);
|
||||
void handleVisitor(SDLPP::Visitor &visitor) override;
|
||||
void setFireFlower(bool fire_flower);
|
||||
|
||||
private:
|
||||
MarioBlock *_parent = nullptr;
|
||||
bool _started_movement = false;
|
||||
bool _fire_flower = false;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -88,7 +88,8 @@ void Mario::handleVisitor(SDLPP::Visitor &visitor) {
|
||||
// for some reason falling of the edge causes on_ground to be true, but
|
||||
// visitor ground_y is 0
|
||||
if (m_visitor.getGroundY() != 0) {
|
||||
setPos(getPos().getX(), m_visitor.getGroundY() - getDoubleRect().second.getY());
|
||||
setPos(getPos().getX(),
|
||||
m_visitor.getGroundY() - getDoubleRect().second.getY());
|
||||
}
|
||||
}
|
||||
// if we just left ground gravity didn't work in custom_move
|
||||
@ -218,14 +219,17 @@ void Mario::setBig() {
|
||||
} else {
|
||||
setBigFlag();
|
||||
setSize({ BLOCK_SIZE, 2 * BLOCK_SIZE });
|
||||
setBaseRect(isJumping() ? MARIO_JUMP_BIG_SRC : MARIO_STANDING_BIG_SRC);
|
||||
setAnimationFrames(MARIO_WALK_BIG_ANIM);
|
||||
standing_src = &MARIO_STANDING_BIG_SRC;
|
||||
death_src = &MARIO_DEATH_BIG_SRC;
|
||||
change_dir_src = &MARIO_CHANGE_DIR_BIG_SRC;
|
||||
jump_src = &MARIO_JUMP_BIG_SRC;
|
||||
walk_anim = &MARIO_WALK_BIG_ANIM;
|
||||
}
|
||||
setBaseRect(isJumping()
|
||||
? (hasFire() ? MARIO_JUMP_FIRE_SRC : MARIO_JUMP_BIG_SRC)
|
||||
: (hasFire() ? MARIO_STANDING_FIRE_SRC
|
||||
: MARIO_STANDING_BIG_SRC));
|
||||
setAnimationFrames(hasFire() ? MARIO_WALK_FIRE_ANIM : MARIO_WALK_BIG_ANIM);
|
||||
standing_src = hasFire() ? &MARIO_STANDING_FIRE_SRC : &MARIO_STANDING_BIG_SRC;
|
||||
death_src = hasFire() ? &MARIO_DEATH_FIRE_SRC : &MARIO_DEATH_BIG_SRC;
|
||||
change_dir_src = hasFire() ? &MARIO_CHANGE_DIR_FIRE_SRC : &MARIO_CHANGE_DIR_BIG_SRC;
|
||||
jump_src = hasFire() ? &MARIO_JUMP_FIRE_SRC : &MARIO_JUMP_BIG_SRC;
|
||||
walk_anim = hasFire() ? &MARIO_WALK_FIRE_ANIM : &MARIO_WALK_BIG_ANIM;
|
||||
}
|
||||
|
||||
void Mario::unsetBig() {
|
||||
|
@ -20,6 +20,14 @@ const std::vector<SDL_Rect> MARIO_WALK_BIG_ANIM = { { 43, 26, 16, 32 },
|
||||
const SDL_Rect MARIO_CHANGE_DIR_BIG_SRC = { 98, 26, 16, 32 };
|
||||
const SDL_Rect MARIO_JUMP_BIG_SRC = { 119, 26, 16, 32 };
|
||||
|
||||
const SDL_Rect MARIO_STANDING_FIRE_SRC = { 1, 157, 16, 32 };
|
||||
const SDL_Rect MARIO_DEATH_FIRE_SRC = { 22, 157, 16, 32 };
|
||||
const std::vector<SDL_Rect> MARIO_WALK_FIRE_ANIM = { { 43, 157, 16, 32 },
|
||||
{ 60, 157, 16, 32 },
|
||||
{ 77, 157, 16, 32 } };
|
||||
const SDL_Rect MARIO_CHANGE_DIR_FIRE_SRC = { 98, 157, 16, 32 };
|
||||
const SDL_Rect MARIO_JUMP_FIRE_SRC = { 119, 157, 16, 32 };
|
||||
|
||||
const SDL_Rect FLOOR_SRC = { 1, 131, 16, 16 };
|
||||
const SDL_Rect HILL_INCLINE_SRC = { 137, 97, 16, 16 };
|
||||
const SDL_Rect HILL_DECLINE_SRC = { 205, 97, 16, 16 };
|
||||
@ -80,6 +88,8 @@ const SDL_Rect CANNON_PEDESTAL_SRC = { 256, 29, 16, 16 };
|
||||
const SDL_Rect CANNON_SRC = { 256, 12, 16, 16 };
|
||||
const SDL_Rect COIN_SRC = { 549, 202, 16, 16 };
|
||||
const SDL_Rect MUSHROOM_SRC = { 69, 12, 16, 16 };
|
||||
const SDL_Rect FIRE_FLOWER_SRC = { 1, 12, 16, 16 };
|
||||
const SDL_Rect HARD_SRC = { 69, 63, 16, 16 };
|
||||
|
||||
extern const SDL_Rect MOD_DESTRUCTIBLE_SRC = { 0, 0, 16, 16 };
|
||||
extern const SDL_Rect MOD_BACKGROUND_SRC = { 16, 0, 16, 16 };
|
||||
|
@ -26,6 +26,12 @@ extern const SDL_Rect MARIO_DEATH_BIG_SRC;
|
||||
extern const std::vector<SDL_Rect> MARIO_WALK_BIG_ANIM;
|
||||
extern const SDL_Rect MARIO_CHANGE_DIR_BIG_SRC;
|
||||
extern const SDL_Rect MARIO_JUMP_BIG_SRC;
|
||||
//------------------ FIRE MARIO ----------------------
|
||||
extern const SDL_Rect MARIO_STANDING_FIRE_SRC;
|
||||
extern const SDL_Rect MARIO_DEATH_FIRE_SRC;
|
||||
extern const std::vector<SDL_Rect> MARIO_WALK_FIRE_ANIM;
|
||||
extern const SDL_Rect MARIO_CHANGE_DIR_FIRE_SRC;
|
||||
extern const SDL_Rect MARIO_JUMP_FIRE_SRC;
|
||||
|
||||
//------------------ TERRAIN ------------------------
|
||||
extern const SDL_Rect FLOOR_SRC;
|
||||
@ -88,6 +94,8 @@ extern const SDL_Rect CANNON_PEDESTAL_SRC;
|
||||
extern const SDL_Rect CANNON_SRC;
|
||||
extern const SDL_Rect COIN_SRC;
|
||||
extern const SDL_Rect MUSHROOM_SRC;
|
||||
extern const SDL_Rect FIRE_FLOWER_SRC;
|
||||
extern const SDL_Rect HARD_SRC;
|
||||
//------------------ MODIFIERS ----------------------
|
||||
extern const SDL_Rect MOD_DESTRUCTIBLE_SRC;
|
||||
extern const SDL_Rect MOD_BACKGROUND_SRC;
|
||||
|
Loading…
Reference in New Issue
Block a user