70 lines
2.4 KiB
C++
70 lines
2.4 KiB
C++
|
#include "fireball.hpp"
|
||
|
#include "../sprites.hpp"
|
||
|
#include "../global_vars.hpp"
|
||
|
#include "../objectids.hpp"
|
||
|
#include "../visitors/projectile_visitor.hpp"
|
||
|
|
||
|
Fireball::Fireball(int x, int y, std::shared_ptr<SDLPP::Renderer> &renderer)
|
||
|
: MarioBlock(x, y, renderer, g_items_texture, FIRE_BALL_ANIM[3]) {
|
||
|
setHidden(true);
|
||
|
ensureCollision();
|
||
|
setSize({BLOCK_SIZE/2, BLOCK_SIZE/2});
|
||
|
setId(FIREBALL_ID);
|
||
|
setBouncable(true);
|
||
|
setAnimationFrames(FIRE_BALL_ANIM);
|
||
|
setAnimationSpeed(16);
|
||
|
resumeAnimation();
|
||
|
setOnGround(false);
|
||
|
|
||
|
auto bottom_detect = SDLPP::RectColider(0.2, 1, 0.6, 0, NPC_FLOOR_DETECT);
|
||
|
bottom_detect.setColor("#FF0000");
|
||
|
bottom_detect.setOutlineColor("#FF0000");
|
||
|
bottom_detect.setMinHeight(1);
|
||
|
addCollision(bottom_detect);
|
||
|
addCollision(SDLPP::RectColider(0, 0.25, 0.1, 0.6, NPC_LEFT_SIDE_DETECT));
|
||
|
addCollision(
|
||
|
SDLPP::RectColider(0.9, 0.25, 0.1, 0.6, NPC_RIGHT_SIDE_DETECT));
|
||
|
jump_movement = movementSpeed;
|
||
|
}
|
||
|
|
||
|
void Fireball::custom_move(int ticks) {
|
||
|
ticks_till_death -= ticks;
|
||
|
if (ticks_till_death <= 0) {
|
||
|
destroy();
|
||
|
}
|
||
|
gravity(ticks);
|
||
|
MarioBlock::custom_move(ticks);
|
||
|
}
|
||
|
|
||
|
void Fireball::setMovementDir(bool left) {
|
||
|
setMovement(movementSpeed / 2 * (left ? -1 : 1), 0);
|
||
|
}
|
||
|
|
||
|
void Fireball::handleVisitor(SDLPP::Visitor &visitor) {
|
||
|
#ifndef EDITOR
|
||
|
// TODO -
|
||
|
// https://web.archive.org/web/20130807122227/http://i276.photobucket.com/albums/kk21/jdaster64/smb_playerphysics.png
|
||
|
auto &p_visitor = dynamic_cast<ProjectileVisitor &>(visitor);
|
||
|
// handle gravity
|
||
|
setOnGround(p_visitor.isOnGround());
|
||
|
if(p_visitor.isOnGround() && jump_movement > movementSpeed/16) {
|
||
|
setMovement(getMovement().getX(), -jump_movement);
|
||
|
setPos(getPos() - SDLPP::Vec2D<double>(0, jump_movement * BLOCK_SIZE));
|
||
|
jump_movement /= 2;
|
||
|
setOnGround(false);
|
||
|
}
|
||
|
if (p_visitor.canGoLeft() != p_visitor.canGoRight()) {
|
||
|
if(p_visitor.canGoLeft()) {
|
||
|
// we only want to be the size of the fireball left of the blockage
|
||
|
setPos(-1 * getDoubleRect().second.getX() + p_visitor.getMovementBlockage().getX(), getPos().getY());
|
||
|
} else {
|
||
|
// we want to be size of the blockage away from the blockage
|
||
|
setPos(BLOCK_SIZE + p_visitor.getMovementBlockage().getX(), getPos().getY());
|
||
|
}
|
||
|
setMovementDir(getMovement().getX() > 0);
|
||
|
}
|
||
|
if (p_visitor.getDeath()) {
|
||
|
destroy();
|
||
|
}
|
||
|
#endif
|
||
|
}
|