Mario: change size and texture when Mario eats a mushroom
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
zv0n 2022-10-25 19:33:09 +02:00
parent 1462c2211b
commit d89712ebab
3 changed files with 47 additions and 20 deletions

View File

@ -7,7 +7,7 @@
Mario::Mario(int x, int y, const std::shared_ptr<SDLPP::Renderer> &renderer)
: MarioBlock(x, y, renderer, g_mario_texture, MARIO_STANDING_SRC) {
setAnimationFrames(MARIO_WALK_ANIM);
setAnimationFrames(*walk_anim);
setId(MARIO_ID);
setAlignment(SDLPP::OBJ_CENTER, SDLPP::OBJ_CENTER);
setAnimationSpeed(12.5);
@ -79,7 +79,7 @@ void Mario::handleVisitor(SDLPP::Visitor &visitor) {
on_ground = m_visitor.isOnGround();
if (!jumping && on_ground) {
resetMovementY();
setBaseRect(MARIO_STANDING_SRC);
setBaseRect(*standing_src);
if (!controllable) {
setDeath();
}
@ -88,7 +88,7 @@ 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() - BLOCK_SIZE);
setPos(getPos().getX(), m_visitor.getGroundY() - getDoubleRect().second.getY());
}
}
// if we just left ground gravity didn't work in custom_move
@ -164,7 +164,7 @@ void Mario::jump() {
slow_jump = getPos().getY() - 2 * BLOCK_SIZE;
addMovement(0, -jump_movement);
ticks_till_gravity = base_gravity_ticks;
setBaseRect(MARIO_JUMP_SRC);
setBaseRect(*jump_src);
pauseAnimation();
}
@ -211,3 +211,35 @@ void Mario::stopMovement() {
controllable = false;
setMovement(0, getMovement().getY());
}
void Mario::setBig() {
if (isBig()) {
setFireFlag();
} 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;
}
}
void Mario::unsetBig() {
if (hasFire()) {
unsetFireFlag();
} else {
unsetBigFlag();
setSize({BLOCK_SIZE, BLOCK_SIZE});
setBaseRect(isJumping() ? MARIO_JUMP_SRC : MARIO_STANDING_SRC);
setAnimationFrames(MARIO_WALK_ANIM);
standing_src = &MARIO_STANDING_SRC;
death_src = &MARIO_DEATH_SRC;
change_dir_src = &MARIO_CHANGE_DIR_SRC;
jump_src = &MARIO_JUMP_SRC;
walk_anim = &MARIO_WALK_ANIM;
}
}

View File

@ -25,20 +25,8 @@ public:
return _death;
}
void handleDeath();
void setBig() {
if (isBig()) {
setFireFlag();
} else {
setBigFlag();
}
}
void unsetBig() {
if (hasFire()) {
unsetFireFlag();
} else {
unsetBigFlag();
}
}
void setBig();
void unsetBig();
void setStar() {
setStarFlag();
}
@ -86,6 +74,13 @@ private:
void stopMovement();
uint8_t special_flags = 0;
// SRCs
const SDL_Rect *standing_src = &MARIO_STANDING_SRC;
const SDL_Rect *death_src = &MARIO_DEATH_SRC;
const SDL_Rect *change_dir_src = &MARIO_CHANGE_DIR_SRC;
const SDL_Rect *jump_src = &MARIO_JUMP_SRC;
const std::vector<SDL_Rect> *walk_anim = &MARIO_WALK_ANIM;
void setBigFlag() {
special_flags = special_flags | BIG_FLAG;
}

View File

@ -15,8 +15,8 @@ const SDL_Rect MARIO_JUMP_SRC = { 119, 9, 16, 16 };
const SDL_Rect MARIO_STANDING_BIG_SRC = { 1, 26, 16, 32 };
const SDL_Rect MARIO_DEATH_BIG_SRC = { 22, 26, 16, 32 };
const std::vector<SDL_Rect> MARIO_WALK_BIG_ANIM = { { 43, 26, 16, 32 },
{ 60, 9, 16, 32 },
{ 77, 9, 16, 32 } };
{ 60, 26, 16, 32 },
{ 77, 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 };