Mario editor: more terrain, can place Mario
This commit is contained in:
+57
-13
@@ -41,6 +41,10 @@ int current_tool_index = 0;
|
||||
int max_tool_index = 0;
|
||||
|
||||
std::shared_ptr<SDLPP::Texture> g_placeholder_texture = nullptr;
|
||||
std::shared_ptr<SDLPP::Texture> g_placeholder_mario = nullptr;
|
||||
|
||||
std::shared_ptr<SDLPP::RenderObject> g_mario = nullptr;
|
||||
SDLPP::Vec2D<int> g_mario_pos = {0,0};
|
||||
|
||||
void handleKeyDown( SDL_Keycode key, SDLPP::Scene &scene ) {
|
||||
switch ( key ) {
|
||||
@@ -65,11 +69,21 @@ void handleKeyDown( SDL_Keycode key, SDLPP::Scene &scene ) {
|
||||
}
|
||||
|
||||
void updateTool() {
|
||||
current_tool->setTexture(g_placeholder_texture, getSourceRectByID(possibleBlocks[current_block], OVERWORLD));
|
||||
if(possibleBlocks[current_block] == MARIO_ID) {
|
||||
current_tool->setTexture(g_placeholder_mario, getSourceRectByID(possibleBlocks[current_block], OVERWORLD));
|
||||
} else {
|
||||
current_tool->setTexture(g_placeholder_texture, getSourceRectByID(possibleBlocks[current_block], OVERWORLD));
|
||||
}
|
||||
current_tool->setId(possibleBlocks[current_block]);
|
||||
current_tool->getCollisions()[0]->setId(possibleBlocks[current_block]);
|
||||
}
|
||||
|
||||
void removeMario() {
|
||||
auto prev = objects[g_mario_pos.getX()][g_mario_pos.getY()];
|
||||
objects[g_mario_pos.getX()][g_mario_pos.getY()] = {std::get<0>(prev), std::get<1>(prev), 0, 0, 0, 0};
|
||||
g_mario->destroy();
|
||||
}
|
||||
|
||||
void updateToolSelection(int prev_index) {
|
||||
auto prev = prev_index * 8;
|
||||
auto cur = current_tool_index * 8;
|
||||
@@ -155,20 +169,42 @@ void pollEvents( SDLPP::Scene &scene ) {
|
||||
std::lock_guard<std::mutex> lock(destruction_mutex);
|
||||
|
||||
ToolVisitor visitor;
|
||||
visitor.setVisitorType(TOOL_VISITOR_TYPE);
|
||||
if(current_tool->getId() < 0x7000) {
|
||||
visitor.setVisitorType(MODIFIER_VISITOR_TYPE);
|
||||
} else {
|
||||
visitor.setVisitorType(TOOL_VISITOR_TYPE);
|
||||
}
|
||||
// TODO
|
||||
scene.visitCollisions(*current_tool, visitor);
|
||||
if(visitor.removeBlock() && !visitor.addBlock()) {
|
||||
// TODO check if modifier
|
||||
auto prev = objects[current_start_index + current_box.getX()][current_box.getY()];
|
||||
objects[current_start_index + current_box.getX()][current_box.getY()] = {OVERWORLD, 0, std::get<2>(prev), std::get<3>(prev), 0, 0};
|
||||
if(visitor.getVisitorType() == TOOL_VISITOR_TYPE) {
|
||||
objects[current_start_index + current_box.getX()][current_box.getY()] = {OVERWORLD, 0, std::get<2>(prev), std::get<3>(prev), std::get<4>(prev), std::get<5>(prev)};
|
||||
} else {
|
||||
objects[current_start_index + current_box.getX()][current_box.getY()] = {std::get<0>(prev), std::get<1>(prev), 0, 0, 0, 0};
|
||||
}
|
||||
} else if(visitor.addBlock()) {
|
||||
// TODO check if modifier
|
||||
auto prev = objects[current_start_index + current_box.getX()][current_box.getY()];
|
||||
objects[current_start_index + current_box.getX()][current_box.getY()] = {OVERWORLD, current_tool->getId(), std::get<2>(prev), std::get<3>(prev), 0, 0};
|
||||
auto obj = createTerrainBlock(current_tool->getId(), OVERWORLD, renderer, 1 + current_box.getX(), current_box.getY(), true);
|
||||
obj->getCollisions()[0]->setId(EDITOR_TERRAIN_ID);
|
||||
int z_index = 1;
|
||||
std::shared_ptr<SDLPP::RenderObject> obj = nullptr;
|
||||
if(visitor.getVisitorType() == TOOL_VISITOR_TYPE) {
|
||||
objects[current_start_index + current_box.getX()][current_box.getY()] = {OVERWORLD, current_tool->getId(), std::get<2>(prev), std::get<3>(prev), std::get<4>(prev), std::get<5>(prev)};
|
||||
obj = createTerrainBlock(current_tool->getId(), OVERWORLD, renderer, 1 + current_box.getX(), current_box.getY(), true);
|
||||
obj->getCollisions()[0]->setId(EDITOR_TERRAIN_ID);
|
||||
} else {
|
||||
// TODO check if modifier or character
|
||||
objects[current_start_index + current_box.getX()][current_box.getY()] = {std::get<0>(prev), std::get<1>(prev), OVERWORLD, MARIO_ID, 0, 0};
|
||||
obj = createMario(OVERWORLD, renderer, 1 + current_box.getX(), current_box.getY());
|
||||
if(g_mario) {
|
||||
removeMario();
|
||||
}
|
||||
g_mario = obj;
|
||||
g_mario_pos = {current_start_index + current_box.getX(), current_box.getY()};
|
||||
obj->getCollisions()[0]->setId(EDITOR_CHARACTER_ID);
|
||||
z_index = scene.getObjects().size() - 1;
|
||||
}
|
||||
scene.addObject(obj);
|
||||
scene.setZIndex(obj, 1);
|
||||
scene.setZIndex(obj, z_index);
|
||||
}
|
||||
}
|
||||
if(current_tool_box.getX() != -1) {
|
||||
@@ -307,13 +343,18 @@ int main() {
|
||||
}
|
||||
int tool_index = 0;
|
||||
for(auto &block : possibleBlocks) {
|
||||
tools.push_back(createTerrainBlock(block, OVERWORLD, renderer, false));
|
||||
if(block == MARIO_ID ) {
|
||||
tools.push_back(createMario(OVERWORLD, renderer, 0, 0));
|
||||
} else {
|
||||
tools.push_back(createTerrainBlock(block, OVERWORLD, renderer, false));
|
||||
}
|
||||
tools.back()->setHidden(true);
|
||||
tools.back()->setPermanent();
|
||||
auto x = tool_index % 4;
|
||||
auto y = tool_index / 4;
|
||||
// TODO add 14 and 1 as constants somewhere
|
||||
// TODO investigate
|
||||
tools.back()->setPos(13*BLOCK_SIZE + x*BLOCK_SIZE, BLOCK_SIZE + y*BLOCK_SIZE);
|
||||
// TODO investigate when not permanent requires `-1` on x position
|
||||
tools.back()->setPos(14*BLOCK_SIZE + x*BLOCK_SIZE, BLOCK_SIZE + y*BLOCK_SIZE);
|
||||
// std::cout << "TOOL POS: " << tools.back()->getPos().getX() << ", " << tools.back()->getPos().getY() << std::endl;
|
||||
scene->addObject(tools.back());
|
||||
tool_index = (tool_index + 1) % 8;
|
||||
@@ -363,9 +404,12 @@ int main() {
|
||||
|
||||
g_placeholder_texture = std::make_shared< SDLPP::Texture >(
|
||||
renderer, "sprites/terrain.png", MARIO_OVERWORLD_COLORKEY );
|
||||
g_placeholder_texture->setAlpha(100);
|
||||
g_placeholder_mario = std::make_shared< SDLPP::Texture >(
|
||||
renderer, "sprites/mario.png", MARIO_OVERWORLD_COLORKEY );
|
||||
g_placeholder_mario->setAlpha(100);
|
||||
current_tool = createTerrainBlock(possibleBlocks[current_block], OVERWORLD, renderer, g_placeholder_texture, false);
|
||||
current_tool->addCollision(SDLPP::RectColider(0.1, 0.1, 0.8, 0.8));
|
||||
current_tool->setTextureAlpha(100);
|
||||
dynamic_cast<MarioBlock&>(*current_tool).setTool();
|
||||
scene->addObject(current_tool);
|
||||
scene->moveZTop(current_tool);
|
||||
|
||||
Reference in New Issue
Block a user