Mario: Fireball works
This commit is contained in:
+26
-7
@@ -4,9 +4,10 @@
|
||||
#include "objectids.hpp"
|
||||
#include "sprites.hpp"
|
||||
#include "visitors/mario_visitor.hpp"
|
||||
#include "blocks/fireball.hpp"
|
||||
|
||||
Mario::Mario(int x, int y, const std::shared_ptr<SDLPP::Renderer> &renderer)
|
||||
: MarioBlock(x, y, renderer, g_mario_texture, MARIO_STANDING_SRC) {
|
||||
Mario::Mario(int x, int y, const std::shared_ptr<SDLPP::Renderer> &renderer, std::function<void(std::shared_ptr<MarioBlock>&, bool)> addObject)
|
||||
: MarioBlock(x, y, renderer, g_mario_texture, MARIO_STANDING_SRC), _addObject(addObject) {
|
||||
setAnimationFrames(*walk_anim);
|
||||
setId(MARIO_ID);
|
||||
setAlignment(SDLPP::OBJ_CENTER, SDLPP::OBJ_CENTER);
|
||||
@@ -32,8 +33,8 @@ Mario::Mario(int x, int y, const std::shared_ptr<SDLPP::Renderer> &renderer)
|
||||
setStatic(false);
|
||||
bounce_speed *= 4;
|
||||
}
|
||||
Mario::Mario(const std::shared_ptr<SDLPP::Renderer> &renderer)
|
||||
: Mario(0, 0, renderer) {}
|
||||
Mario::Mario(const std::shared_ptr<SDLPP::Renderer> &renderer, std::function<void(std::shared_ptr<MarioBlock>&, bool)> addObject)
|
||||
: Mario(0, 0, renderer, addObject) {}
|
||||
void Mario::walkLeft() {
|
||||
if (!controllable) {
|
||||
return;
|
||||
@@ -107,9 +108,7 @@ void Mario::handleVisitor(SDLPP::Visitor &visitor) {
|
||||
// TODO more readable function names
|
||||
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)) {
|
||||
} else if (m_visitor.canGoLeft() != m_visitor.canGoRight()) {
|
||||
// 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)
|
||||
@@ -169,6 +168,26 @@ void Mario::jump() {
|
||||
pauseAnimation();
|
||||
}
|
||||
|
||||
#ifndef EDITOR
|
||||
void Mario::fire() {
|
||||
if (!hasFire()) {
|
||||
return;
|
||||
}
|
||||
auto fireball = std::make_shared<Fireball>(0, 0, renderer);
|
||||
fireball->setPos(getPos() + SDLPP::Vec2D<double>((faces_right ? 1 : -1) * BLOCK_SIZE, BLOCK_SIZE));
|
||||
fireball->setMovementDir(!faces_right);
|
||||
auto fireball_m = std::static_pointer_cast<MarioBlock>(fireball);
|
||||
fireball->setHidden(false);
|
||||
_addObject(fireball_m, true);
|
||||
}
|
||||
void Mario::setAddObjFunc(std::function<void(std::shared_ptr<MarioBlock>&, bool)> func) {
|
||||
_addObject = func;
|
||||
}
|
||||
std::function<void(std::shared_ptr<MarioBlock>&, bool)> Mario::getAddObjFunc() {
|
||||
return _addObject;
|
||||
}
|
||||
#endif
|
||||
|
||||
void Mario::stopJump() {
|
||||
stop_jump = true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user