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) Mario::Mario(int x, int y, const std::shared_ptr<SDLPP::Renderer> &renderer)
: MarioBlock(x, y, renderer, g_mario_texture, MARIO_STANDING_SRC) { : MarioBlock(x, y, renderer, g_mario_texture, MARIO_STANDING_SRC) {
setAnimationFrames(MARIO_WALK_ANIM); setAnimationFrames(*walk_anim);
setId(MARIO_ID); setId(MARIO_ID);
setAlignment(SDLPP::OBJ_CENTER, SDLPP::OBJ_CENTER); setAlignment(SDLPP::OBJ_CENTER, SDLPP::OBJ_CENTER);
setAnimationSpeed(12.5); setAnimationSpeed(12.5);
@ -79,7 +79,7 @@ void Mario::handleVisitor(SDLPP::Visitor &visitor) {
on_ground = m_visitor.isOnGround(); on_ground = m_visitor.isOnGround();
if (!jumping && on_ground) { if (!jumping && on_ground) {
resetMovementY(); resetMovementY();
setBaseRect(MARIO_STANDING_SRC); setBaseRect(*standing_src);
if (!controllable) { if (!controllable) {
setDeath(); 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 // 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() - BLOCK_SIZE); 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
@ -164,7 +164,7 @@ void Mario::jump() {
slow_jump = getPos().getY() - 2 * BLOCK_SIZE; slow_jump = getPos().getY() - 2 * BLOCK_SIZE;
addMovement(0, -jump_movement); addMovement(0, -jump_movement);
ticks_till_gravity = base_gravity_ticks; ticks_till_gravity = base_gravity_ticks;
setBaseRect(MARIO_JUMP_SRC); setBaseRect(*jump_src);
pauseAnimation(); pauseAnimation();
} }
@ -211,3 +211,35 @@ void Mario::stopMovement() {
controllable = false; controllable = false;
setMovement(0, getMovement().getY()); 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; return _death;
} }
void handleDeath(); void handleDeath();
void setBig() { void setBig();
if (isBig()) { void unsetBig();
setFireFlag();
} else {
setBigFlag();
}
}
void unsetBig() {
if (hasFire()) {
unsetFireFlag();
} else {
unsetBigFlag();
}
}
void setStar() { void setStar() {
setStarFlag(); setStarFlag();
} }
@ -86,6 +74,13 @@ private:
void stopMovement(); void stopMovement();
uint8_t special_flags = 0; 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() { void setBigFlag() {
special_flags = special_flags | BIG_FLAG; 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_STANDING_BIG_SRC = { 1, 26, 16, 32 };
const SDL_Rect MARIO_DEATH_BIG_SRC = { 22, 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 }, const std::vector<SDL_Rect> MARIO_WALK_BIG_ANIM = { { 43, 26, 16, 32 },
{ 60, 9, 16, 32 }, { 60, 26, 16, 32 },
{ 77, 9, 16, 32 } }; { 77, 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 };