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