Mod texture

This commit is contained in:
zvon 2021-06-24 20:53:58 +02:00
parent b423ac7b8c
commit 2617156833
8 changed files with 40 additions and 13 deletions

View File

@ -156,6 +156,8 @@ const std::vector< uint64_t > possibleBlocks = {
const std::vector< uint64_t > possibleMods = { const std::vector< uint64_t > possibleMods = {
DESTRUCTIBLE_MODIFIER_ID, DESTRUCTIBLE_MODIFIER_ID,
BACKGROUND_MODIFIER_ID, BACKGROUND_MODIFIER_ID,
COIN_MODIFIER_ID,
MUSHROOM_MODIFIER_ID,
}; };
const std::vector< uint64_t > possibleCharacters = { 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_PEDESTAL_ID, &CANNON_PEDESTAL_SRC },
{ CANNON_ID, &CANNON_SRC }, { CANNON_ID, &CANNON_SRC },
{ MARIO_ID, &MARIO_STANDING_SRC }, { MARIO_ID, &MARIO_STANDING_SRC },
{ DESTRUCTIBLE_MODIFIER_ID, &DESTRUCTIBLE_SRC }, { DESTRUCTIBLE_MODIFIER_ID, &MOD_DESTRUCTIBLE_SRC },
{ BACKGROUND_MODIFIER_ID, &BACKGROUND_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 = { const std::unordered_map< uint64_t, uint64_t > block_flags = {

View File

@ -89,6 +89,7 @@ struct GlobalVars {
std::shared_ptr< SDLPP::RenderObject > current_tool; std::shared_ptr< SDLPP::RenderObject > current_tool;
std::shared_ptr< SDLPP::Texture > translucent_terrain_texture; std::shared_ptr< SDLPP::Texture > translucent_terrain_texture;
std::shared_ptr< SDLPP::Texture > translucent_mario_texture; std::shared_ptr< SDLPP::Texture > translucent_mario_texture;
std::shared_ptr< SDLPP::Texture > translucent_mod_texture;
std::shared_ptr< SDLPP::RenderObject > mario; std::shared_ptr< SDLPP::RenderObject > mario;
SDLPP::Vec2D< int > mario_pos; SDLPP::Vec2D< int > mario_pos;
}; };
@ -121,7 +122,7 @@ void updateTool() {
target_texture = global_vars.translucent_mario_texture; target_texture = global_vars.translucent_mario_texture;
break; break;
case BlockRole::MODIFIER: case BlockRole::MODIFIER:
target_texture = global_vars.translucent_terrain_texture; target_texture = global_vars.translucent_mod_texture;
break; break;
case BlockRole::CHARACTER: case BlockRole::CHARACTER:
break; break;
@ -614,7 +615,7 @@ void placeTool( SDLPP::Scene &scene ) {
LandType::OVERWORLD, renderer, LandType::OVERWORLD, renderer,
global_vars.mouse.edit_box.getX(), global_vars.mouse.edit_box.getX(),
global_vars.mouse.edit_box.getY(), 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 ); new_obj->getCollisions()[0]->setId( EDITOR_TERRAIN_ID );
// TODO createModifierBlock // TODO createModifierBlock
dynamic_cast< MarioBlock * >( new_obj.get() ) dynamic_cast< MarioBlock * >( new_obj.get() )
@ -796,16 +797,22 @@ void populateToolGrid(
for ( auto &block : blocks ) { for ( auto &block : blocks ) {
switch ( type ) { switch ( type ) {
case ToolType::CHARACTER: case ToolType::CHARACTER:
if ( block == MARIO_ID ) if ( block == MARIO_ID ) {
tool_store.push_back( createMario( tool_store.push_back( createMario(
global_vars.current_world_type, renderer, 0, 0 ) ); global_vars.current_world_type, renderer, 0, 0 ) );
else break;
// fall through }
case ToolType::BLOCK: // fall through
case ToolType::MOD: 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( tool_store.push_back(
createTerrainBlock( block, global_vars.current_world_type, createTerrainBlock( block, global_vars.current_world_type,
renderer, false, true ) ); renderer, false, true ) );
break;
default: default:
break; break;
} }
@ -922,9 +929,14 @@ int main() {
renderer, "sprites/terrain.png", MARIO_OVERWORLD_COLORKEY ); renderer, "sprites/terrain.png", MARIO_OVERWORLD_COLORKEY );
g_mario_texture = std::make_shared< SDLPP::Texture >( g_mario_texture = std::make_shared< SDLPP::Texture >(
renderer, "sprites/mario.png", MARIO_OVERWORLD_COLORKEY ); renderer, "sprites/mario.png", MARIO_OVERWORLD_COLORKEY );
g_mod_texture = std::make_shared<SDLPP::Texture>(
renderer, "sprites/mods.png");
g_translucent_terrain_texture = std::make_shared< SDLPP::Texture >( g_translucent_terrain_texture = std::make_shared< SDLPP::Texture >(
renderer, "sprites/terrain.png", MARIO_OVERWORLD_COLORKEY ); renderer, "sprites/terrain.png", MARIO_OVERWORLD_COLORKEY );
g_translucent_terrain_texture->setAlpha( 100 ); g_translucent_terrain_texture->setAlpha( 100 );
g_translucent_mod_texture = std::make_shared<SDLPP::Texture>(
renderer, "sprites/mods.png");
g_translucent_mod_texture->setAlpha( 100 );
auto scene = std::make_shared< SDLPP::Scene >( renderer ); auto scene = std::make_shared< SDLPP::Scene >( renderer );
auto bg = std::make_shared< SDLPP::RectangleRender >( auto bg = std::make_shared< SDLPP::RectangleRender >(
@ -1045,6 +1057,7 @@ int main() {
global_vars.current_tool->removeCollisions(); global_vars.current_tool->removeCollisions();
global_vars.current_tool->addCollision( global_vars.current_tool->addCollision(
SDLPP::RectColider( 0.1, 0.1, 0.8, 0.8 ) ); 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(); dynamic_cast< MarioBlock & >( *global_vars.current_tool ).setTool();
scene->addObject( global_vars.current_tool ); scene->addObject( global_vars.current_tool );
scene->moveZTop( global_vars.current_tool ); scene->moveZTop( global_vars.current_tool );

View File

@ -3,5 +3,7 @@
std::shared_ptr< SDLPP::Texture > g_terrain_texture{}; std::shared_ptr< SDLPP::Texture > g_terrain_texture{};
std::shared_ptr< SDLPP::Texture > g_mario_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_terrain_texture{};
std::shared_ptr< SDLPP::Texture > g_translucent_mod_texture{};
std::shared_ptr< SDLPP::Scene > g_playground{}; std::shared_ptr< SDLPP::Scene > g_playground{};

View File

@ -5,7 +5,9 @@
extern std::shared_ptr< SDLPP::Texture > g_terrain_texture; 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_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_terrain_texture;
extern std::shared_ptr< SDLPP::Texture > g_translucent_mod_texture;
extern std::shared_ptr< SDLPP::Scene > g_playground; extern std::shared_ptr< SDLPP::Scene > g_playground;
#endif #endif

View File

@ -154,7 +154,7 @@ void loadMap( std::shared_ptr< SDLPP::Scene > &scene,
// TODO createModifierBlock with data // TODO createModifierBlock with data
auto mod = createTerrainBlock( auto mod = createTerrainBlock(
block.getModifierId(), LandType::OVERWORLD, renderer, i, j, 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 ); mod->getCollisions()[0]->setId( EDITOR_TERRAIN_ID );
dynamic_cast< MarioBlock * >( mod.get() )->setTerrain( false ); dynamic_cast< MarioBlock * >( mod.get() )->setTerrain( false );
scene->addObject( mod ); scene->addObject( mod );

View File

@ -65,6 +65,8 @@
// modifiers // modifiers
#define DESTRUCTIBLE_MODIFIER_ID 0x01 #define DESTRUCTIBLE_MODIFIER_ID 0x01
#define BACKGROUND_MODIFIER_ID 0x02 #define BACKGROUND_MODIFIER_ID 0x02
#define COIN_MODIFIER_ID 0x03
#define MUSHROOM_MODIFIER_ID 0x04
// character IDs // character IDs
#define MARIO_ID 0x0F #define MARIO_ID 0x0F

View File

@ -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_PEDESTAL_SRC = {256, 29, 16, 16};
const SDL_Rect CANNON_SRC = {256, 12, 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 MOD_DESTRUCTIBLE_SRC = {0, 0, 16, 16};
extern const SDL_Rect BACKGROUND_SRC = {16, 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<uint64_t> OVERWORLD_SHIFT = {0, 0}; const SDLPP::Vec2D<uint64_t> OVERWORLD_SHIFT = {0, 0};
const SDLPP::Vec2D<uint64_t> UNDERWORLD_SHIFT = {274, 0}; const SDLPP::Vec2D<uint64_t> UNDERWORLD_SHIFT = {274, 0};

View File

@ -87,8 +87,10 @@ extern const SDL_Rect CANNON_TOWER_SRC;
extern const SDL_Rect CANNON_PEDESTAL_SRC; extern const SDL_Rect CANNON_PEDESTAL_SRC;
extern const SDL_Rect CANNON_SRC; extern const SDL_Rect CANNON_SRC;
//------------------ MODIFIERS ---------------------- //------------------ MODIFIERS ----------------------
extern const SDL_Rect DESTRUCTIBLE_SRC; extern const SDL_Rect MOD_DESTRUCTIBLE_SRC;
extern const SDL_Rect BACKGROUND_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<uint64_t> OVERWORLD_SHIFT; extern const SDLPP::Vec2D<uint64_t> OVERWORLD_SHIFT;
extern const SDLPP::Vec2D<uint64_t> UNDERWORLD_SHIFT; extern const SDLPP::Vec2D<uint64_t> UNDERWORLD_SHIFT;