2021-04-25 20:42:55 +00:00
|
|
|
#ifndef MARIO_VISITOR_H
|
|
|
|
#define MARIO_VISITOR_H
|
|
|
|
|
2021-08-04 22:32:17 +00:00
|
|
|
#include "../../sdlpp/sdlpp_visitor.hpp"
|
|
|
|
#include "../../sdlpp/sdlpp_geometry.hpp"
|
|
|
|
#include "../../sdlpp/sdlpp_scene.hpp"
|
|
|
|
#include "../blocks.hpp"
|
2021-04-25 20:42:55 +00:00
|
|
|
|
|
|
|
class MarioVisitor : public SDLPP::Visitor {
|
|
|
|
public:
|
2022-09-22 18:16:46 +00:00
|
|
|
MarioVisitor(bool is_jumping, SDLPP::Scene &scene, bool &death,
|
2021-10-18 08:10:43 +00:00
|
|
|
int &coin_count,
|
|
|
|
std::vector<std::shared_ptr<MarioBlock>> &moving_objects)
|
2022-09-22 18:16:46 +00:00
|
|
|
: jumping(is_jumping), _scene(scene), _death(death),
|
2021-10-18 08:10:43 +00:00
|
|
|
_coin_count(coin_count), _moving_objects(moving_objects) {}
|
|
|
|
void visit(const SDLPP::RenderObject &obj) override;
|
2021-08-07 10:13:23 +00:00
|
|
|
bool isOnGround() const {
|
2021-04-25 20:42:55 +00:00
|
|
|
return onGround;
|
|
|
|
}
|
2021-08-07 10:13:23 +00:00
|
|
|
bool isDead() const {
|
2022-09-22 18:16:46 +00:00
|
|
|
return _death;
|
2021-04-25 20:42:55 +00:00
|
|
|
}
|
2021-08-07 10:13:23 +00:00
|
|
|
bool isStopped() const {
|
2021-04-26 19:59:21 +00:00
|
|
|
return stop;
|
|
|
|
}
|
2021-08-07 10:13:23 +00:00
|
|
|
double newXPos() const {
|
2021-04-26 19:59:21 +00:00
|
|
|
return newX;
|
|
|
|
}
|
2021-10-18 08:10:43 +00:00
|
|
|
void setFromId(uint64_t id) override {
|
2021-04-26 19:59:21 +00:00
|
|
|
from = id;
|
|
|
|
}
|
2021-08-07 10:13:23 +00:00
|
|
|
uint64_t getFromId() const override {
|
2021-05-02 12:14:11 +00:00
|
|
|
return from;
|
|
|
|
}
|
2021-10-18 08:10:43 +00:00
|
|
|
void setVisitorType(uint64_t type) override {
|
2021-05-02 12:14:11 +00:00
|
|
|
_type = type;
|
|
|
|
}
|
2021-08-07 10:13:23 +00:00
|
|
|
uint64_t getVisitorType() const override {
|
2021-05-02 12:14:11 +00:00
|
|
|
return _type;
|
|
|
|
}
|
2021-08-07 10:13:23 +00:00
|
|
|
bool canGoLeft() const {
|
2021-04-29 10:33:31 +00:00
|
|
|
return !left;
|
|
|
|
}
|
2021-08-07 10:13:23 +00:00
|
|
|
bool canGoRight() const {
|
2021-04-29 10:33:31 +00:00
|
|
|
return !right;
|
|
|
|
}
|
2021-08-07 10:13:23 +00:00
|
|
|
double getGroundY() const {
|
2021-05-22 20:36:53 +00:00
|
|
|
return groundY;
|
|
|
|
}
|
2021-08-07 10:13:23 +00:00
|
|
|
bool topBlock() const {
|
2021-05-23 21:57:29 +00:00
|
|
|
return top_hit;
|
|
|
|
}
|
2021-08-07 10:13:23 +00:00
|
|
|
bool moveTop() const {
|
2021-05-26 15:48:33 +00:00
|
|
|
return top_left_right && !top_hit;
|
2021-05-25 10:26:04 +00:00
|
|
|
}
|
|
|
|
const SDLPP::Vec2D<double> &getRightLeftPos() {
|
|
|
|
return rightleftpos;
|
|
|
|
}
|
|
|
|
|
2021-08-07 10:13:23 +00:00
|
|
|
bool canDestroy() const {
|
2021-05-25 10:26:04 +00:00
|
|
|
return jumping && !top_hit;
|
|
|
|
}
|
2021-04-26 19:59:21 +00:00
|
|
|
|
2021-05-25 22:46:19 +00:00
|
|
|
const SDLPP::Vec2D<double> &getMovementBlockage() {
|
|
|
|
return movement_blockage;
|
|
|
|
}
|
|
|
|
|
2021-08-07 10:13:23 +00:00
|
|
|
double getStopX() const {
|
2021-05-25 22:46:19 +00:00
|
|
|
return newX;
|
|
|
|
}
|
|
|
|
|
2021-07-22 22:08:05 +00:00
|
|
|
void setCoin() {
|
2021-08-04 22:32:17 +00:00
|
|
|
// TODO remove coin?
|
2021-07-22 22:08:05 +00:00
|
|
|
coin = true;
|
2021-08-04 22:32:17 +00:00
|
|
|
_coin_count++;
|
2021-07-22 22:08:05 +00:00
|
|
|
}
|
|
|
|
|
2021-08-07 10:13:23 +00:00
|
|
|
bool hasCoin() const {
|
2021-07-22 22:08:05 +00:00
|
|
|
return coin;
|
|
|
|
}
|
|
|
|
|
2021-07-24 18:50:24 +00:00
|
|
|
void setCoinBlock(std::shared_ptr<MarioBlock> &coin) {
|
2021-08-04 22:32:17 +00:00
|
|
|
// TODO remove coin_block?
|
2021-07-24 18:50:24 +00:00
|
|
|
coin_block = coin;
|
2021-08-04 22:32:17 +00:00
|
|
|
_scene.addObject(coin);
|
2021-08-07 19:59:06 +00:00
|
|
|
_scene.moveZJustAboveBackground(coin);
|
2021-07-24 18:50:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool hasCoinBlock() {
|
|
|
|
return coin_block != nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::shared_ptr<MarioBlock> &getCoinBlock() {
|
|
|
|
return coin_block;
|
|
|
|
}
|
|
|
|
|
2021-08-07 19:42:51 +00:00
|
|
|
bool hasMushroom() const {
|
|
|
|
return mushroom;
|
|
|
|
}
|
|
|
|
|
|
|
|
void setMushroomBlock(std::shared_ptr<MarioBlock> &mushroom) {
|
|
|
|
_scene.addObject(mushroom);
|
2021-08-07 19:59:06 +00:00
|
|
|
_scene.moveZJustAboveBackground(mushroom);
|
2021-08-07 19:42:51 +00:00
|
|
|
_moving_objects.push_back(mushroom);
|
|
|
|
}
|
|
|
|
|
2021-08-08 19:40:00 +00:00
|
|
|
bool shouldBounce() {
|
|
|
|
return _bounce;
|
|
|
|
}
|
|
|
|
|
2022-09-23 14:46:50 +00:00
|
|
|
bool levelEnd() {
|
|
|
|
return _end;
|
|
|
|
}
|
|
|
|
|
|
|
|
const SDLPP::Vec2D<double> &getEndPos() {
|
|
|
|
return endPos;
|
|
|
|
}
|
|
|
|
|
2021-04-25 20:42:55 +00:00
|
|
|
private:
|
|
|
|
bool onGround = false;
|
2021-05-22 20:36:53 +00:00
|
|
|
double groundY = 0;
|
2021-04-26 19:59:21 +00:00
|
|
|
bool stop = false;
|
2021-08-07 10:13:23 +00:00
|
|
|
double newX{};
|
2021-04-26 19:59:21 +00:00
|
|
|
uint64_t from = -1;
|
2021-04-29 10:33:31 +00:00
|
|
|
bool left = false;
|
|
|
|
bool right = false;
|
2021-05-02 12:14:11 +00:00
|
|
|
uint64_t _type = 0;
|
2021-05-23 21:57:29 +00:00
|
|
|
bool top_hit = false;
|
2021-05-25 10:26:04 +00:00
|
|
|
SDLPP::Vec2D<double> rightleftpos;
|
|
|
|
bool top_left_right = false;
|
|
|
|
bool jumping;
|
2021-07-22 22:08:05 +00:00
|
|
|
bool coin = false;
|
2021-05-25 22:46:19 +00:00
|
|
|
SDLPP::Vec2D<double> movement_blockage;
|
2021-07-24 18:50:24 +00:00
|
|
|
std::shared_ptr<MarioBlock> coin_block = nullptr;
|
2021-08-04 22:32:17 +00:00
|
|
|
SDLPP::Scene &_scene;
|
2022-09-22 18:16:46 +00:00
|
|
|
bool &_death;
|
2021-08-04 22:32:17 +00:00
|
|
|
int &_coin_count;
|
2021-08-07 19:42:51 +00:00
|
|
|
bool mushroom = false;
|
2021-10-18 08:10:43 +00:00
|
|
|
std::vector<std::shared_ptr<MarioBlock>> &_moving_objects;
|
2021-08-08 19:40:00 +00:00
|
|
|
bool _bounce = false;
|
2022-09-23 14:46:50 +00:00
|
|
|
bool _end = false;
|
|
|
|
SDLPP::Vec2D<double> endPos;
|
2021-05-26 16:24:09 +00:00
|
|
|
};
|
|
|
|
|
2021-04-25 20:42:55 +00:00
|
|
|
#endif
|