zv0n
9402f2afa2
Some checks reported errors
continuous-integration/drone/push Build encountered an error
175 lines
4.0 KiB
C++
175 lines
4.0 KiB
C++
#ifndef MARIO_VISITOR_H
|
|
#define MARIO_VISITOR_H
|
|
|
|
#include "../../sdlpp/sdlpp_visitor.hpp"
|
|
#include "../../sdlpp/sdlpp_geometry.hpp"
|
|
#include "../../sdlpp/sdlpp_scene.hpp"
|
|
#include "../blocks.hpp"
|
|
|
|
class MarioVisitor : public SDLPP::Visitor {
|
|
public:
|
|
MarioVisitor(bool is_jumping, SDLPP::Scene &scene, int &coin_count,
|
|
std::vector<std::shared_ptr<MarioBlock>> &moving_objects,
|
|
bool is_big, bool has_star)
|
|
: jumping(is_jumping), _scene(scene), _coin_count(coin_count),
|
|
_moving_objects(moving_objects), _is_big(is_big),
|
|
_has_star(has_star) {}
|
|
void visit(const SDLPP::RenderObject &obj) override;
|
|
bool isOnGround() const {
|
|
return onGround;
|
|
}
|
|
bool isDead() const {
|
|
return _death;
|
|
}
|
|
bool isInstantDead() const {
|
|
return _instant_death;
|
|
}
|
|
bool isStopped() const {
|
|
return stop;
|
|
}
|
|
double newXPos() const {
|
|
return newX;
|
|
}
|
|
void setFromId(uint64_t id) override {
|
|
from = id;
|
|
}
|
|
uint64_t getFromId() const override {
|
|
return from;
|
|
}
|
|
void setVisitorType(uint64_t type) override {
|
|
_type = type;
|
|
}
|
|
uint64_t getVisitorType() const override {
|
|
return _type;
|
|
}
|
|
bool canGoLeft() const {
|
|
return !left;
|
|
}
|
|
bool canGoRight() const {
|
|
return !right;
|
|
}
|
|
double getGroundY() const {
|
|
return groundY;
|
|
}
|
|
bool topBlock() const {
|
|
return top_hit;
|
|
}
|
|
bool moveTop() const {
|
|
return top_left_right && !top_hit;
|
|
}
|
|
const SDLPP::Vec2D<double> &getRightLeftPos() {
|
|
return rightleftpos;
|
|
}
|
|
|
|
bool canDestroy() const {
|
|
return jumping && !top_hit;
|
|
}
|
|
|
|
const SDLPP::Vec2D<double> &getMovementBlockage() {
|
|
return movement_blockage;
|
|
}
|
|
|
|
double getStopX() const {
|
|
return newX;
|
|
}
|
|
|
|
void setCoin() {
|
|
// TODO remove coin?
|
|
coin = true;
|
|
_coin_count++;
|
|
}
|
|
|
|
bool hasCoin() const {
|
|
return coin;
|
|
}
|
|
|
|
void setCoinBlock(std::shared_ptr<MarioBlock> &coin) {
|
|
// TODO remove coin_block?
|
|
coin_block = coin;
|
|
_scene.addObject(coin);
|
|
_scene.moveZJustAboveBackground(coin);
|
|
}
|
|
|
|
bool hasCoinBlock() {
|
|
return coin_block != nullptr;
|
|
}
|
|
|
|
std::shared_ptr<MarioBlock> &getCoinBlock() {
|
|
return coin_block;
|
|
}
|
|
|
|
bool hasMushroom() const {
|
|
return mushroom;
|
|
}
|
|
|
|
void setMushroomBlock(std::shared_ptr<MarioBlock> &mushroom) {
|
|
_scene.addObject(mushroom);
|
|
_scene.moveZJustAboveBackground(mushroom);
|
|
_moving_objects.push_back(mushroom);
|
|
}
|
|
|
|
bool shouldBounce() {
|
|
return _bounce;
|
|
}
|
|
|
|
bool levelEnd() {
|
|
return _end;
|
|
}
|
|
|
|
const SDLPP::Vec2D<double> &getEndPos() {
|
|
return endPos;
|
|
}
|
|
|
|
bool isBig() const {
|
|
return _is_big;
|
|
}
|
|
|
|
bool hasStar() const {
|
|
return _has_star;
|
|
}
|
|
bool hasTeleport() const {
|
|
return !teleport_level.empty();
|
|
}
|
|
const std::string &getTeleportLevel() const {
|
|
return teleport_level;
|
|
}
|
|
void setTeleportLevel(const std::string &level) {
|
|
teleport_level = level;
|
|
}
|
|
bool teleportBottom() {
|
|
return teleport_bottom;
|
|
}
|
|
|
|
private:
|
|
bool onGround = false;
|
|
double groundY = 0;
|
|
bool stop = false;
|
|
double newX{};
|
|
uint64_t from = -1;
|
|
bool left = false;
|
|
bool right = false;
|
|
uint64_t _type = 0;
|
|
bool top_hit = false;
|
|
SDLPP::Vec2D<double> rightleftpos;
|
|
bool top_left_right = false;
|
|
bool jumping;
|
|
bool coin = false;
|
|
SDLPP::Vec2D<double> movement_blockage;
|
|
std::shared_ptr<MarioBlock> coin_block = nullptr;
|
|
SDLPP::Scene &_scene;
|
|
int &_coin_count;
|
|
bool mushroom = false;
|
|
std::vector<std::shared_ptr<MarioBlock>> &_moving_objects;
|
|
bool _bounce = false;
|
|
bool _end = false;
|
|
SDLPP::Vec2D<double> endPos;
|
|
bool _is_big = false;
|
|
bool _has_star = false;
|
|
bool _death = false;
|
|
bool _instant_death = false;
|
|
std::string teleport_level = "";
|
|
bool teleport_bottom = false;
|
|
};
|
|
|
|
#endif
|