]> code.bitgloo.com Git - clyne/gamedev.git/commitdiff
better mob combat stuff
authorClyne Sullivan <tullivan99@gmail.com>
Tue, 17 May 2016 12:44:01 +0000 (08:44 -0400)
committerClyne Sullivan <tullivan99@gmail.com>
Tue, 17 May 2016 12:44:01 +0000 (08:44 -0400)
Changelog
brice.dat
include/mob.hpp
include/ui.hpp
src/entities.cpp
src/items.cpp
src/mob.cpp
src/ui.cpp
src/ui_menu.cpp
src/world.cpp

index bd4fb68b6db411cc8d1e9f52916b06e2473b3818..00374d514b73eacdcf6c1cb17b79c352faca1b7e 100644 (file)
--- a/Changelog
+++ b/Changelog
 
        - NPCs and mobs can gracefully walk between worlds, carry dialog
        - began more work on combat stuffs
+
+5/16/2016:
+==========
+
+       - added jump page
+       - created quest lightbulb texture
+       - fixed overlay
+       
+5/17/2016:
+==========
+
+       - added onHit and onDeath routines to mobs
+       - added mob drops on arena kills
+       - continued work on new renderings
index ea71945339f7a7cd6d35324a11df49578bb93bfc..c7447b6a5034f00615eef4cd81a6b7237facfd15 100644 (file)
--- a/brice.dat
+++ b/brice.dat
@@ -1,5 +1,5 @@
 2
-canSprint
-0
 canJump
 0
+canSprint
+1
index 00cd396711841759a34636ff9e3754eb0c4ce0c4..4425159d7558d8c0c0f607c11e22b4556784742a 100644 (file)
@@ -1,6 +1,9 @@
 #ifndef MOB_H_
 #define MOB_H_
 
+#include <forward_list>
+#include <tuple>
+
 #include <common.hpp>
 #include <entities.hpp>
 #include <gametime.hpp>
@@ -13,8 +16,12 @@ using namespace tinyxml2;
 extern Player *player;
 extern std::string currentXML;
 
+using Drop = std::tuple<std::string, unsigned int, float>;
+
 class Mob : public Entity {
 protected:
+       std::forward_list<Drop> drop;
+
     unsigned int actCounter;
     unsigned int actCounterInitial;
     bool ridable;
@@ -29,6 +36,10 @@ public:
        void wander(void);
     void ride(Entity *e);
     virtual void act(void) =0;
+
+       virtual void onHit(unsigned int) =0;
+       virtual void onDeath(void);
+
     virtual bool bindTex(void) =0;
     virtual void createFromXML(const XMLElement *e) =0;
 };
@@ -46,6 +57,7 @@ public:
     Page(void);
 
     void act(void);
+       void onHit(unsigned int);
     bool bindTex(void);
     void createFromXML(const XMLElement *e);
 };
@@ -55,6 +67,7 @@ public:
     Door(void);
 
     void act(void);
+       void onHit(unsigned int);
     bool bindTex(void);
     void createFromXML(const XMLElement *e);
 };
@@ -64,6 +77,7 @@ public:
     Cat(void);
 
     void act(void);
+       void onHit(unsigned int);
     bool bindTex(void);
     void createFromXML(const XMLElement *e);
 };
@@ -73,6 +87,7 @@ public:
     Rabbit(void);
 
     void act(void);
+       void onHit(unsigned int);
     bool bindTex(void);
     void createFromXML(const XMLElement *e);
 };
@@ -84,6 +99,7 @@ public:
     Bird(void);
 
     void act(void);
+       void onHit(unsigned int);
     bool bindTex(void);
     void createFromXML(const XMLElement *e);
 };
@@ -96,6 +112,7 @@ public:
     Trigger(void);
 
     void act(void);
+       void onHit(unsigned int);
     bool bindTex(void);
     void createFromXML(const XMLElement *e);
 };
