Editor: add character support
This commit is contained in:
parent
f3c4380bfb
commit
c7309d56a3
@ -94,6 +94,7 @@ struct GlobalVars {
|
||||
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::Texture > translucent_enemies_texture;
|
||||
std::shared_ptr< SDLPP::RenderObject > mario;
|
||||
SDLPP::Vec2D< int > mario_pos;
|
||||
};
|
||||
@ -133,6 +134,7 @@ void updateTool() {
|
||||
target_src = global_vars.mods[global_vars.tool.index]->getTextureSourceRect();
|
||||
break;
|
||||
case BlockRole::CHARACTER:
|
||||
target_texture = global_vars.translucent_enemies_texture;
|
||||
target_src = global_vars.characters[global_vars.tool.index]->getTextureSourceRect();
|
||||
break;
|
||||
}
|
||||
@ -577,6 +579,10 @@ void placeTool( SDLPP::Scene &scene ) {
|
||||
case BlockRole::TERRAIN:
|
||||
visitor.setVisitorType( VisitorType::Terrain );
|
||||
break;
|
||||
case BlockRole::CHARACTER:
|
||||
case BlockRole::MARIO:
|
||||
visitor.setVisitorType( VisitorType::Character );
|
||||
break;
|
||||
default:
|
||||
visitor.setVisitorType( VisitorType::Modifier );
|
||||
break;
|
||||
@ -589,6 +595,9 @@ void placeTool( SDLPP::Scene &scene ) {
|
||||
case VisitorType::Terrain:
|
||||
obj.unsetTerrain();
|
||||
break;
|
||||
case VisitorType::Character:
|
||||
obj.unsetCharacter();
|
||||
break;
|
||||
case VisitorType::Modifier:
|
||||
obj.unsetModifier();
|
||||
break;
|
||||
@ -609,7 +618,7 @@ void placeTool( SDLPP::Scene &scene ) {
|
||||
global_vars.mouse.edit_box.getY(), false, true );
|
||||
new_obj->getCollisions()[0]->setId( EDITOR_TERRAIN_ID );
|
||||
break;
|
||||
case VisitorType::Modifier:
|
||||
case VisitorType::Character:
|
||||
if ( tool_type == BlockRole::MARIO ) {
|
||||
obj.setCharacter( MARIO_ID, global_vars.current_world_type );
|
||||
new_obj =
|
||||
@ -622,8 +631,16 @@ void placeTool( SDLPP::Scene &scene ) {
|
||||
global_vars.mario_pos = getSelectedObjectIndexes();
|
||||
new_obj->getCollisions()[0]->setId( EDITOR_CHARACTER_ID );
|
||||
z_index = scene.getObjects().size() - 1;
|
||||
// TODO BlockRole::Character
|
||||
} else {
|
||||
obj.setCharacter(global_vars.current_tool->getId(), global_vars.current_world_type);
|
||||
new_obj = createTerrainBlock(obj.getCharacterId(), obj.getCharacterType(), renderer, global_vars.mouse.edit_box.getX(), global_vars.mouse.edit_box.getY(), false, true);
|
||||
new_obj->getCollisions()[0]->setId(EDITOR_CHARACTER_ID);
|
||||
dynamic_cast< MarioBlock * >( new_obj.get() )
|
||||
->setTerrain( false );
|
||||
z_index = scene.getObjects().size() - 1;
|
||||
}
|
||||
break;
|
||||
case VisitorType::Modifier:
|
||||
obj.setModifier( global_vars.current_tool->getId(),
|
||||
global_vars.current_tool->getData() );
|
||||
new_obj = createTerrainBlock(
|
||||
@ -638,7 +655,6 @@ void placeTool( SDLPP::Scene &scene ) {
|
||||
dynamic_cast< MarioBlock * >( new_obj.get() )
|
||||
->setTerrain( false );
|
||||
z_index = scene.getObjects().size() - 1;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
@ -842,6 +858,7 @@ void populateToolGrid(
|
||||
}
|
||||
tool_store.back()->setHidden( true );
|
||||
tool_store.back()->setPermanent();
|
||||
tool_store.back()->pauseAnimation();
|
||||
auto x = tool_index % count_x;
|
||||
auto y = tool_index / count_x;
|
||||
tool_store.back()->setPos( start_x + x * BLOCK_SIZE,
|
||||
@ -961,12 +978,17 @@ int main() {
|
||||
renderer, "sprites/mario.png", MARIO_OVERWORLD_COLORKEY );
|
||||
g_mod_texture =
|
||||
std::make_shared< SDLPP::Texture >( renderer, "sprites/mods.png" );
|
||||
g_enemies_texture = std::make_shared< SDLPP::Texture >(
|
||||
renderer, "sprites/enemies.png", MARIO_OVERWORLD_COLORKEY );
|
||||
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< SDLPP::Texture >( renderer, "sprites/mods.png" );
|
||||
g_translucent_mod_texture->setAlpha( 100 );
|
||||
g_translucent_enemies_texture = std::make_shared< SDLPP::Texture >(
|
||||
renderer, "sprites/enemies.png", MARIO_OVERWORLD_COLORKEY );
|
||||
g_translucent_enemies_texture->setAlpha( 100 );
|
||||
|
||||
auto scene = std::make_shared< SDLPP::Scene >( renderer );
|
||||
auto bg = std::make_shared< SDLPP::RectangleRender >(
|
||||
@ -1070,10 +1092,7 @@ int main() {
|
||||
mouse->addCollision( SDLPP::RectColider( { 0, 0 }, { 1, 1 } ) );
|
||||
scene->addObject( mouse );
|
||||
|
||||
global_vars.translucent_terrain_texture =
|
||||
std::make_shared< SDLPP::Texture >( renderer, "sprites/terrain.png",
|
||||
MARIO_OVERWORLD_COLORKEY );
|
||||
global_vars.translucent_terrain_texture->setAlpha( 100 );
|
||||
global_vars.translucent_terrain_texture = g_translucent_terrain_texture;
|
||||
global_vars.translucent_mario_texture = std::make_shared< SDLPP::Texture >(
|
||||
renderer, "sprites/mario.png", MARIO_OVERWORLD_COLORKEY );
|
||||
global_vars.translucent_mario_texture->setAlpha( 100 );
|
||||
@ -1094,6 +1113,7 @@ int main() {
|
||||
global_vars.coin_tool->addCollision(
|
||||
SDLPP::RectColider( 0.1, 0.1, 0.8, 0.8 ) );
|
||||
global_vars.translucent_mod_texture = g_translucent_mod_texture;
|
||||
global_vars.translucent_enemies_texture = g_translucent_enemies_texture;
|
||||
dynamic_cast< MarioBlock & >( *global_vars.current_tool ).setTool();
|
||||
scene->addObject( global_vars.current_tool );
|
||||
scene->addObject( global_vars.coin_tool );
|
||||
@ -1125,9 +1145,15 @@ int main() {
|
||||
MOD_LEFT_ENABLED_FLAG | MOD_RIGHT_ENABLED_FLAG |
|
||||
CHARACTER_LEFT_ENABLED_FLAG | CHARACTER_RIGHT_ENABLED_FLAG );
|
||||
|
||||
while ( !getFlag( QUIT_FLAG ) ) {
|
||||
SDL_PumpEvents();
|
||||
scene->updateSizeAndPosition();
|
||||
scene->renderScene();
|
||||
renderer->presentRenderer();
|
||||
setFlag(UPDATE_FLAG);
|
||||
|
||||
while ( !getFlag( QUIT_FLAG ) ) {
|
||||
SDL_framerateDelay( &gFPS );
|
||||
SDL_PumpEvents();
|
||||
std::lock_guard< std::mutex > lock( destruction_mutex );
|
||||
scene->renderScene();
|
||||
renderer->presentRenderer();
|
||||
|
@ -107,7 +107,7 @@ void ToolVisitor::visit( const SDLPP::RenderObject &obj ) {
|
||||
remove_block = true;
|
||||
if ( obj.getId() == source_id &&
|
||||
m_obj.getType() == source_type &&
|
||||
getVisitorType() == VisitorType::Modifier ) {
|
||||
getVisitorType() == VisitorType::Character ) {
|
||||
add_block = false;
|
||||
}
|
||||
}
|
||||
|
@ -10,6 +10,7 @@ struct VisitorType {
|
||||
enum Value {
|
||||
Terrain = 0xE001,
|
||||
Modifier = 0xE002,
|
||||
Character = 0xE003,
|
||||
};
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user