aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Changelog8
-rw-r--r--brice.dat8
-rw-r--r--include/entities.hpp3
-rw-r--r--include/inventory.hpp7
-rw-r--r--include/texture.hpp3
-rw-r--r--include/world.hpp2
-rw-r--r--main.cpp11
-rw-r--r--src/entities.cpp3
-rw-r--r--src/inventory.cpp8
-rw-r--r--src/mob.cpp17
-rw-r--r--src/ui.cpp7
-rw-r--r--src/world.cpp14
-rw-r--r--xml/bobshouse.xml2
-rw-r--r--xml/playerSpawnHill1.xml6
-rw-r--r--xml/playerSpawnHill1_Building1.xml6
-rw-r--r--xml/town.xml5
16 files changed, 82 insertions, 28 deletions
diff --git a/Changelog b/Changelog
index ee05b85..b530132 100644
--- a/Changelog
+++ b/Changelog
@@ -1071,3 +1071,11 @@ Late June (6/16/2016 - 6/27/2016)
- redid forest trees, mountains, houses
- fixed major issue with entering structures
- exploring more ideas for soundtracks
+
+6/29/2016:
+==========
+
+ - added chests
+ - added q to drop items, as objects
+ - chests snag dropped objects, right click to reclaim
+ - control setting is good, needs saving though
diff --git a/brice.dat b/brice.dat
index 2033bae..4dad711 100644
--- a/brice.dat
+++ b/brice.dat
@@ -1,7 +1,7 @@
3
-canSprint
-1
-canJump
-0
Slow
0
+canJump
+0
+canSprint
+1
diff --git a/include/entities.hpp b/include/entities.hpp
index 4abb3cb..2d96a9f 100644
--- a/include/entities.hpp
+++ b/include/entities.hpp
@@ -386,9 +386,8 @@ public:
};
class Object : public Entity{
-private:
- std::string iname;
public:
+ std::string iname;
std::string pickupDialog;
bool questObject = false;
diff --git a/include/inventory.hpp b/include/inventory.hpp
index a85e537..ca402b3 100644
--- a/include/inventory.hpp
+++ b/include/inventory.hpp
@@ -219,13 +219,16 @@ public:
/***********************************************************************************
* OLD STUFF THAT NEEDS TO GET UPDATED *
**********************************************************************************/
+
+using InventorySlot = std::pair<Item *, unsigned int>;
+
class Inventory {
private:
unsigned int size; //how many slots our inventory has
unsigned int sel; //what item is currently selected
int os = 0;
public:
- std::vector<std::pair<Item*, uint>> Items;
+ std::vector<InventorySlot> Items;
bool invOpen = false; //is the inventory open
bool invOpening = false; //is the opening animation playing
@@ -253,6 +256,8 @@ public:
void setSelectionDown();
void draw(void); // Draws a text list of items in this inventory (should only be called for the player for now)
+
+ const Item* getCurrentItem(void);
};
void initInventorySprites(void);
diff --git a/include/texture.hpp b/include/texture.hpp
index c301af1..7f22a79 100644
--- a/include/texture.hpp
+++ b/include/texture.hpp
@@ -46,6 +46,9 @@ public:
TextureIterator(void) {
position = std::begin(textures);
}
+ ~TextureIterator(void) {
+ textures.clear();
+ }
TextureIterator(const std::vector<std::string> &l) {
for (const auto &s : l)
textures.emplace_back(Texture::loadTexture(s), s);
diff --git a/include/world.hpp b/include/world.hpp
index a2de048..9a892d8 100644
--- a/include/world.hpp
+++ b/include/world.hpp
@@ -66,7 +66,7 @@ extern std::string currentXML;
/**
* Defines how many game ticks it takes to go from day to night or vice versa.
*/
-constexpr const unsigned int DAY_CYCLE = 12000;
+constexpr const unsigned int DAY_CYCLE = 10000;
/**
* Defines the velocity of player when moved by the keyboard
diff --git a/main.cpp b/main.cpp
index fd8ed4d..1bfce77 100644
--- a/main.cpp
+++ b/main.cpp
@@ -265,8 +265,8 @@ int main(int argc, char *argv[])
for (const auto &xf : xmlFiles) {
if (xf[0] != '.') {
XMLDocument xmld;
- auto file = (xmlFolder + xf).c_str();
- xmld.LoadFile(file);
+ auto file = xmlFolder + xf;
+ xmld.LoadFile(file.c_str());
auto xmle = xmld.FirstChildElement("World");
@@ -286,7 +286,8 @@ int main(int argc, char *argv[])
xmle->DeleteAttribute("dindex");
xmle = xmle->NextSiblingElement();
}
- xmld.SaveFile(file, false);
+
+ xmld.SaveFile(file.c_str(), false);
}
}
@@ -328,6 +329,10 @@ int main(int argc, char *argv[])
arena->setBackground(WorldBGType::Forest);
arena->setBGM("assets/music/embark.wav");
+
+ player->inv->addItem("Wood Sword", 10);
+
+
// the main loop, in all of its gloriousness..
std::thread([&]{
while (gameRunning) {
diff --git a/src/entities.cpp b/src/entities.cpp
index 0c312e2..f4c020c 100644
--- a/src/entities.cpp
+++ b/src/entities.cpp
@@ -188,6 +188,7 @@ Player::Player() : Entity()
Player::~Player()
{
delete inv;
+ delete &tex;
}
void Player::createFromXML(XMLElement *e, World *w=nullptr)
@@ -716,7 +717,7 @@ COMMONAIFUNC:
// handle give tags
if ((oxml = exml->FirstChildElement("give"))) {
do player->inv->addItem(oxml->Attribute("id"), oxml->UnsignedAttribute("count"));
- while ((oxml = oxml->NextSiblingElement()));
+ while ((oxml = oxml->NextSiblingElement("give")));
}
// handle take tags
diff --git a/src/inventory.cpp b/src/inventory.cpp
index ede5eeb..7e8c94e 100644
--- a/src/inventory.cpp
+++ b/src/inventory.cpp
@@ -727,3 +727,11 @@ bool Inventory::detectCollision(vec2 one, vec2 two) {
(void)two;
return false;
}
+
+const Item* Inventory::getCurrentItem(void)
+{
+ if (Items.size() > 0)
+ return Items[sel].first;
+ else
+ return nullptr;
+}
diff --git a/src/mob.cpp b/src/mob.cpp
index 20273d6..99d6f34 100644
--- a/src/mob.cpp
+++ b/src/mob.cpp
@@ -432,11 +432,26 @@ Chest::Chest(void) : Mob()
width = HLINES(10);
height = HLINES(5);
tex = TextureIterator({"assets/chest.png"});
+ inv = new Inventory(1);
}
void Chest::act(void)
{
- //die();
+ if (isInside(ui::mouse) && player->isNear(this)) {
+ if ((SDL_GetMouseState(NULL, NULL) & SDL_BUTTON(SDL_BUTTON_RIGHT)) && !ui::dialogBoxExists)
+ for (auto &i : inv->Items) {
+ player->inv->addItem(i.first->name, i.second);
+ inv->takeItem(i.first->name, i.second);
+ }
+ }
+
+ for (auto &e : currentWorld->entity) {
+ if (e->type == OBJECTT && e->isNear(this)) {
+ auto o = dynamic_cast<Object *>(e);
+ inv->addItem(o->iname, 1);
+ e->health = 0;
+ }
+ }
}
void Chest::onHit(unsigned int _health)
diff --git a/src/ui.cpp b/src/ui.cpp
index f3523f6..18bae1b 100644
--- a/src/ui.cpp
+++ b/src/ui.cpp
@@ -1533,6 +1533,13 @@ EXIT:
action::disable();
heyOhLetsGo = 0;
+ } else if (SDL_KEY == SDLK_q) {
+ auto item = player->inv->getCurrentItem();
+ if (item != nullptr) {
+ if (player->inv->takeItem(item->name, 1) == 0)
+ currentWorld->addObject(item->name, "o shit waddup",
+ player->loc.x + player->width / 2, player->loc.y + player->height / 2);
+ }
} else switch (SDL_KEY) {
case SDLK_F3:
debug ^= true;
diff --git a/src/world.cpp b/src/world.cpp
index 7294fda..9c51ec8 100644
--- a/src/world.cpp
+++ b/src/world.cpp
@@ -780,26 +780,26 @@ singleDetect(Entity *e)
if (entity[i] == e) {
switch (e->type) {
case STRUCTURET:
- killed = "structure";
+ killed = " structure";
build.erase(std::find(std::begin(build), std::end(build), e));
break;
case NPCT:
- killed = "NPC";
+ killed = "n NPC";
npc.erase(std::find(std::begin(npc), std::end(npc), e));
break;
case MOBT:
- killed = "mob";
+ killed = " mob";
mob.erase(std::find(std::begin(mob), std::end(mob), e));
break;
case OBJECTT:
- killed = "object";
+ killed = "n object";
object.erase(std::find(std::begin(object), std::end(object), *Objectp(e)));
break;
default:
break;
}
- std::cout << "Killed a " << killed << "...\n";
+ std::cout << "Killed a" << killed << "...\n";
entity.erase(entity.begin() + i);
return;
}
@@ -1823,7 +1823,9 @@ loadWorldFromXMLNoSave(std::string path) {
return nullptr;
_currentXML = xmlFolder + path;
- _currentXMLRaw = readFile(_currentXML.c_str());
+ const char *worthless = readFile(_currentXML.c_str());
+ _currentXMLRaw = worthless;
+ delete[] worthless;
// create a temporary XMLDocument if this isn't the main world
if (!loadedLeft && !loadedRight)
diff --git a/xml/bobshouse.xml b/xml/bobshouse.xml
index ebf020b..2d69813 100644
--- a/xml/bobshouse.xml
+++ b/xml/bobshouse.xml
@@ -3,5 +3,5 @@
<style background="1" bgm="assets/music/embark.wav" folder="assets/style/classic/"/>
<floor width="1600"/>
<link outside="town.xml"/>
- <npc name="Bob" hasDialog="false" spawnx="30"/>
+ <npc name="Bob" hasDialog="false" spawnx="30" health="1" x="-229.27991" y="0" dindex="9999"/>
</IndoorWorld>
diff --git a/xml/playerSpawnHill1.xml b/xml/playerSpawnHill1.xml
index 92e4c87..73fe104 100644
--- a/xml/playerSpawnHill1.xml
+++ b/xml/playerSpawnHill1.xml
@@ -16,11 +16,11 @@
<Dialog name="Guy">
<text id="0" nextid="1">
Hello there! My name is Ralph.
- <gotox>300</gotox>
+ <gotox>300</gotox>
</text>
<text id="1">
...
- <gotox>1000</gotox>
+ <gotox>1000</gotox>
<set id="Slow" value="0"/>
<set id="canSprint" value="1"/>
</text>
@@ -33,5 +33,5 @@
<text id="0" stop="true">
Hey friend! It's dangerous out there, here take these!
Wait, promise you'll stop by my stand in the local market!
- <give id="Wood Sword" count="1"/> <give id="Hunters Bow" count="1"/> <give id="Crude Arrow" count="110"/> <give id="Fried Chicken" count="1"/> <give id="Mossy Torch" count="1"/></text>
+ <give id="Wood Sword" count="1"/> <give id="Hunters Bow" count="1"/> <give id="Crude Arrow" count="110"/> <give id="Fried Chicken" count="1"/> <give id="Mossy Torch" count="1"/></text>
</Dialog>
diff --git a/xml/playerSpawnHill1_Building1.xml b/xml/playerSpawnHill1_Building1.xml
index 74eec76..4fd30cb 100644
--- a/xml/playerSpawnHill1_Building1.xml
+++ b/xml/playerSpawnHill1_Building1.xml
@@ -10,17 +10,17 @@
<Dialog name="Bob">
<text id="0" nextid="1" pause="true">
Hey. Have a Dank MayMay :)
- <give id="Dank MayMay" count="1"/></text>
+ <give id="Dank MayMay" count="1"/></text>
<text id="1" nextid="2">
What? You want another Dank MayMay?
</text>
<text id="2" nextid="3" pause="true">
K.
- <give id="Dank MayMay" count="1"/></text>
+ <give id="Dank MayMay" count="1"/></text>
<text id="3" nextid="4">
Well... I'm out of Dank MayMays.
</text>
<text id="4">
Have a sword though.
- <give id="Wood Sword" count="1"/></text>
+ <give id="Wood Sword" count="1"/></text>
</Dialog>
diff --git a/xml/town.xml b/xml/town.xml
index 5ee8397..b9da09c 100644
--- a/xml/town.xml
+++ b/xml/town.xml
@@ -4,8 +4,8 @@
<generation type="Random" width="1600"/>
<time>6000</time>
<spawnx>-300</spawnx>
- <npc name="Sanc" hasDialog="true" health="1" x="414.76144" y="62.599087" dindex="9999"/>
- <npc name="Bob" hasDialog="true" spawnx="30" health="1" x="356.11185" y="60.999081" dindex="0"/>
+ <npc name="Sanc" hasDialog="true" health="1" x="464.45755" y="65.399185" dindex="0"/>
+ <npc name="Bob" hasDialog="true" spawnx="30" health="1" x="-772.5" y="59.999001" dindex="0"/>
<structure type="1" spawnx="300" alive="1"/>
<structure inside="bobshouse.xml" type="1" spawnx="10" alive="1"/>
<chest alive="1"/>
@@ -13,6 +13,7 @@
<Dialog name="Bob">
<text id="0" nextid="1" pause="true">
+ <give id="Dank MayMay" count="10"/>
<content alive="1">
Hey there! The name's Bob. Good to see you've finally woken up from your nap by the cliff there... lol
</content>