From 2617156833e13ec89f9d51e0d7662411be2d004f Mon Sep 17 00:00:00 2001 From: zvon Date: Thu, 24 Jun 2021 20:53:58 +0200 Subject: [PATCH] Mod texture --- mario/blocks.cpp | 8 ++++++-- mario/editor.cpp | 25 +++++++++++++++++++------ mario/global_vars.cpp | 2 ++ mario/global_vars.hpp | 2 ++ mario/maploader.cpp | 2 +- mario/objectids.hpp | 2 ++ mario/sprites.cpp | 6 ++++-- mario/sprites.hpp | 6 ++++-- 8 files changed, 40 insertions(+), 13 deletions(-) diff --git a/mario/blocks.cpp b/mario/blocks.cpp index 8485966..9daaad7 100644 --- a/mario/blocks.cpp +++ b/mario/blocks.cpp @@ -156,6 +156,8 @@ const std::vector< uint64_t > possibleBlocks = { const std::vector< uint64_t > possibleMods = { DESTRUCTIBLE_MODIFIER_ID, BACKGROUND_MODIFIER_ID, + COIN_MODIFIER_ID, + MUSHROOM_MODIFIER_ID, }; const std::vector< uint64_t > possibleCharacters = { @@ -229,8 +231,10 @@ const std::unordered_map< uint64_t, const SDL_Rect * > block_mapping = { { CANNON_PEDESTAL_ID, &CANNON_PEDESTAL_SRC }, { CANNON_ID, &CANNON_SRC }, { MARIO_ID, &MARIO_STANDING_SRC }, - { DESTRUCTIBLE_MODIFIER_ID, &DESTRUCTIBLE_SRC }, - { BACKGROUND_MODIFIER_ID, &BACKGROUND_SRC }, + { DESTRUCTIBLE_MODIFIER_ID, &MOD_DESTRUCTIBLE_SRC }, + { BACKGROUND_MODIFIER_ID, &MOD_BACKGROUND_SRC }, + { COIN_MODIFIER_ID, &MOD_COIN_SRC }, + { MUSHROOM_MODIFIER_ID, &MOD_MUSHROOM_SRC }, }; const std::unordered_map< uint64_t, uint64_t > block_flags = { diff --git a/mario/editor.cpp b/mario/editor.cpp index 41b00a8..98e486d 100644 --- a/mario/editor.cpp +++ b/mario/editor.cpp @@ -89,6 +89,7 @@ struct GlobalVars { std::shared_ptr< SDLPP::RenderObject > current_tool; std::shared_ptr< SDLPP::Texture > translucent_terrain_texture; std::shared_ptr< SDLPP::Texture > translucent_mario_texture; + std::shared_ptr< SDLPP::Texture > translucent_mod_texture; std::shared_ptr< SDLPP::RenderObject > mario; SDLPP::Vec2D< int > mario_pos; }; @@ -121,7 +122,7 @@ void updateTool() { target_texture = global_vars.translucent_mario_texture; break; case BlockRole::MODIFIER: - target_texture = global_vars.translucent_terrain_texture; + target_texture = global_vars.translucent_mod_texture; break; case BlockRole::CHARACTER: break; @@ -614,7 +615,7 @@ void placeTool( SDLPP::Scene &scene ) { LandType::OVERWORLD, renderer, global_vars.mouse.edit_box.getX(), global_vars.mouse.edit_box.getY(), - global_vars.translucent_terrain_texture, false, true ); + global_vars.translucent_mod_texture, false, true ); new_obj->getCollisions()[0]->setId( EDITOR_TERRAIN_ID ); // TODO createModifierBlock dynamic_cast< MarioBlock * >( new_obj.get() ) @@ -796,16 +797,22 @@ void populateToolGrid( for ( auto &block : blocks ) { switch ( type ) { case ToolType::CHARACTER: - if ( block == MARIO_ID ) + if ( block == MARIO_ID ) { tool_store.push_back( createMario( global_vars.current_world_type, renderer, 0, 0 ) ); - else - // fall through - case ToolType::BLOCK: + break; + } + // fall through case ToolType::MOD: + tool_store.push_back( + createTerrainBlock( block, global_vars.current_world_type, + renderer, g_mod_texture, false, true ) ); + break; + case ToolType::BLOCK: tool_store.push_back( createTerrainBlock( block, global_vars.current_world_type, renderer, false, true ) ); + break; default: break; } @@ -922,9 +929,14 @@ int main() { renderer, "sprites/terrain.png", MARIO_OVERWORLD_COLORKEY ); g_mario_texture = std::make_shared< SDLPP::Texture >( renderer, "sprites/mario.png", MARIO_OVERWORLD_COLORKEY ); + g_mod_texture = std::make_shared( + renderer, "sprites/mods.png"); g_translucent_terrain_texture = std::make_shared< SDLPP::Texture >( renderer, "sprites/terrain.png", MARIO_OVERWORLD_COLORKEY ); g_translucent_terrain_texture->setAlpha( 100 ); + g_translucent_mod_texture = std::make_shared( + renderer, "sprites/mods.png"); + g_translucent_mod_texture->setAlpha( 100 ); auto scene = std::make_shared< SDLPP::Scene >( renderer ); auto bg = std::make_shared< SDLPP::RectangleRender >( @@ -1045,6 +1057,7 @@ int main() { global_vars.current_tool->removeCollisions(); global_vars.current_tool->addCollision( SDLPP::RectColider( 0.1, 0.1, 0.8, 0.8 ) ); + global_vars.translucent_mod_texture = g_translucent_mod_texture; dynamic_cast< MarioBlock & >( *global_vars.current_tool ).setTool(); scene->addObject( global_vars.current_tool ); scene->moveZTop( global_vars.current_tool ); diff --git a/mario/global_vars.cpp b/mario/global_vars.cpp index 9bbb60d..7bfac60 100644 --- a/mario/global_vars.cpp +++ b/mario/global_vars.cpp @@ -3,5 +3,7 @@ std::shared_ptr< SDLPP::Texture > g_terrain_texture{}; std::shared_ptr< SDLPP::Texture > g_mario_texture{}; +std::shared_ptr< SDLPP::Texture > g_mod_texture{}; std::shared_ptr< SDLPP::Texture > g_translucent_terrain_texture{}; +std::shared_ptr< SDLPP::Texture > g_translucent_mod_texture{}; std::shared_ptr< SDLPP::Scene > g_playground{}; diff --git a/mario/global_vars.hpp b/mario/global_vars.hpp index 2577870..26d4850 100644 --- a/mario/global_vars.hpp +++ b/mario/global_vars.hpp @@ -5,7 +5,9 @@ extern std::shared_ptr< SDLPP::Texture > g_terrain_texture; extern std::shared_ptr< SDLPP::Texture > g_mario_texture; +extern std::shared_ptr< SDLPP::Texture > g_mod_texture; extern std::shared_ptr< SDLPP::Texture > g_translucent_terrain_texture; +extern std::shared_ptr< SDLPP::Texture > g_translucent_mod_texture; extern std::shared_ptr< SDLPP::Scene > g_playground; #endif diff --git a/mario/maploader.cpp b/mario/maploader.cpp index 12c684d..ee76879 100644 --- a/mario/maploader.cpp +++ b/mario/maploader.cpp @@ -154,7 +154,7 @@ void loadMap( std::shared_ptr< SDLPP::Scene > &scene, // TODO createModifierBlock with data auto mod = createTerrainBlock( block.getModifierId(), LandType::OVERWORLD, renderer, i, j, - g_translucent_terrain_texture, false, editor ); + g_translucent_mod_texture, false, editor ); mod->getCollisions()[0]->setId( EDITOR_TERRAIN_ID ); dynamic_cast< MarioBlock * >( mod.get() )->setTerrain( false ); scene->addObject( mod ); diff --git a/mario/objectids.hpp b/mario/objectids.hpp index f363813..87de41f 100644 --- a/mario/objectids.hpp +++ b/mario/objectids.hpp @@ -65,6 +65,8 @@ // modifiers #define DESTRUCTIBLE_MODIFIER_ID 0x01 #define BACKGROUND_MODIFIER_ID 0x02 +#define COIN_MODIFIER_ID 0x03 +#define MUSHROOM_MODIFIER_ID 0x04 // character IDs #define MARIO_ID 0x0F diff --git a/mario/sprites.cpp b/mario/sprites.cpp index 345dc31..da50716 100644 --- a/mario/sprites.cpp +++ b/mario/sprites.cpp @@ -79,8 +79,10 @@ const SDL_Rect CANNON_TOWER_SRC = {256, 46, 16, 16}; const SDL_Rect CANNON_PEDESTAL_SRC = {256, 29, 16, 16}; const SDL_Rect CANNON_SRC = {256, 12, 16, 16}; -extern const SDL_Rect DESTRUCTIBLE_SRC = {0, 0, 16, 16}; -extern const SDL_Rect BACKGROUND_SRC = {16, 0, 16, 16}; +extern const SDL_Rect MOD_DESTRUCTIBLE_SRC = {0, 0, 16, 16}; +extern const SDL_Rect MOD_BACKGROUND_SRC = {16, 0, 16, 16}; +extern const SDL_Rect MOD_COIN_SRC = {32, 0, 16, 16}; +extern const SDL_Rect MOD_MUSHROOM_SRC = {48, 0, 16, 16}; const SDLPP::Vec2D OVERWORLD_SHIFT = {0, 0}; const SDLPP::Vec2D UNDERWORLD_SHIFT = {274, 0}; diff --git a/mario/sprites.hpp b/mario/sprites.hpp index 6a1a558..eb498fb 100644 --- a/mario/sprites.hpp +++ b/mario/sprites.hpp @@ -87,8 +87,10 @@ extern const SDL_Rect CANNON_TOWER_SRC; extern const SDL_Rect CANNON_PEDESTAL_SRC; extern const SDL_Rect CANNON_SRC; //------------------ MODIFIERS ---------------------- -extern const SDL_Rect DESTRUCTIBLE_SRC; -extern const SDL_Rect BACKGROUND_SRC; +extern const SDL_Rect MOD_DESTRUCTIBLE_SRC; +extern const SDL_Rect MOD_BACKGROUND_SRC; +extern const SDL_Rect MOD_COIN_SRC; +extern const SDL_Rect MOD_MUSHROOM_SRC; extern const SDLPP::Vec2D OVERWORLD_SHIFT; extern const SDLPP::Vec2D UNDERWORLD_SHIFT;