2021-04-25 20:42:55 +00:00
|
|
|
#ifndef BLOCKS_H
|
|
|
|
#define BLOCKS_H
|
|
|
|
|
|
|
|
#include "../sdlpp/sdlpp_rectrenderer.hpp"
|
2021-08-07 19:39:15 +00:00
|
|
|
#include <SDL2/SDL_rect.h>
|
2021-04-25 20:42:55 +00:00
|
|
|
#include <memory>
|
|
|
|
|
2021-05-31 12:03:11 +00:00
|
|
|
struct LandType {
|
|
|
|
enum Value { OVERWORLD = 0, UNDERWORLD = 1, WATER = 2, BOWSER = 4 };
|
|
|
|
};
|
|
|
|
|
2021-05-02 12:14:11 +00:00
|
|
|
class MarioBlock : public SDLPP::RectangleRender {
|
|
|
|
public:
|
2021-10-18 07:08:35 +00:00
|
|
|
MarioBlock(int x, int y, const std::shared_ptr<SDLPP::Renderer> &renderer,
|
|
|
|
std::shared_ptr<SDLPP::Texture> texture, SDL_Rect src,
|
|
|
|
bool can_be_destroyed = false, bool destructible = false);
|
|
|
|
void visit(SDLPP::Visitor &visitor) override;
|
|
|
|
void setTool(bool tool = true);
|
|
|
|
void setTerrain(bool terrain = true);
|
2021-05-25 20:05:50 +00:00
|
|
|
void bounce();
|
2021-08-07 19:39:15 +00:00
|
|
|
void travelToPos(const SDLPP::Vec2D<double> &target);
|
2021-10-18 07:08:35 +00:00
|
|
|
void custom_move(int ticks) override;
|
|
|
|
void setType(LandType::Value type);
|
2021-05-31 12:03:11 +00:00
|
|
|
LandType::Value getType() const;
|
2021-07-22 22:08:05 +00:00
|
|
|
virtual void onScrollUp() {}
|
|
|
|
virtual void onScrollDown() {}
|
2021-08-07 10:13:23 +00:00
|
|
|
virtual uint8_t getData() const {
|
2021-07-24 17:59:25 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2021-10-18 07:08:35 +00:00
|
|
|
virtual void setData(uint8_t /*UNUSED*/) {}
|
2021-08-04 22:32:17 +00:00
|
|
|
// handle own visitor
|
|
|
|
virtual void handleVisitor(SDLPP::Visitor &visitor) {}
|
2021-07-22 22:08:05 +00:00
|
|
|
bool hasCoin();
|
|
|
|
bool hasMushroom();
|
|
|
|
void removeCoin();
|
|
|
|
void removeMushroom();
|
2021-08-07 19:39:15 +00:00
|
|
|
void addMushroom();
|
2021-10-18 07:08:35 +00:00
|
|
|
void setCoinCount(int coins);
|
|
|
|
void setDestructible(bool destructible = true);
|
2021-07-22 22:08:05 +00:00
|
|
|
void ensureCollision();
|
2021-08-07 19:39:15 +00:00
|
|
|
bool isBouncing() const;
|
|
|
|
bool isTraveling() const;
|
|
|
|
void setBaseRect(SDL_Rect rect);
|
2021-08-07 20:25:32 +00:00
|
|
|
void checkVisibility(double rightmost_x);
|
|
|
|
bool wasVisible() const;
|
2022-11-11 18:47:35 +00:00
|
|
|
void harden();
|
2021-07-24 18:50:24 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
double bounce_speed = 0.5;
|
|
|
|
int bounce_ticks = 100;
|
2021-08-07 19:39:15 +00:00
|
|
|
double travel_speed = bounce_speed;
|
|
|
|
void gravity(int ticks);
|
|
|
|
void setOnGround(bool on_ground = true) {
|
|
|
|
_on_ground = on_ground;
|
2021-10-18 07:08:35 +00:00
|
|
|
if (on_ground) {
|
2021-08-07 19:39:15 +00:00
|
|
|
setMovement(getMovement().getX(), 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
bool isOnGround() const {
|
|
|
|
return _on_ground;
|
|
|
|
}
|
|
|
|
void setGravityTicks(int ticks) {
|
|
|
|
_base_gravity_ticks = ticks;
|
|
|
|
}
|
|
|
|
|
2021-10-18 07:08:35 +00:00
|
|
|
virtual void setWorldTypeSrc(LandType::Value world);
|
2021-05-08 22:46:10 +00:00
|
|
|
|
2022-09-23 14:46:50 +00:00
|
|
|
bool isBouncable() {
|
|
|
|
return _bouncable;
|
|
|
|
}
|
|
|
|
|
|
|
|
void setBouncable(bool bouncable = true) {
|
|
|
|
_bouncable = bouncable;
|
|
|
|
}
|
|
|
|
|
2021-05-02 12:14:11 +00:00
|
|
|
private:
|
|
|
|
bool _tool = false;
|
2021-05-07 21:17:05 +00:00
|
|
|
bool _terrain = true;
|
2021-05-23 22:07:40 +00:00
|
|
|
bool _destructible = false;
|
2021-05-31 16:54:59 +00:00
|
|
|
bool _can_be_destroyed = false;
|
2021-05-25 20:05:50 +00:00
|
|
|
bool _bouncing = false;
|
2021-08-07 19:39:15 +00:00
|
|
|
bool _traveling = false;
|
2021-07-22 22:08:05 +00:00
|
|
|
int _coins = 0;
|
|
|
|
bool _mushroom = false;
|
2021-07-24 18:50:24 +00:00
|
|
|
bool _release_coin = false;
|
|
|
|
int ticks_to_bounce = 0;
|
2021-10-18 07:08:35 +00:00
|
|
|
SDLPP::Vec2D<double> og_pos = {};
|
2021-05-31 12:03:11 +00:00
|
|
|
LandType::Value _type;
|
2021-07-24 17:59:25 +00:00
|
|
|
SDL_Rect _base_src;
|
2021-10-18 07:08:35 +00:00
|
|
|
SDLPP::Vec2D<double> _target = { 0, 0 };
|
2021-07-22 22:08:05 +00:00
|
|
|
|
2021-08-07 19:39:15 +00:00
|
|
|
bool _on_ground = true;
|
|
|
|
int _base_gravity_ticks = 1000 / 60;
|
|
|
|
int _ticks_till_gravity = 0;
|
2021-10-18 07:08:35 +00:00
|
|
|
double _gravity_acceleration = 1.0 / (64.0 / 7.0);
|
2021-08-07 20:25:32 +00:00
|
|
|
bool _was_visible = false;
|
2022-09-23 14:46:50 +00:00
|
|
|
bool _bouncable = true;
|
2021-05-02 12:14:11 +00:00
|
|
|
};
|
|
|
|
|
2021-10-18 07:08:35 +00:00
|
|
|
extern const std::vector<uint64_t> possibleBlocks;
|
|
|
|
extern const std::vector<uint64_t> possibleMods;
|
|
|
|
extern const std::vector<uint64_t> possibleCharacters;
|
|
|
|
extern const std::vector<LandType::Value> possibleLands;
|
2021-04-30 07:10:58 +00:00
|
|
|
|
2021-05-08 22:43:53 +00:00
|
|
|
struct BlockRole {
|
|
|
|
enum Value {
|
|
|
|
TERRAIN,
|
|
|
|
MODIFIER,
|
|
|
|
CHARACTER,
|
|
|
|
MARIO,
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2021-10-18 07:08:35 +00:00
|
|
|
std::shared_ptr<MarioBlock>
|
|
|
|
createTerrainBlock(uint64_t block_id, LandType::Value type,
|
|
|
|
std::shared_ptr<SDLPP::Renderer> &renderer,
|
|
|
|
bool destructible = false, bool editor = false);
|
|
|
|
std::shared_ptr<MarioBlock>
|
|
|
|
createTerrainBlock(uint64_t block_id, LandType::Value type,
|
|
|
|
std::shared_ptr<SDLPP::Renderer> &renderer, int x, int y,
|
|
|
|
bool destructible = false, bool editor = false);
|
|
|
|
std::shared_ptr<MarioBlock>
|
|
|
|
createMario(LandType::Value type, std::shared_ptr<SDLPP::Renderer> &renderer,
|
|
|
|
int x, int y, bool editor = false);
|
2021-04-25 20:42:55 +00:00
|
|
|
|
2021-10-18 07:08:35 +00:00
|
|
|
enum BlockRole::Value getBlockRole(uint64_t id);
|
2021-05-02 12:28:17 +00:00
|
|
|
|
2021-04-25 20:42:55 +00:00
|
|
|
#endif
|