]> code.bitgloo.com Git - clyne/gamedev.git/commitdiff
Bow shoots particles
authordrumsetmonkey <abelleisle@roadrunner.com>
Tue, 3 May 2016 12:20:49 +0000 (08:20 -0400)
committerdrumsetmonkey <abelleisle@roadrunner.com>
Tue, 3 May 2016 12:20:49 +0000 (08:20 -0400)
assets/items/arrow_crude.png [new file with mode: 0644]
config/items.xml
include/inventory.hpp
src/inventory.cpp
src/items.cpp
xml/playerSpawnHill1.xml

diff --git a/assets/items/arrow_crude.png b/assets/items/arrow_crude.png
new file mode 100644 (file)
index 0000000..3d82074
Binary files /dev/null and b/assets/items/arrow_crude.png differ
index 0918c336dbdd984bbf19d71467b3aee8db91dcf4..119284235bc93296d9cce21ed6fe1c06928ff755 100644 (file)
@@ -13,5 +13,6 @@
 <item name="Fried Chicken"  type="Cooked Food"  value="10" maxStackSize="6" sprite="assets/items/FOOD_CHICKEN_FRIED.png" />
 
 <!-- NEW ITEMS -->
-<item name="Wood Sword"     type="Sword"        damage="69" maxStackSize="1" sprite="assets/items/SWORD_WOOD.png" />
-<item name="Clyne is shit bow" type="Bow"       damage="10" maxStackSize="1" sprite="assets/items/bow.png"/>
+<item name="Wood Sword"     type="Sword"    damage="3"  maxStackSize="1"    sprite="assets/items/SWORD_WOOD.png" />
+<item name="Hunters Bow"    type="Bow"      damage="2"  maxStackSize="1"    sprite="assets/items/bow.png"/>
+<item name="Crude Arrow"    type="Arrow"    damage="1"  maxStackSize="99"   sprite="assets/items/arrow_crude.png"/>
index bee2fbdfffe828beb389b345d57ae35446aae698..6712c26729776c94b3581d90ad83425aa3afbd8e 100644 (file)
@@ -112,6 +112,24 @@ public:
        Sword* clone();
 };
 
+class Arrow : public Item {
+private:
+       // same as sword
+       float damage;
+public:
+
+       // see sword
+       float getDamage();
+
+       // sets amount of damage
+       void setDamage(float d);
+
+       // uses item
+       int useItem();
+
+       Arrow *clone();
+};
+
 /**
  *     Bow class. We use this for shooting bow and arrows
  */
@@ -123,6 +141,9 @@ public:
        // returns the amount of damage, see sword
        float getDamage();
 
+       // sets the amount of damages
+       void setDamage(float d);
+
        // handles shooting and arrow curving
        int useItem();
 
index b617d09877aefa3ecb1a4df94d110bf7967eab25..b363b860d8445c2a2b8ffa1e3d04fe60368efc8b 100644 (file)
@@ -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);
index f88186ab23c1bace1d70be70116e869aa4159bad..21484b4b8de4f15b244115a1627f9197f67cf9a7 100644 (file)
@@ -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);
@@ -189,6 +226,21 @@ void Sword::setDamage(float d)
        damage = 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                      *
 **************************************************/
index aa0a36ce293e061d9c4d6e50fd19c791da257d32..6b911a5ac1ec9e0be1952943d64d519ea0e23de9 100644 (file)
@@ -79,7 +79,8 @@ And it wasn't stormy.
        <text id="0" pause="true">
                Here have this sword!
                <give id="Wood Sword" count="1"/>
-               <give id="Clyne is shit bow" count="1"/>
+               <give id="Hunters Bow" count="1"/>
+               <give id="Crude Arrow" count="110"/>
                <give id="Fried Chicken" count="1"/>
        </text>
 </Dialog>