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) {
|
if (visitor.getFromId() == MARIO_TOP_DETECT) {
|
||||||
auto &mario_visitor = dynamic_cast<MarioVisitor &>(visitor);
|
auto &mario_visitor = dynamic_cast<MarioVisitor &>(visitor);
|
||||||
if (mario_visitor.canDestroy()) {
|
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();
|
destroy();
|
||||||
} else if (_bouncable) {
|
} else if (_bouncable) {
|
||||||
BounceVisitor bv;
|
BounceVisitor bv;
|
||||||
@ -77,7 +77,11 @@ void MarioBlock::visit(SDLPP::Visitor &visitor) {
|
|||||||
createTerrainBlock(MUSHROOM_ID, LandType::OVERWORLD, renderer);
|
createTerrainBlock(MUSHROOM_ID, LandType::OVERWORLD, renderer);
|
||||||
mushroom->setPos(getPos());
|
mushroom->setPos(getPos());
|
||||||
std::dynamic_pointer_cast<MushroomBlock>(mushroom)->setParent(this);
|
std::dynamic_pointer_cast<MushroomBlock>(mushroom)->setParent(this);
|
||||||
|
std::dynamic_pointer_cast<MushroomBlock>(mushroom)->setFireFlower(mario_visitor.isBig());
|
||||||
dynamic_cast<MarioVisitor &>(visitor).setMushroomBlock(mushroom);
|
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 {
|
bool MarioBlock::wasVisible() const {
|
||||||
return _was_visible;
|
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 setBaseRect(SDL_Rect rect);
|
||||||
void checkVisibility(double rightmost_x);
|
void checkVisibility(double rightmost_x);
|
||||||
bool wasVisible() const;
|
bool wasVisible() const;
|
||||||
|
void harden();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
double bounce_speed = 0.5;
|
double bounce_speed = 0.5;
|
||||||
|
@ -28,8 +28,10 @@ void MushroomBlock::custom_move(int ticks) {
|
|||||||
_parent = nullptr;
|
_parent = nullptr;
|
||||||
} else if (_parent == nullptr && !isTraveling() && !_started_movement) {
|
} else if (_parent == nullptr && !isTraveling() && !_started_movement) {
|
||||||
_started_movement = true;
|
_started_movement = true;
|
||||||
|
if(!_fire_flower) {
|
||||||
setMovement(movementSpeed / 4, 0);
|
setMovement(movementSpeed / 4, 0);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
gravity(ticks);
|
gravity(ticks);
|
||||||
MarioBlock::custom_move(ticks);
|
MarioBlock::custom_move(ticks);
|
||||||
}
|
}
|
||||||
@ -55,3 +57,8 @@ void MushroomBlock::handleVisitor(SDLPP::Visitor &visitor) {
|
|||||||
destroy();
|
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 custom_move(int ticks) override;
|
||||||
void setParent(MarioBlock *parent);
|
void setParent(MarioBlock *parent);
|
||||||
void handleVisitor(SDLPP::Visitor &visitor) override;
|
void handleVisitor(SDLPP::Visitor &visitor) override;
|
||||||
|
void setFireFlower(bool fire_flower);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
MarioBlock *_parent = nullptr;
|
MarioBlock *_parent = nullptr;
|
||||||
bool _started_movement = false;
|
bool _started_movement = false;
|
||||||
|
bool _fire_flower = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#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
|
// for some reason falling of the edge causes on_ground to be true, but
|
||||||
// visitor ground_y is 0
|
// visitor ground_y is 0
|
||||||
if (m_visitor.getGroundY() != 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
|
// if we just left ground gravity didn't work in custom_move
|
||||||
@ -217,15 +218,18 @@ void Mario::setBig() {
|
|||||||
setFireFlag();
|
setFireFlag();
|
||||||
} else {
|
} else {
|
||||||
setBigFlag();
|
setBigFlag();
|
||||||
setSize({BLOCK_SIZE, 2 * BLOCK_SIZE});
|
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() {
|
void Mario::unsetBig() {
|
||||||
@ -233,7 +237,7 @@ void Mario::unsetBig() {
|
|||||||
unsetFireFlag();
|
unsetFireFlag();
|
||||||
} else {
|
} else {
|
||||||
unsetBigFlag();
|
unsetBigFlag();
|
||||||
setSize({BLOCK_SIZE, BLOCK_SIZE});
|
setSize({ BLOCK_SIZE, BLOCK_SIZE });
|
||||||
setBaseRect(isJumping() ? MARIO_JUMP_SRC : MARIO_STANDING_SRC);
|
setBaseRect(isJumping() ? MARIO_JUMP_SRC : MARIO_STANDING_SRC);
|
||||||
setAnimationFrames(MARIO_WALK_ANIM);
|
setAnimationFrames(MARIO_WALK_ANIM);
|
||||||
standing_src = &MARIO_STANDING_SRC;
|
standing_src = &MARIO_STANDING_SRC;
|
||||||
|
@ -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_CHANGE_DIR_BIG_SRC = { 98, 26, 16, 32 };
|
||||||
const SDL_Rect MARIO_JUMP_BIG_SRC = { 119, 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 FLOOR_SRC = { 1, 131, 16, 16 };
|
||||||
const SDL_Rect HILL_INCLINE_SRC = { 137, 97, 16, 16 };
|
const SDL_Rect HILL_INCLINE_SRC = { 137, 97, 16, 16 };
|
||||||
const SDL_Rect HILL_DECLINE_SRC = { 205, 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 CANNON_SRC = { 256, 12, 16, 16 };
|
||||||
const SDL_Rect COIN_SRC = { 549, 202, 16, 16 };
|
const SDL_Rect COIN_SRC = { 549, 202, 16, 16 };
|
||||||
const SDL_Rect MUSHROOM_SRC = { 69, 12, 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_DESTRUCTIBLE_SRC = { 0, 0, 16, 16 };
|
||||||
extern const SDL_Rect MOD_BACKGROUND_SRC = { 16, 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 std::vector<SDL_Rect> MARIO_WALK_BIG_ANIM;
|
||||||
extern const SDL_Rect MARIO_CHANGE_DIR_BIG_SRC;
|
extern const SDL_Rect MARIO_CHANGE_DIR_BIG_SRC;
|
||||||
extern const SDL_Rect MARIO_JUMP_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 ------------------------
|
//------------------ TERRAIN ------------------------
|
||||||
extern const SDL_Rect FLOOR_SRC;
|
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 CANNON_SRC;
|
||||||
extern const SDL_Rect COIN_SRC;
|
extern const SDL_Rect COIN_SRC;
|
||||||
extern const SDL_Rect MUSHROOM_SRC;
|
extern const SDL_Rect MUSHROOM_SRC;
|
||||||
|
extern const SDL_Rect FIRE_FLOWER_SRC;
|
||||||
|
extern const SDL_Rect HARD_SRC;
|
||||||
//------------------ MODIFIERS ----------------------
|
//------------------ MODIFIERS ----------------------
|
||||||
extern const SDL_Rect MOD_DESTRUCTIBLE_SRC;
|
extern const SDL_Rect MOD_DESTRUCTIBLE_SRC;
|
||||||
extern const SDL_Rect MOD_BACKGROUND_SRC;
|
extern const SDL_Rect MOD_BACKGROUND_SRC;
|
||||||
|
Loading…
Reference in New Issue
Block a user