commit c8a7c88b
Add a new spell type to draw ground tiles
Changed files
| M | data/saland/spells/base_spells.json before |
| M | src/saland/Game.cpp before |
| M | src/saland/model/World.cpp before |
| M | src/saland/model/World.hpp before |
diff --git a/data/saland/spells/base_spells.json b/data/saland/spells/base_spells.json
index 28f2689..cc323ec 100644
--- a/data/saland/spells/base_spells.json
+++ b/data/saland/spells/base_spells.json
@@ -37,6 +37,11 @@
"type" : "tile"
}
,{
+ "name" : "spell_create_ground",
+ "tile" : 1,
+ "type" : "tile"
+ }
+ ,{
"icon" : "item_food_potato",
"name" : "spell_spawn_item",
"item_name" : "food_potato"
diff --git a/src/saland/Game.cpp b/src/saland/Game.cpp
index 92a0f58..832a611 100644
--- a/src/saland/Game.cpp
+++ b/src/saland/Game.cpp
@@ -360,10 +360,10 @@ Game::Game() {
data->spell_holder->slot_spell.at(2) = data->spell_holder->get_spell_by_name("spell_create_block:607");
data->spell_holder->slot_spell.at(3) = data->spell_holder->get_spell_by_name("spell_create_block:28");
data->spell_holder->slot_spell.at(4) = data->spell_holder->get_spell_by_name("spell_create_block:16");
- data->spell_holder->slot_spell.at(5) = data->spell_holder->get_spell_by_name("spell_spawn_item:food_potato");
- data->spell_holder->slot_spell.at(6) = data->spell_holder->get_spell_by_name("spell_spawn_item:barrel");
- data->spell_holder->slot_spell.at(7) = data->spell_holder->get_spell_by_name("spell_spawn_item:tree_palm");
- data->spell_holder->slot_spell.at(8) = data->spell_holder->get_spell_by_name("spell_spawn_item:cactus_full");
+ data->spell_holder->slot_spell.at(5) = data->spell_holder->get_spell_by_name("spell_create_ground:1");
+ data->spell_holder->slot_spell.at(6) = data->spell_holder->get_spell_by_name("spell_spawn_item:food_potato");
+ data->spell_holder->slot_spell.at(7) = data->spell_holder->get_spell_by_name("spell_spawn_item:barrel");
+ data->spell_holder->slot_spell.at(8) = data->spell_holder->get_spell_by_name("spell_spawn_item:tree_palm");
data->spell_holder->slot_spell.at(9) = data->spell_holder->get_spell_clear_tile();
}
@@ -1065,6 +1065,28 @@ void Game::Update() {
projectile->timeToLive = 100.0f;
}
}
+ if (data->spell_holder->slot_spell.at(data->spell_holder->slot_selected).name == "spell_create_ground") {
+ if (data->human->castTimeRemaining == 0) {
+ data->human->castTimeRemaining = data->human->castTime;
+ data->human->animation = "spellcast";
+ int base_tile_x = data->world_mouse_x/32;
+ int base_tile_y = data->world_mouse_y/32;
+ int tile = data->spell_holder->slot_spell.at(data->spell_holder->slot_selected).tile;
+ int layer_number = data->gameRegion.world.ground2Layer;
+ if (layer_number >= 0) {
+ for (int dy = 0; dy < data->brushSize; ++dy) {
+ for (int dx = 0; dx < data->brushSize; ++dx) {
+ int tile_x = base_tile_x + dx;
+ int tile_y = base_tile_y + dy;
+ if (sago::tiled::tileInBound(data->gameRegion.world.tm, tile_x, tile_y)
+ && !(data->gameRegion.world.tile_protected(tile_x, tile_y)) ) {
+ sago::tiled::setTileOnLayerNumber(data->gameRegion.world.tm, layer_number, tile_x, tile_y, tile);
+ }
+ }
+ }
+ }
+ }
+ }
if (data->spell_holder->slot_spell.at(data->spell_holder->slot_selected).name == "spell_create_block") {
if (data->human->castTimeRemaining == 0) {
data->human->castTimeRemaining = data->human->castTime;
diff --git a/src/saland/model/World.cpp b/src/saland/model/World.cpp
index e0563d5..1cb46cd 100644
--- a/src/saland/model/World.cpp
+++ b/src/saland/model/World.cpp
@@ -208,13 +208,17 @@ static void bubble_layer_after(sago::tiled::TileMap& tm, const char* layer, cons
}
}
-static void init_tilemap(sago::tiled::TileMap& tm, int& blockingLayer, int& blockingLayer_overlay_1) {
+static void init_tilemap(sago::tiled::TileMap& tm, int& ground2Layer, int& blockingLayer, int& blockingLayer_overlay_1) {
+ ground2Layer = -1;
blockingLayer = -1;
blockingLayer_overlay_1 = -1;
int prefab_layer_ground = -1;
int prefab_blocking_2 = -1;
int prefab_layer_overlay = -1;
for (size_t i=0; i < tm.layers.size(); ++i) {
+ if (tm.layers[i].name == "ground_2") {
+ ground2Layer = i;
+ }
if (tm.layers[i].name == "blocking") {
blockingLayer = i;
}
@@ -251,8 +255,11 @@ static void init_tilemap(sago::tiled::TileMap& tm, int& blockingLayer, int& bloc
bubble_layer_after(tm, "blocking_overlay_1", "prefab_blocking_2");
bubble_layer_after(tm, "prefab_overlay_1", "blocking_overlay_1");
bubble_layer_after(tm, "overlay_1", "prefab_overlay_1");
- // Recheck blocking and blocking_overlay_1 layers as they might have been shifted while sorting.
+ // Recheck layers as they might have been shifted while sorting.
for (size_t i=0; i < tm.layers.size(); ++i) {
+ if (tm.layers[i].name == "ground_2") {
+ ground2Layer = i;
+ }
if (tm.layers[i].name == "blocking") {
blockingLayer = i;
}
@@ -274,7 +281,7 @@ void World::init(std::shared_ptr<b2World>& world, const std::string& mapFileName
tm.tileset[i].alternativeSource = &ts.back();
}
}
- init_tilemap(tm, blockingLayer, blockingLayer_overlay_1);
+ init_tilemap(tm, ground2Layer, blockingLayer, blockingLayer_overlay_1);
init_physics(world);
protected_tiles.resize(tm.height*tm.width);
diff --git a/src/saland/model/World.hpp b/src/saland/model/World.hpp
index 11cb641..ed77454 100644
--- a/src/saland/model/World.hpp
+++ b/src/saland/model/World.hpp
@@ -44,6 +44,7 @@ public:
std::vector<b2Body*> managed_bodies;
std::vector<bool> protected_tiles;
std::vector<bool> blocking_tiles;
+ int ground2Layer = -1;
int blockingLayer = -1;
int blockingLayer_overlay_1 = -1;
};