Mario: prepartations for multiple moving objects
This commit is contained in:
+15
-11
@@ -2,6 +2,7 @@
|
||||
#include "global_vars.hpp"
|
||||
#include "objectids.hpp"
|
||||
#include "sprites.hpp"
|
||||
#include "visitors/mario_visitor.hpp"
|
||||
|
||||
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 );
|
||||
@@ -60,10 +61,12 @@ void Mario::setStanding() {
|
||||
}
|
||||
}
|
||||
|
||||
void Mario::handleVisitor(MarioVisitor &visitor) {
|
||||
void Mario::handleVisitor(SDLPP::Visitor &visitor) {
|
||||
#ifndef EDITOR
|
||||
// TODO - https://web.archive.org/web/20130807122227/http://i276.photobucket.com/albums/kk21/jdaster64/smb_playerphysics.png
|
||||
auto &m_visitor = dynamic_cast<MarioVisitor&>(visitor);
|
||||
// handle gravity
|
||||
on_ground = visitor.isOnGround();
|
||||
on_ground = m_visitor.isOnGround();
|
||||
if(!jumping && on_ground) {
|
||||
resetMovementY();
|
||||
setTextureSourceRect(MARIO_STANDING_SRC);
|
||||
@@ -71,34 +74,35 @@ void Mario::handleVisitor(MarioVisitor &visitor) {
|
||||
resumeAnimation();
|
||||
// for some reason falling of the edge causes on_ground to be true, but
|
||||
// visitor ground_y is 0
|
||||
if(visitor.getGroundY() != 0) {
|
||||
setPos(getPos().getX(), visitor.getGroundY() - BLOCK_SIZE);
|
||||
if(m_visitor.getGroundY() != 0) {
|
||||
setPos(getPos().getX(), m_visitor.getGroundY() - BLOCK_SIZE);
|
||||
}
|
||||
}
|
||||
// if we just left ground gravity didn't work in custom_move
|
||||
if(!on_ground && !jumping && getMovement().getY() == 0) {
|
||||
addMovement(0, 2*gravity_add_falling);
|
||||
}
|
||||
if(visitor.topBlock() && getMovement().getY() < 0) {
|
||||
if(m_visitor.topBlock() && getMovement().getY() < 0) {
|
||||
resetMovementY();
|
||||
stop_jump = true;
|
||||
}
|
||||
// make sure Mario isn't stuck inside a wall
|
||||
// TODO more readable function names
|
||||
if ( visitor.isStopped() ) {
|
||||
setPos( visitor.getStopX(), getPos().getY());
|
||||
} else if ( visitor.canGoLeft() != visitor.canGoRight() && !(on_ground && visitor.getMovementBlockage().getY() > getPos().getY() + BLOCK_SIZE/2) ) {
|
||||
if ( m_visitor.isStopped() ) {
|
||||
setPos( m_visitor.getStopX(), getPos().getY());
|
||||
} else if ( m_visitor.canGoLeft() != m_visitor.canGoRight() && !(on_ground && m_visitor.getMovementBlockage().getY() > getPos().getY() + BLOCK_SIZE/2) ) {
|
||||
// only stop mario on ground if the block obstructs at least half of him (important for bug when mario lands from a high jump and is teleported if visitor is fired at wrong moment)
|
||||
SDLPP::Vec2D<double> next_pos = { visitor.getMovementBlockage().getX() + (visitor.canGoLeft() * -1 + visitor.canGoRight() * 1) * BLOCK_SIZE, getPos().getY() };
|
||||
SDLPP::Vec2D<double> next_pos = { m_visitor.getMovementBlockage().getX() + (m_visitor.canGoLeft() * -1 + m_visitor.canGoRight() * 1) * BLOCK_SIZE, getPos().getY() };
|
||||
setPos(next_pos);
|
||||
} else if (visitor.moveTop() && jumping && !stop_jump) {
|
||||
auto objPos = visitor.getRightLeftPos();
|
||||
} else if (m_visitor.moveTop() && jumping && !stop_jump) {
|
||||
auto objPos = m_visitor.getRightLeftPos();
|
||||
if(objPos.getX() < getPos().getX()) {
|
||||
setPos( objPos.getX() + BLOCK_SIZE, getPos().getY() );
|
||||
} else {
|
||||
setPos( objPos.getX() - BLOCK_SIZE, getPos().getY() );
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void Mario::jump() {
|
||||
|
||||
Reference in New Issue
Block a user