index 099bebf4161442f9b853d315b7e4fb11c87f4524..b950b4b2c34096aa3075fe9c90ed6109f6a180f0 100644 (file)
@@ -94,6 +94,12 @@ namespace ui {
 
        float putText(const float x,const float y,const char *str,...);
 
+       /**
+        * This function is a facility for logic events to draw text; the text
+        * will be prepared then drawn in the render loop.
+        */
+       void putTextL(vec2 c,const char *str, ...);
+
        /*
         *      Creates a dialogBox text string (format: `name`: `text`). This function simply sets up
         *      variables that are drawn in ui::draw(). When the dialog box exists player control is
index ff8dd5d2f11af1099a3d26996e78c3968c3dd01f..c3c580c1c51014c60fdfd57488d453a7e2e62065 100644 (file)
@@ -117,7 +117,7 @@ void Entity::spawn(float x, float y)
        // generate a name
        name = new char[32];
        if (type == MOBT)
-               name[0] = '\0';
+               strncpy(name, "mob", 3);
        else
                randGetomName(this);
 
@@ -127,7 +127,6 @@ void Entity::spawn(float x, float y)
 void Entity::takeHit(unsigned int _health, unsigned int cooldown)
 {
        if (hitCooldown <= 1) {
-               std::cout << "Taking hit " << std::endl;
                // modify variables
                health = fmax(health - _health, 0);
                forcedMove = true;
index 99c143bed3805f1528fa4041f5c0fca38ba0f4c4..6c65b593815ea1597fe856ccd70e6af8c160e49f 100644 (file)
@@ -69,29 +69,30 @@ 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);
+                                                               if (e->type == MOBT)
+                                                                       Mobp(e)->onHit(damage);
+                                                               else
+                                                                       e->takeHit(damage, 600);
 
-                                               static GLuint sColor = Texture::genColor(Color(255,0,0));
-
-                                               GLfloat t[] = {0.0, 0.0,
-                                                                          1.0, 1.0};
-
-                                               GLfloat v[] = {hitbox.start.x,  hitbox.start.y, 1.0,
-                                                                          hitbox.end.x,        hitbox.end.y,   1.0};
+                                                               static GLuint sColor = Texture::genColor(Color(255,0,0));
+                                                               GLfloat t[] = {0.0, 0.0,
+                                                                                          1.0, 1.0};
+                                                               GLfloat v[] = {hitbox.start.x,  hitbox.start.y, 1.0,
+                                                                                          hitbox.end.x,        hitbox.end.y,   1.0};
 
                                        
-                                               glBindTexture(GL_TEXTURE_2D, sColor);
-                                               glUseProgram(worldShader);
-                                               glEnableVertexAttribArray(worldShader_attribute_coord);
-                                               glEnableVertexAttribArray(worldShader_attribute_tex);
+                                                               glBindTexture(GL_TEXTURE_2D, sColor);
+                                                               glUseProgram(worldShader);
+                                                               glEnableVertexAttribArray(worldShader_attribute_coord);
+                                                               glEnableVertexAttribArray(worldShader_attribute_tex);
                                                
-                                               glVertexAttribPointer(worldShader_attribute_coord, 3, GL_FLOAT, GL_FALSE, 0, v);
-                                               glVertexAttribPointer(worldShader_attribute_tex, 2, GL_FLOAT, GL_FALSE, 0, t);
-                                               glDrawArrays(GL_LINES, 0, 2);
+                                                               glVertexAttribPointer(worldShader_attribute_coord, 3, GL_FLOAT, GL_FALSE, 0, v);
+                                                               glVertexAttribPointer(worldShader_attribute_tex, 2, GL_FLOAT, GL_FALSE, 0, t);
+                                                               glDrawArrays(GL_LINES, 0, 2);
 
-                                               glDisableVertexAttribArray(worldShader_attribute_coord);
-                                               glDisableVertexAttribArray(worldShader_attribute_tex);
-                                               glUseProgram(0);
+                                                               glDisableVertexAttribArray(worldShader_attribute_coord);
+                                                               glDisableVertexAttribArray(worldShader_attribute_tex);
+                                                               glUseProgram(0);
                                                                // 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);
index db0b88aa821c85a9a4bd46a0eb6e314be5b5ce26..1f998f7959f838fd242dfa08b546129ef1a98e28 100644 (file)
@@ -39,6 +39,12 @@ void Page::act(void)
     }
 }
 
+void Page::onHit(unsigned int _health)
+{
+       (void)_health;
+       act();
+}
+
 bool Page::bindTex(void)
 {
     glActiveTexture(GL_TEXTURE0);
@@ -72,6 +78,11 @@ void Door::act(void)
 {
 }
 
+void Door::onHit(unsigned int _health)
+{
+       (void)_health;
+}
+
 bool Door::bindTex(void)
 {
     glActiveTexture(GL_TEXTURE0);
@@ -124,6 +135,11 @@ void Cat::act(void)
     }
 }
 
+void Cat::onHit(unsigned int _health)
+{
+       health += _health;
+}
+
 bool Cat::bindTex(void)
 {
     glActiveTexture(GL_TEXTURE0);
@@ -148,6 +164,10 @@ Rabbit::Rabbit(void) : Mob()
     tex = TextureIterator({"assets/rabbit.png", "assets/rabbit1.png"});
     actCounterInitial = randGet() % 240 + 15;
     actCounter = 1;
+
+       drop = {
+               std::make_tuple("Dank MayMay", 5, 1.00f)
+       };
 }
 
 void Rabbit::act(void)
@@ -170,6 +190,11 @@ void Rabbit::act(void)
     }
 }
 
+void Rabbit::onHit(unsigned int _health)
+{
+       takeHit(_health, 600);
+}
+
 bool Rabbit::bindTex(void)
 {
     glActiveTexture(GL_TEXTURE0);
@@ -219,6 +244,11 @@ void Bird::act(void)
     vel.x = direction ? -0.3f : 0.3f;
 }
 
+void Bird::onHit(unsigned int _health)
+{
+       takeHit(_health, 1000);
+}
+
 bool Bird::bindTex(void)
 {
     glActiveTexture(GL_TEXTURE0);
@@ -292,6 +322,11 @@ void Trigger::act(void)
     }
 }
 
+void Trigger::onHit(unsigned int _health)
+{
+       (void)_health;
+}
+
 bool Trigger::bindTex(void)
 {
     return false;
@@ -347,3 +382,18 @@ void Mob::ride(Entity *e)
     else
         rider = e;
 }
+
+void Mob::onDeath(void)
+{
+       vec2 q = vec2 {player->loc.x, game::SCREEN_HEIGHT - 100.0f};
+
+       ui::putTextL(q, "Player got: ");
+
+       for (const auto &d : drop) {
+               if ((randGet() % 100) < std::get<float>(d) * 100.0f) {
+                       q.y -= 20;
+                       ui::putTextL(q, "%d x %s", std::get<unsigned int>(d), std::get<std::string>(d).c_str());
+                       player->inv->addItem(std::get<std::string>(d), std::get<unsigned int>(d));
+               }
+       }
+}
index a5bc2d7b63ca986144afc9748b9adaf2ca7b335c..f9c52bc30999c691e608198e2147db3ba36b91a5 100644 (file)
@@ -58,6 +58,8 @@ static unsigned char fontColor[4] = {255,255,255,255};
  *     Variables for dialog boxes / options.
  */
 
+static std::vector<std::pair<vec2, std::string>> textToDraw;
+
 static std::vector<std::pair<std::string,vec3>> dialogOptText;
 static std::string dialogBoxText;
 static std::vector<vec3> merchArrowLoc (2, vec3 { 0, 0, 0 });
@@ -511,6 +513,18 @@ namespace ui {
                return putString(x, y, buf.get());
        }
 
+       void putTextL(vec2 c, const char *str, ...) {
+               va_list args;
+               std::unique_ptr<char[]> buf (new char[512]);
+               memset(buf.get(), 0, 512 * sizeof(char));
+               
+               va_start(args, str);
+               vsnprintf(buf.get(), 512, str, args);
+               va_end(args);
+
+               textToDraw.push_back(std::make_pair(c, buf.get()));
+       }
+
        void dialogBox(std::string name, std::string opt, bool passive, std::string text, ...) {
                va_list dialogArgs;
                std::unique_ptr<char[]> printfbuf (new char[512]);
@@ -940,7 +954,11 @@ namespace ui {
                                        Mix_PlayChannel(1, dialogClick, 0);
                        }
 
+               } else {
+                       for (const auto &s : textToDraw)
+                               putString(s.first.x, s.first.y, s.second);
                }
+
                if (!fadeIntensity) {
                        vec2 hub = {
                                (SCREEN_WIDTH/2+offset.x)-fontSize*10,
@@ -1154,7 +1172,9 @@ EXIT:
                                if ((action::make = e.button.button & SDL_BUTTON_RIGHT))
                                        /*player->inv->invHover =*/ edown = false;
 
-                       if (dialogBoxExists || pageTexReady) {
+                               textToDraw.clear();
+
+                               if (dialogBoxExists || pageTexReady) {
                                        // right click advances dialog
                                        if ((e.button.button & SDL_BUTTON_RIGHT))
                                                dialogAdvance();
index e766b6176432c80759edb236223220f77ac418c4..309d16a7eccab0f4f86637ae2abef7a2814ed76d 100644 (file)
@@ -153,7 +153,8 @@ namespace ui {
                        glUseProgram(textShader);
                        
                        glBindTexture(GL_TEXTURE_2D, backTex);
-                       drawRect(vec2(offset.x - SCREEN_WIDTH / 2, offset.y - (SCREEN_HEIGHT / 2)), vec2(offset.x + SCREEN_WIDTH / 2, offset.y + (SCREEN_HEIGHT / 2)));
+                       drawRect(vec2(offset.x - SCREEN_WIDTH / 2 - 1, offset.y - (SCREEN_HEIGHT / 2)),
+                                vec2(offset.x + SCREEN_WIDTH / 2, offset.y + (SCREEN_HEIGHT / 2)));
 
                        glUseProgram(0);
 
index 70ba9678ca3ba7de561d6dac7ba4810447f7e15e..b6e46bf7640e3a5c03461d3c2d83b5369be41e2e 100644 (file)
@@ -747,6 +747,8 @@ singleDetect(Entity *e)
     } else if (e->health <= 0) {
         // die
         e->die();
+               if (inBattle && e->type == MOBT)
+                       Mobp(e)->onDeath();
 
         // delete the entity
                for (i = 0; i < entity.size(); i++) {