Mario: set mario pointer when loading map for editor
This commit is contained in:
parent
19c29b261c
commit
d2bc497070
@ -291,9 +291,8 @@ void placeTool( SDLPP::Scene &scene ) {
|
|||||||
new_obj->getCollisions()[0]->setId( EDITOR_TERRAIN_ID );
|
new_obj->getCollisions()[0]->setId( EDITOR_TERRAIN_ID );
|
||||||
break;
|
break;
|
||||||
case VisitorType::Modifier:
|
case VisitorType::Modifier:
|
||||||
if(tool_type == BlockRole::CHARACTER) {
|
if(tool_type == BlockRole::MARIO) {
|
||||||
std::get< MapObject::CHARACTER_TYPE >( obj ) = LandType::OVERWORLD;
|
std::get< MapObject::CHARACTER_TYPE >( obj ) = LandType::OVERWORLD;
|
||||||
// TODO character ID
|
|
||||||
std::get< MapObject::CHARACTER_ID >( obj ) = MARIO_ID;
|
std::get< MapObject::CHARACTER_ID >( obj ) = MARIO_ID;
|
||||||
std::get< MapObject::MODIFIER_TYPE >( obj ) = 0;
|
std::get< MapObject::MODIFIER_TYPE >( obj ) = 0;
|
||||||
std::get< MapObject::MODIFIER_DATA >( obj ) = 0;
|
std::get< MapObject::MODIFIER_DATA >( obj ) = 0;
|
||||||
@ -306,6 +305,7 @@ void placeTool( SDLPP::Scene &scene ) {
|
|||||||
global_vars.mario_pos = getSelectedObjectPosition();
|
global_vars.mario_pos = getSelectedObjectPosition();
|
||||||
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 {
|
||||||
// TODO data
|
// TODO data
|
||||||
std::cout << "Want to set: " << (int)std::get< MapObject::MODIFIER_TYPE >( obj ) << std::endl;
|
std::cout << "Want to set: " << (int)std::get< MapObject::MODIFIER_TYPE >( obj ) << std::endl;
|
||||||
@ -417,7 +417,7 @@ int main() {
|
|||||||
bg->setId( 1 );
|
bg->setId( 1 );
|
||||||
scene->addObject( bg );
|
scene->addObject( bg );
|
||||||
|
|
||||||
loadMap( scene, "test_binary.bin", renderer, global_vars.objects );
|
loadMap( scene, global_vars.mario, "test_binary.bin", renderer, global_vars.objects );
|
||||||
|
|
||||||
// grid
|
// grid
|
||||||
for ( int i = 1; i < ( MAP_WIDTH + 2 ); i++ ) {
|
for ( int i = 1; i < ( MAP_WIDTH + 2 ); i++ ) {
|
||||||
|
@ -46,8 +46,9 @@ void loadMap( std::shared_ptr< SDLPP::Scene > &scene,
|
|||||||
if ( id == FLOOR_ID || id == BRICK_ID || id == BRICK_TOP_ID ) {
|
if ( id == FLOOR_ID || id == BRICK_ID || id == BRICK_TOP_ID ) {
|
||||||
collision = true;
|
collision = true;
|
||||||
}
|
}
|
||||||
// TODO definitely make this somehow more streamlined, probably flags
|
// TODO definitely make this somehow more streamlined, probably
|
||||||
if(modifier_type == DESTRUCTIBLE_ID) {
|
// flags
|
||||||
|
if ( modifier_type == DESTRUCTIBLE_ID ) {
|
||||||
destructible = true;
|
destructible = true;
|
||||||
}
|
}
|
||||||
// TODO add modifiers to createTerrainBlock
|
// TODO add modifiers to createTerrainBlock
|
||||||
@ -68,7 +69,9 @@ void loadMap( std::shared_ptr< SDLPP::Scene > &scene,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// editor loader
|
// editor loader
|
||||||
void loadMap( std::shared_ptr< SDLPP::Scene > &scene, const std::string &file,
|
void loadMap( std::shared_ptr< SDLPP::Scene > &scene,
|
||||||
|
std::shared_ptr< SDLPP::RenderObject > &mario,
|
||||||
|
const std::string &file,
|
||||||
std::shared_ptr< SDLPP::Renderer > &renderer,
|
std::shared_ptr< SDLPP::Renderer > &renderer,
|
||||||
std::vector< mapColumnType > &objects ) {
|
std::vector< mapColumnType > &objects ) {
|
||||||
std::ifstream map_file;
|
std::ifstream map_file;
|
||||||
@ -115,13 +118,16 @@ void loadMap( std::shared_ptr< SDLPP::Scene > &scene, const std::string &file,
|
|||||||
scene->addObject( createMario(
|
scene->addObject( createMario(
|
||||||
static_cast< LandType::Value >( character_type ),
|
static_cast< LandType::Value >( character_type ),
|
||||||
renderer, i, j ) );
|
renderer, i, j ) );
|
||||||
|
mario = scene->getObject(scene->getObjects().size() - 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ( modifier_type ) {
|
if ( modifier_type ) {
|
||||||
auto mod = createTerrainBlock( modifier_type, LandType::OVERWORLD, renderer, i, j, g_translucent_terrain_texture, true );
|
auto mod = createTerrainBlock(
|
||||||
|
modifier_type, LandType::OVERWORLD, renderer, i, j,
|
||||||
|
g_translucent_terrain_texture, true );
|
||||||
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 );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -142,20 +148,25 @@ void saveMap( const std::string &file, std::vector< mapColumnType > &objects ) {
|
|||||||
auto &obj = col[i];
|
auto &obj = col[i];
|
||||||
uint16_t wide_type = std::get< MapObject::TERRAIN_TYPE >( obj );
|
uint16_t wide_type = std::get< MapObject::TERRAIN_TYPE >( obj );
|
||||||
wide_type = wide_type << 12;
|
wide_type = wide_type << 12;
|
||||||
uint16_t write_num = ( 0x0FFF & std::get< MapObject::TERRAIN_ID >( obj ) ) | wide_type;
|
uint16_t write_num =
|
||||||
|
( 0x0FFF & std::get< MapObject::TERRAIN_ID >( obj ) ) |
|
||||||
|
wide_type;
|
||||||
// character type can be 0 (overworld), modifier data can be 0
|
// character type can be 0 (overworld), modifier data can be 0
|
||||||
if ( std::get< MapObject::CHARACTER_ID >( obj ) || std::get< MapObject::MODIFIER_TYPE >( obj ) ) {
|
if ( std::get< MapObject::CHARACTER_ID >( obj ) ||
|
||||||
|
std::get< MapObject::MODIFIER_TYPE >( obj ) ) {
|
||||||
write_num |= 0x8000;
|
write_num |= 0x8000;
|
||||||
}
|
}
|
||||||
output_file.write( ( char * )&write_num,
|
output_file.write( ( char * )&write_num,
|
||||||
sizeof( uint16_t ) / sizeof( char ) );
|
sizeof( uint16_t ) / sizeof( char ) );
|
||||||
uint8_t additional_data = 0;
|
uint8_t additional_data = 0;
|
||||||
if ( std::get< MapObject::CHARACTER_ID >( obj ) ) {
|
if ( std::get< MapObject::CHARACTER_ID >( obj ) ) {
|
||||||
additional_data |= std::get< MapObject::CHARACTER_TYPE >( obj ) << 4;
|
additional_data |= std::get< MapObject::CHARACTER_TYPE >( obj )
|
||||||
|
<< 4;
|
||||||
additional_data |= std::get< MapObject::CHARACTER_ID >( obj );
|
additional_data |= std::get< MapObject::CHARACTER_ID >( obj );
|
||||||
} else if ( std::get< MapObject::MODIFIER_TYPE >( obj ) ) {
|
} else if ( std::get< MapObject::MODIFIER_TYPE >( obj ) ) {
|
||||||
std::cout << "SAVING MODIFIERS!" << std::endl;
|
std::cout << "SAVING MODIFIERS!" << std::endl;
|
||||||
additional_data |= std::get< MapObject::MODIFIER_TYPE >( obj ) << 4;
|
additional_data |= std::get< MapObject::MODIFIER_TYPE >( obj )
|
||||||
|
<< 4;
|
||||||
additional_data |= 0x80;
|
additional_data |= 0x80;
|
||||||
additional_data |= std::get< MapObject::MODIFIER_DATA >( obj );
|
additional_data |= std::get< MapObject::MODIFIER_DATA >( obj );
|
||||||
}
|
}
|
||||||
|
@ -23,7 +23,9 @@ void loadMap( std::shared_ptr< SDLPP::Scene > &scene,
|
|||||||
std::shared_ptr< SDLPP::RectangleRender > mario,
|
std::shared_ptr< SDLPP::RectangleRender > mario,
|
||||||
const std::string &file,
|
const std::string &file,
|
||||||
std::shared_ptr< SDLPP::Renderer > &renderer );
|
std::shared_ptr< SDLPP::Renderer > &renderer );
|
||||||
void loadMap( std::shared_ptr< SDLPP::Scene > &scene, const std::string &file,
|
void loadMap( std::shared_ptr< SDLPP::Scene > &scene,
|
||||||
|
std::shared_ptr< SDLPP::RenderObject > &mario,
|
||||||
|
const std::string &file,
|
||||||
std::shared_ptr< SDLPP::Renderer > &renderer,
|
std::shared_ptr< SDLPP::Renderer > &renderer,
|
||||||
std::vector< mapColumnType > &objects );
|
std::vector< mapColumnType > &objects );
|
||||||
void saveMap( const std::string &file, std::vector< mapColumnType > &objects );
|
void saveMap( const std::string &file, std::vector< mapColumnType > &objects );
|
||||||
|
Loading…
Reference in New Issue
Block a user