diff --git a/src/saland/GameItems.cpp b/src/saland/GameItems.cpp new file mode 100644 index 0000000..2ba92b6 --- /dev/null +++ b/src/saland/GameItems.cpp @@ -0,0 +1,41 @@ +/* +=========================================================================== + * 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 "GameItems.hpp" + +static ItemDef itemDef; + +const ItemDef& getItem(const std::string& itemName) { + if (itemName == "barrel") { + itemDef.radius = 16.0f; + itemDef.sprite = "item_barrel"; + itemDef.itemid = "barrel"; + itemDef.isStatic = true; + } + if (itemName == "food_potato") { + itemDef.radius = 9.0f; + itemDef.sprite = "item_food_potato"; + itemDef.isStatic = false; + } + return itemDef; +} \ No newline at end of file diff --git a/src/saland/GameItems.hpp b/src/saland/GameItems.hpp new file mode 100644 index 0000000..81304e0 --- /dev/null +++ b/src/saland/GameItems.hpp @@ -0,0 +1,38 @@ +/* +=========================================================================== + * 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 GAMEITEMS_HPP +#define GAMEITEMS_HPP + +#include "model/placeables.hpp" + +struct ItemDef { + float radius = 1.0f; + std::string itemid = ""; + std::string sprite = ""; + bool isStatic = true; +}; + +const ItemDef& getItem(const std::string& itemName); + +#endif /* GAMEITEMS_HPP */ \ No newline at end of file diff --git a/src/saland/GameRegion.cpp b/src/saland/GameRegion.cpp index ab238bf..5cd329e 100644 --- a/src/saland/GameRegion.cpp +++ b/src/saland/GameRegion.cpp @@ -22,6 +22,7 @@ https://github.com/sago007/saland */ #include "GameRegion.hpp" +#include "GameItems.hpp" GameRegion::GameRegion() { Init(0, 0, "world1", false); @@ -103,20 +104,13 @@ void GameRegion::Init(int x, int y, const std::string& worldName, bool forceRese world.init(physicsBox, loadMap); - ItemDef barrelDef; - barrelDef.radius = 16.0f; - barrelDef.sprite = "item_barrel"; - barrelDef.itemid = "barrel"; - barrelDef.isStatic = true; + const ItemDef& barrelDef = getItem("barrel"); SpawnItem(barrelDef, 100.0f, 100.0f); SpawnItem(barrelDef, 100.0f, 100.0f+32.0f); SpawnItem(barrelDef, 100.0f, 100.0f+64.0f); - ItemDef potatoDef; - potatoDef.radius = 9.0f; - potatoDef.sprite = "item_food_potato"; - potatoDef.isStatic = false; + const ItemDef& potatoDef = getItem("food_potato"); SpawnItem(potatoDef, 600.0f, 20.0f); diff --git a/src/saland/GameRegion.hpp b/src/saland/GameRegion.hpp index 0f1a9af..1099c40 100644 --- a/src/saland/GameRegion.hpp +++ b/src/saland/GameRegion.hpp @@ -26,6 +26,7 @@ https://github.com/sago007/saland #include "model/World.hpp" #include "model/placeables.hpp" +#include "GameItems.hpp" #include "../sagotmx/tmx_struct.h" #include @@ -35,13 +36,6 @@ struct MonsterDef { }; -struct ItemDef { - float radius = 1.0f; - std::string itemid = ""; - std::string sprite = ""; - bool isStatic = true; -}; - class GameRegion { public: