Refactor to use objects for terrain/mod creation, added coin modifier

This commit is contained in:
2021-07-23 00:08:05 +02:00
parent 79d9f266b4
commit 3be728843a
15 changed files with 1384 additions and 127 deletions
+23 -17
View File
@@ -2,6 +2,7 @@
#define BLOCKS_H
#include "../sdlpp/sdlpp_rectrenderer.hpp"
#include "../sdlpp/sdlpp_fontconfiguration.hpp"
#include <memory>
struct LandType {
@@ -10,7 +11,7 @@ struct LandType {
class MarioBlock : public SDLPP::RectangleRender {
public:
MarioBlock( int x, int y, std::shared_ptr< SDLPP::Renderer > renderer,
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 );
@@ -19,6 +20,17 @@ public:
virtual void custom_move(int ticks) override;
void setType(LandType::Value type);
LandType::Value getType() const;
virtual void onScrollUp() {}
virtual void onScrollDown() {}
virtual uint8_t getData() {return 0;}
virtual void setData(uint8_t /*UNUSED*/) {}
bool hasCoin();
bool hasMushroom();
void removeCoin();
void removeMushroom();
void setCoinCount(int coins);
void setDestructible(bool destructible = true);
void ensureCollision();
private:
bool _tool = false;
@@ -26,10 +38,14 @@ private:
bool _destructible = false;
bool _can_be_destroyed = false;
bool _bouncing = false;
int _coins = 0;
bool _mushroom = false;
const int bounce_ticks = 100;
int ticks_to_bounce = bounce_ticks;
SDLPP::Vec2D<double> og_pos = {};
LandType::Value _type;
virtual void setWorldTypeSrc(LandType::Value world);
};
extern const std::vector< uint64_t > possibleBlocks;
@@ -46,30 +62,20 @@ struct BlockRole {
};
};
std::shared_ptr< SDLPP::RectangleRender >
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< SDLPP::RectangleRender >
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< SDLPP::RectangleRender >
createTerrainBlock( uint64_t block_id, LandType::Value type,
std::shared_ptr< SDLPP::Renderer > &renderer,
std::shared_ptr< SDLPP::Texture > texture,
bool destructible = false, bool editor = false );
std::shared_ptr< SDLPP::RectangleRender >
createTerrainBlock( uint64_t block_id, LandType::Value type,
std::shared_ptr< SDLPP::Renderer > &renderer, int x, int y,
std::shared_ptr< SDLPP::Texture > texture,
bool destructible = false, bool editor = false );
std::shared_ptr< SDLPP::RectangleRender >
std::shared_ptr< MarioBlock >
createMario( LandType::Value type, std::shared_ptr< SDLPP::Renderer > &renderer,
int x, int y );
SDL_Rect getSourceRectByID( uint64_t id, LandType::Value type );
int x, int y, bool editor = false );
enum BlockRole::Value getBlockRole( uint64_t id );
SDL_Rect getSourceRectByID( uint64_t id, LandType::Value type );
#endif