aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authordrumsetmonkey <abelleisle@roadrunner.com>2016-05-03 08:20:49 -0400
committerdrumsetmonkey <abelleisle@roadrunner.com>2016-05-03 08:20:49 -0400
commit30d454d7ffc102f2503dfa84937e706e6fc01a4b (patch)
tree0201c75e8aefabbdfc766642bd26a8acfeedac16 /src
parentf102149e15ca1ac36cbb4e2627e5ce44f2d5273a (diff)
Bow shoots particles
Diffstat (limited to 'src')
-rw-r--r--src/inventory.cpp60
-rw-r--r--src/items.cpp57
2 files changed, 104 insertions, 13 deletions
diff --git a/src/inventory.cpp b/src/inventory.cpp
index b617d09..b363b86 100644
--- a/src/inventory.cpp
+++ b/src/inventory.cpp
@@ -41,8 +41,6 @@ void items(void)
XMLElement *exml = xml.FirstChildElement("item");
XMLElement *cxml = xml.FirstChildElement("currency");
- Sword *tmpSword = new Sword();
-
while (cxml) {
// NEWEWEWEWEWEWEWEW
@@ -62,16 +60,26 @@ void items(void)
// if the type is a sword
} else if (strCaseCmp(name, "sword")) {
+ Sword *tmpSword = new Sword();
tmpSword->setDamage(exml->FloatAttribute("damage"));
ItemMap.push_back(tmpSword->clone());
// if the type is a bow
} else if (strCaseCmp(name, "bow")) {
- ItemMap.push_back(new Bow());
+ Bow *tmpBow = new Bow();
+ tmpBow->setDamage(exml->FloatAttribute("damage"));
+ ItemMap.push_back(tmpBow->clone());
+
+ // arrow
+ } else if (strCaseCmp(name, "arrow")) {
+
+ Arrow *tmpArrow = new Arrow();
+ tmpArrow->setDamage(exml->FloatAttribute("damage"));
+ ItemMap.push_back(tmpArrow->clone());
// uncooked / raw food
- } else if (strCaseCmp(name, "raw food")) {
+ }else if (strCaseCmp(name, "raw food")) {
ItemMap.push_back(new RawFood());
@@ -106,7 +114,7 @@ void items(void)
int Inventory::addItem(std::string name, uint count)
{
- std::cout << "Adding: " << count << " " << name << std::endl;
+ std::cout << "Adding: " << count << " " << name << "\n";
for (uint i = 0; i < ItemMap.size(); i++) {
if (strCaseCmp(ItemMap[i]->name, name)) {
for (auto &it : Items) {
@@ -114,13 +122,32 @@ int Inventory::addItem(std::string name, uint count)
if ((it.second + count) < it.first->maxStackSize) {
it.second += count;
return 0;
+ } else {
+ count -= (it.second + count) - it.first->maxStackSize;
+ it.second = it.first->maxStackSize;
}
}
}
- Items[os] = std::make_pair(ItemMap[i]->clone(), count);
- if (!Items[os+1].second) {
- os++;
- }
+ uint tmpCount = count;
+ do {
+ if ((count) > ItemMap[i]->maxStackSize) {
+ count -= ItemMap[i]->maxStackSize;
+ tmpCount = ItemMap[i]->maxStackSize;
+ } else {
+ tmpCount = count;
+ count = 0;
+ }
+ Items[os] = std::make_pair(ItemMap[i]->clone(), tmpCount);
+ if (!Items[os+1].second) {
+ os++;
+ } else {
+ for (uint z = 0; z < Items.size(); z++) {
+ if (!Items[z].second) {
+ os = z;
+ }
+ }
+ }
+ } while (count > 0);
return 0;
}
}
@@ -608,10 +635,17 @@ void itemDraw(Player *p, Item *d) {
glBindTexture(GL_TEXTURE_2D,d->tex->image[0]);
glColor4ub(255,255,255,255);
glBegin(GL_QUADS);
- glTexCoord2i(0,1);glVertex2f(itemLoc.x, itemLoc.y);
- glTexCoord2i(1,1);glVertex2f(itemLoc.x+d->dim.x,itemLoc.y);
- glTexCoord2i(1,0);glVertex2f(itemLoc.x+d->dim.x,itemLoc.y+d->dim.y);
- glTexCoord2i(0,0);glVertex2f(itemLoc.x, itemLoc.y+d->dim.y);
+ if (p->left) {
+ glTexCoord2i(0,1);glVertex2f(itemLoc.x, itemLoc.y);
+ glTexCoord2i(1,1);glVertex2f(itemLoc.x+d->dim.x,itemLoc.y);
+ glTexCoord2i(1,0);glVertex2f(itemLoc.x+d->dim.x,itemLoc.y+d->dim.y);
+ glTexCoord2i(0,0);glVertex2f(itemLoc.x, itemLoc.y+d->dim.y);
+ } else {
+ glTexCoord2i(1,1);glVertex2f(itemLoc.x, itemLoc.y);
+ glTexCoord2i(0,1);glVertex2f(itemLoc.x+d->dim.x,itemLoc.y);
+ glTexCoord2i(0,0);glVertex2f(itemLoc.x+d->dim.x,itemLoc.y+d->dim.y);
+ glTexCoord2i(1,0);glVertex2f(itemLoc.x, itemLoc.y+d->dim.y);
+ }
glEnd();
glDisable(GL_TEXTURE_2D);
glTranslatef(player->loc.x*2,0,0);
diff --git a/src/items.cpp b/src/items.cpp
index f88186a..21484b4 100644
--- a/src/items.cpp
+++ b/src/items.cpp
@@ -1,7 +1,9 @@
#include <inventory.hpp>
#include <entities.hpp>
+#include <world.hpp>
extern Player *player;
+extern World *currentWorld;
/************************************************************************************
* GLOBAL *
@@ -64,6 +66,10 @@ int Sword::useItem()
if (hitbox.end.x > e->loc.x && hitbox.end.x < e->loc.x + e->width) {
if (hitbox.end.y > e->loc.y && hitbox.end.y < e->loc.y + e->height) {
e->takeHit(damage, 600);
+
+ // add some blood
+ // for(int r = 0; r < (rand()%5);r++)
+ // currentWorld->addParticle(rand()%game::HLINE*3 + e->loc.x - .05f,e->loc.y + e->height*.5, game::HLINE,game::HLINE, -(rand()%10)*.01,((rand()%4)*.001-.002), {(rand()%75+10)/100.0f,0,0}, 10000);
}
}
@@ -83,8 +89,34 @@ int Sword::useItem()
return 0;
}
+int Arrow::useItem()
+{
+
+ return 0;
+}
+
int Bow::useItem()
{
+ float rot = atan(sqrt(pow(ui::mouse.y-(player->loc.y + player->height),2)/pow(ui::mouse.x-player->loc.x,2)));
+ float speed = 1.0;
+ float vx = speed * cos(rot);
+ float vy = speed * sin(rot);
+
+ ui::mouse.x < player->loc.x ? vx *= -1 : vx *= 1;
+ ui::mouse.y < player->loc.y + player->height ? vy *= -1 : vy *= 1;
+
+ currentWorld->addParticle( player->loc.x, // x
+ player->loc.y + player->height, // y
+ HLINES(3), // width
+ HLINES(3), // height
+ vx, // vel.x
+ vy, // vel.y
+ { 139, 69, 19 }, // RGB color
+ 2500 // duration (ms)
+ );
+
+
+
return 0;
}
@@ -115,6 +147,11 @@ Sword* Sword::clone()
return new Sword(*this);
}
+Arrow* Arrow::clone()
+{
+ return new Arrow(*this);
+}
+
Bow* Bow::clone()
{
return new Bow(*this);
@@ -190,6 +227,21 @@ void Sword::setDamage(float d)
}
/**************************************************
+* ARROW *
+**************************************************/
+
+float Arrow::getDamage()
+{
+ return damage;
+}
+
+void Arrow::setDamage(float d)
+{
+ damage = d;
+}
+
+
+/**************************************************
* BOW *
**************************************************/
@@ -198,6 +250,11 @@ float Bow::getDamage()
return damage;
}
+void Bow::setDamage(float d)
+{
+ damage = d;
+}
+
/**************************************************
* FOODS *
**************************************************/