diff --git a/extra/editor/texture_selector.py b/extra/editor/texture_selector.py index 0366674..ef65f24 100644 --- a/extra/editor/texture_selector.py +++ b/extra/editor/texture_selector.py @@ -67,7 +67,9 @@ def callback_filter(sv): def callback_canvas_motion(event): x, y = event.x, event.y - status_mouse_over['text'] = "Top: "+str(x-(x%32))+","+str(y-(y%32)) + if not imageFrame or not imageFrame.image_file: + return + status_mouse_over['text'] = "Top: "+str(x-(x%32))+","+str(y-(y%32))+", tile: "+ str( (y//32)*imageFrame.image_file.width()//32+x//32+1 ) #print('{}, {}'.format(x, y)) diff --git a/src/saland/Game.cpp b/src/saland/Game.cpp index 545ad0e..46e1ab3 100644 --- a/src/saland/Game.cpp +++ b/src/saland/Game.cpp @@ -44,6 +44,7 @@ https://github.com/sago007/saland #include #include "console/Console.hpp" #include "GameConsoleCommand.hpp" +#include "../terrain/WaterHandler.hpp" int32 velocityIterations = 6; int32 positionIterations = 2; @@ -431,6 +432,8 @@ void Game::ProcessInput(const SDL_Event& event, bool& processed) { int layer_number = 2; // Do not hardcode uint32_t tile = data->drawTile; sago::tiled::setTileOnLayerNumber(data->gameRegion.world.tm, layer_number, tile_x, tile_y, tile); + WaterHandler wh; + wh.updateTile(data->gameRegion.world.tm, tile_x, tile_y); data->gameRegion.world.init_physics(data->gameRegion.physicsBox); } if (event.key.keysym.sym == globalData.playerControls.block_delete @@ -656,6 +659,8 @@ void Game::Update() { && !(data->gameRegion.world.tile_protected(tile_x, tile_y)) ) { int layer_number = 2; // Do not hardcode sago::tiled::setTileOnLayerNumber(data->gameRegion.world.tm, layer_number, tile_x, tile_y, tile); + WaterHandler wh; + wh.updateTile(data->gameRegion.world.tm, tile_x, tile_y); data->gameRegion.world.init_physics(data->gameRegion.physicsBox); } } diff --git a/src/terrain/WaterHandler.cpp b/src/terrain/WaterHandler.cpp new file mode 100644 index 0000000..4fe3286 --- /dev/null +++ b/src/terrain/WaterHandler.cpp @@ -0,0 +1,35 @@ +/* +=========================================================================== + * Saland Adventures +Copyright (C) 2014-2020 Poul Sander + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see http://www.gnu.org/licenses/ + +Source information and contacts persons can be found at +https://github.com/sago007/saland +=========================================================================== +*/ + +#include "WaterHandler.hpp" +#include + +void WaterHandler::updateTile(sago::tiled::TileMap& tm, int x, int y) { + int layer_number = 2; // Do not hardcode + uint32_t tile = default_tile; + uint32_t current_tile = sago::tiled::getTileFromLayer(tm, tm.layers.at(layer_number), x, y); + std::cout << "tile: " << current_tile << "\n"; + if (tiles.find(current_tile) != tiles.end()) { + sago::tiled::setTileOnLayerNumber(tm, layer_number, x, y, tile); + } +} \ No newline at end of file diff --git a/src/terrain/WaterHandler.hpp b/src/terrain/WaterHandler.hpp new file mode 100644 index 0000000..5d0f4f4 --- /dev/null +++ b/src/terrain/WaterHandler.hpp @@ -0,0 +1,37 @@ +/* +=========================================================================== + * Saland Adventures +Copyright (C) 2014-2020 Poul Sander + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see http://www.gnu.org/licenses/ + +Source information and contacts persons can be found at +https://github.com/sago007/saland +=========================================================================== +*/ + +#ifndef TERRAIN_WATERHANDLER_HPP +#define TERRAIN_WATERHANDLER_HPP + +#include +#include "../sagotmx/tmx_struct.h" + +struct WaterHandler { + std::unordered_set tiles = {28, 29, 30, 60, 61, 62, 92, 93, 94, 188, 189, 190}; + uint32_t default_tile = 28; + + void updateTile(sago::tiled::TileMap& world, int x, int y); +}; + +#endif //TERRAIN_WATERHANDLER_HPP