Mario editor: switching between blocks
This commit is contained in:
parent
96857a99af
commit
8b8f3b7f06
@ -28,4 +28,6 @@ std::shared_ptr<SDLPP::RectangleRender> createTerrainBlock( uint64_t block_id, B
|
||||
std::shared_ptr<SDLPP::RectangleRender> createTerrainBlock( uint64_t block_id, BlockType type, std::shared_ptr<SDLPP::Renderer> &renderer, int x, int y, std::shared_ptr<SDLPP::Texture> texture, bool collision = false );
|
||||
std::shared_ptr<SDLPP::RectangleRender> createMario( BlockType type, std::shared_ptr<SDLPP::Renderer> &renderer, int x, int y );
|
||||
|
||||
SDL_Rect getSourceRectByID( uint64_t id, BlockType type );
|
||||
|
||||
#endif
|
||||
|
@ -29,9 +29,12 @@ std::mutex destruction_mutex;
|
||||
|
||||
int current_start_index = 0;
|
||||
int current_max_index = 0;
|
||||
uint64_t current_block = 0;
|
||||
SDLPP::Vec2D<int> current_box = {0, 0};
|
||||
std::shared_ptr<SDLPP::RenderObject> current_tool = nullptr;
|
||||
|
||||
std::shared_ptr<SDLPP::Texture> g_placeholder_texture = nullptr;
|
||||
|
||||
void handleKeyDown( SDL_Keycode key, SDLPP::Scene &scene ) {
|
||||
switch ( key ) {
|
||||
case SDLK_ESCAPE:
|
||||
@ -54,11 +57,21 @@ void handleKeyDown( SDL_Keycode key, SDLPP::Scene &scene ) {
|
||||
}
|
||||
}
|
||||
|
||||
void updateTool() {
|
||||
current_tool->setTexture(g_placeholder_texture, getSourceRectByID(possibleBlocks[current_block], OVERWORLD));
|
||||
current_tool->setId(possibleBlocks[current_block]);
|
||||
current_tool->getCollisions()[0]->setId(possibleBlocks[current_block]);
|
||||
}
|
||||
|
||||
void handleKeyUp( SDL_Keycode key ) {
|
||||
switch ( key ) {
|
||||
case SDLK_a:
|
||||
current_block = (current_block + possibleBlocks.size() - 1) % possibleBlocks.size();
|
||||
updateTool();
|
||||
break;
|
||||
case SDLK_d:
|
||||
current_block = (current_block + 1) % possibleBlocks.size();
|
||||
updateTool();
|
||||
break;
|
||||
case SDLK_w:
|
||||
case SDLK_s:
|
||||
@ -243,9 +256,9 @@ int main() {
|
||||
scene->addObject( mouse );
|
||||
current_max_index = objects.size() - 18;
|
||||
|
||||
auto placeholder_texture = std::make_shared< SDLPP::Texture >(
|
||||
g_placeholder_texture = std::make_shared< SDLPP::Texture >(
|
||||
renderer, "sprites/terrain.png", MARIO_OVERWORLD_COLORKEY );
|
||||
current_tool = createTerrainBlock(FLOOR_ID, OVERWORLD, renderer, placeholder_texture, false);
|
||||
current_tool = createTerrainBlock(possibleBlocks[current_block], OVERWORLD, renderer, g_placeholder_texture, false);
|
||||
current_tool->addCollision(SDLPP::RectColider(0.1, 0.1, 0.8, 0.8));
|
||||
current_tool->setTextureAlpha(100);
|
||||
dynamic_cast<MarioBlock&>(*current_tool).setTool();
|
||||
|
Loading…
Reference in New Issue
Block a user