Mario Editor: smaller block size

This commit is contained in:
zvon 2021-06-01 10:18:33 +02:00
parent 243c1d9d04
commit 0475f4967b
3 changed files with 22 additions and 23 deletions

View File

@ -3,7 +3,7 @@
#include "blocks.hpp"
#include "sprites.hpp"
EditBox::EditBox(int x, int y, int map_width, int map_height, std::shared_ptr<SDLPP::Renderer> renderer) : SDLPP::RectangleRender(BLOCK_SIZE + x*BLOCK_SIZE, (map_width - map_height + 2)*BLOCK_SIZE + y*BLOCK_SIZE, BLOCK_SIZE, BLOCK_SIZE, renderer) {
EditBox::EditBox(int x, int y, float start_x, float start_y, int map_width, int map_height, std::shared_ptr<SDLPP::Renderer> renderer) : SDLPP::RectangleRender(start_x + x*BLOCK_SIZE, start_y + y*BLOCK_SIZE, BLOCK_SIZE, BLOCK_SIZE, renderer) {
_x = x;
_y = y;
setId(EDITOR_EDIT_SQUARE);

View File

@ -5,7 +5,7 @@
class EditBox : public SDLPP::RectangleRender {
public:
EditBox(int x, int y, int map_width, int map_height, std::shared_ptr<SDLPP::Renderer> renderer);
EditBox(int x, int y, float start_x, float start_y, int map_width, int map_height, std::shared_ptr<SDLPP::Renderer> renderer);
virtual SDLPP::Vec2D<int> getIndexes() const;
virtual void visit( SDLPP::Visitor &visitor ) override;
private:

View File

@ -21,7 +21,7 @@
#include "editor_visitor.hpp"
#include "tool_box.hpp"
#define MAP_WIDTH 18
#define MAP_WIDTH 24
#define MAP_HEIGHT 16
#define QUIT_FLAG 0x00000001
@ -36,7 +36,7 @@
#define CHARACTER_RIGHT_ENABLED_FLAG 0x00000200
#define TOOLS_WIDTH 4
#define CHARACTER_WIDTH 2
#define CHARACTER_WIDTH 3
#define MOD_WIDTH 2
#define OVERWORLD_WIDTH 2
@ -475,8 +475,7 @@ void getMousePositionFlags( SDLPP::Scene &scene ) {
if ( visitor.foundEditBox() ) {
const auto &box = global_vars.mouse.edit_box;
global_vars.current_tool->setPos( box.getX() * BLOCK_SIZE,
( MAP_WIDTH - MAP_HEIGHT + 2 ) *
BLOCK_SIZE +
1 - MAP_HEIGHT * BLOCK_SIZE +
box.getY() * BLOCK_SIZE );
}
}
@ -920,7 +919,7 @@ int main() {
SDLPP::init();
SDLPP::Window w( "Mario editor!" );
w.setResizable( true );
BLOCK_SIZE = 1.0 / ( MAP_WIDTH + 2 );
BLOCK_SIZE = 1.0 / 26;
auto renderer = std::make_shared< SDLPP::Renderer >( w );
renderer->setBlendMode( SDL_BLENDMODE_BLEND );
@ -955,7 +954,7 @@ int main() {
// map
auto arrows = createArrowControls(
0, ( MAP_WIDTH + 1 ) * BLOCK_SIZE,
( MAP_WIDTH + 2 - MAP_HEIGHT ) * BLOCK_SIZE, MAP_HEIGHT * BLOCK_SIZE,
1 - MAP_HEIGHT * BLOCK_SIZE, MAP_HEIGHT * BLOCK_SIZE,
EDITOR_LEFT_MAP_ID, EDITOR_RIGHT_MAP_ID, scene, font_config );
auto left_map_arrow = arrows.first;
auto right_map_arrow = arrows.second;
@ -965,53 +964,53 @@ int main() {
for ( int i = 0; i < MAP_WIDTH; i++ ) {
for ( int j = 0; j < MAP_HEIGHT; j++ ) {
scene->addObject( std::make_shared< EditBox >(
i, j, MAP_WIDTH, MAP_HEIGHT, renderer ) );
i, j, BLOCK_SIZE, 1 - MAP_HEIGHT * BLOCK_SIZE, MAP_WIDTH, MAP_HEIGHT, renderer ) );
}
}
// tools
populateToolGrid( TOOLS_WIDTH, 2, ( MAP_WIDTH - TOOLS_WIDTH ) * BLOCK_SIZE,
BLOCK_SIZE, ToolType::BLOCK, possibleBlocks,
1 - (MAP_HEIGHT + 3) * BLOCK_SIZE, ToolType::BLOCK, possibleBlocks,
global_vars.tools, global_vars.tool_boxes, scene,
"TERRAIN", font_config );
arrows = createArrowControls( ( MAP_WIDTH - TOOLS_WIDTH - 1 ) * BLOCK_SIZE,
MAP_WIDTH * BLOCK_SIZE, BLOCK_SIZE,
MAP_WIDTH * BLOCK_SIZE, 1 - (MAP_HEIGHT + 3) * BLOCK_SIZE,
2 * BLOCK_SIZE, EDITOR_LEFT_TOOL_ID,
EDITOR_RIGHT_TOOL_ID, scene, font_config );
auto left_tool_arrow = arrows.first;
auto right_tool_arrow = arrows.second;
createGrid( ( MAP_WIDTH - TOOLS_WIDTH ) * BLOCK_SIZE, BLOCK_SIZE,
createGrid( ( MAP_WIDTH - TOOLS_WIDTH ) * BLOCK_SIZE, 1 - (MAP_HEIGHT + 3) * BLOCK_SIZE,
TOOLS_WIDTH, 2, scene );
// mods
populateToolGrid( MOD_WIDTH, 2, 4 * BLOCK_SIZE, BLOCK_SIZE, ToolType::MOD,
populateToolGrid( MOD_WIDTH, 2, 5 * BLOCK_SIZE, 1 - (MAP_HEIGHT + 3) * BLOCK_SIZE, ToolType::MOD,
possibleMods, global_vars.mods, global_vars.mod_boxes,
scene, "MODS", font_config );
arrows =
createArrowControls( 3 * BLOCK_SIZE, ( MOD_WIDTH + 4 ) * BLOCK_SIZE,
BLOCK_SIZE, 2 * BLOCK_SIZE, EDITOR_LEFT_MOD_ID,
createArrowControls( 4 * BLOCK_SIZE, ( MOD_WIDTH + 5 ) * BLOCK_SIZE,
1 - (MAP_HEIGHT + 3) * BLOCK_SIZE, 2 * BLOCK_SIZE, EDITOR_LEFT_MOD_ID,
EDITOR_RIGHT_MOD_ID, scene, font_config );
auto left_mod_arrow = arrows.first;
auto right_mod_arrow = arrows.second;
createGrid( 4 * BLOCK_SIZE, BLOCK_SIZE, MOD_WIDTH, 2, scene );
createGrid( 5 * BLOCK_SIZE, 1 - (MAP_HEIGHT + 3) * BLOCK_SIZE, MOD_WIDTH, 2, scene );
// characters
populateToolGrid( CHARACTER_WIDTH, 2, ( MOD_WIDTH + 7 ) * BLOCK_SIZE,
BLOCK_SIZE, ToolType::CHARACTER, possibleCharacters,
populateToolGrid( CHARACTER_WIDTH, 2, ( MOD_WIDTH + 8 ) * BLOCK_SIZE,
1 - (MAP_HEIGHT + 3) * BLOCK_SIZE, ToolType::CHARACTER, possibleCharacters,
global_vars.characters, global_vars.character_boxes,
scene, "CHARACTERS", font_config );
arrows = createArrowControls(
( MOD_WIDTH + 6 ) * BLOCK_SIZE,
( MOD_WIDTH + 7 + CHARACTER_WIDTH ) * BLOCK_SIZE, BLOCK_SIZE,
( MOD_WIDTH + 7 ) * BLOCK_SIZE,
( MOD_WIDTH + 8 + CHARACTER_WIDTH ) * BLOCK_SIZE, 1 - (MAP_HEIGHT + 3) * BLOCK_SIZE,
2 * BLOCK_SIZE, EDITOR_LEFT_CHARACTER_ID, EDITOR_RIGHT_CHARACTER_ID,
scene, font_config );
auto left_char_arrow = arrows.first;
auto right_char_arrow = arrows.second;
createGrid( ( MOD_WIDTH + 7 ) * BLOCK_SIZE, BLOCK_SIZE, CHARACTER_WIDTH, 2,
createGrid( ( MOD_WIDTH + 8 ) * BLOCK_SIZE, 1 - (MAP_HEIGHT + 3) * BLOCK_SIZE, CHARACTER_WIDTH, 2,
scene );
// world type
populateWorldType( OVERWORLD_WIDTH, 2, 0, BLOCK_SIZE, scene, "WORLD",
populateWorldType( OVERWORLD_WIDTH, 2, BLOCK_SIZE, 1 - (MAP_HEIGHT + 3) * BLOCK_SIZE, scene, "WORLD",
font_config );
createGrid( 0, BLOCK_SIZE, OVERWORLD_WIDTH, 2, scene );
createGrid( BLOCK_SIZE, 1 - (MAP_HEIGHT + 3) * BLOCK_SIZE, OVERWORLD_WIDTH, 2, scene );
global_vars.map.max_page = global_vars.objects.size() - MAP_WIDTH;