Mario: end of level logic
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
#include "mario.hpp"
|
||||
#include "blocks.hpp"
|
||||
#include "global_vars.hpp"
|
||||
#include "objectids.hpp"
|
||||
#include "sprites.hpp"
|
||||
@@ -34,6 +35,9 @@ Mario::Mario(int x, int y, const std::shared_ptr<SDLPP::Renderer> &renderer)
|
||||
Mario::Mario(const std::shared_ptr<SDLPP::Renderer> &renderer)
|
||||
: Mario(0, 0, renderer) {}
|
||||
void Mario::walkLeft() {
|
||||
if (!controllable) {
|
||||
return;
|
||||
}
|
||||
if (on_ground)
|
||||
resumeAnimation();
|
||||
addMovement(-side_movement, 0);
|
||||
@@ -46,6 +50,9 @@ void Mario::walkLeft() {
|
||||
}
|
||||
|
||||
void Mario::walkRight() {
|
||||
if (!controllable) {
|
||||
return;
|
||||
}
|
||||
if (on_ground)
|
||||
resumeAnimation();
|
||||
addMovement(side_movement, 0);
|
||||
@@ -73,6 +80,9 @@ void Mario::handleVisitor(SDLPP::Visitor &visitor) {
|
||||
if (!jumping && on_ground) {
|
||||
resetMovementY();
|
||||
setBaseRect(MARIO_STANDING_SRC);
|
||||
if (!controllable) {
|
||||
setDeath();
|
||||
}
|
||||
if (getMovement().getX() != 0)
|
||||
resumeAnimation();
|
||||
// for some reason falling of the edge causes on_ground to be true, but
|
||||
@@ -120,10 +130,20 @@ void Mario::handleVisitor(SDLPP::Visitor &visitor) {
|
||||
if (m_visitor.hasMushroom()) {
|
||||
setType(LandType::UNDERWORLD);
|
||||
}
|
||||
if (m_visitor.levelEnd() && controllable) {
|
||||
if (std::abs(getPos().getX() - m_visitor.getEndPos().getX()) <
|
||||
BLOCK_SIZE / 8) {
|
||||
setPos(m_visitor.getEndPos().getX(), getPos().getY());
|
||||
stopMovement();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void Mario::jump() {
|
||||
if (!controllable) {
|
||||
return;
|
||||
}
|
||||
if (!on_ground)
|
||||
return;
|
||||
jumping = true;
|
||||
@@ -172,3 +192,8 @@ void Mario::setWorldTypeSrc(LandType::Value /*UNUSED*/) {
|
||||
MarioBlock::setWorldTypeSrc(LandType::OVERWORLD);
|
||||
// TODO
|
||||
}
|
||||
|
||||
void Mario::stopMovement() {
|
||||
controllable = false;
|
||||
setMovement(0, getMovement().getY());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user