aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Changelog14
-rw-r--r--assets/music/thoughtful.wavbin0 -> 21782572 bytes
-rw-r--r--brice.dat4
-rw-r--r--include/mob.hpp17
-rw-r--r--include/ui.hpp6
-rw-r--r--src/entities.cpp3
-rw-r--r--src/items.cpp37
-rw-r--r--src/mob.cpp50
-rw-r--r--src/ui.cpp24
-rw-r--r--src/ui_menu.cpp3
-rw-r--r--src/world.cpp2
11 files changed, 135 insertions, 25 deletions
diff --git a/Changelog b/Changelog
index bd4fb68..00374d5 100644
--- a/Changelog
+++ b/Changelog
@@ -997,3 +997,17 @@
- 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
diff --git a/assets/music/thoughtful.wav b/assets/music/thoughtful.wav
new file mode 100644
index 0000000..3960208
--- /dev/null
+++ b/assets/music/thoughtful.wav
Binary files differ
diff --git a/brice.dat b/brice.dat
index ea71945..61d57c2 100644
--- a/brice.dat
+++ b/brice.dat
@@ -1,5 +1,5 @@
2
-canSprint
-0
canJump
0
+canSprint
+0
diff --git a/include/mob.hpp b/include/mob.hpp
index 00cd396..4425159 100644
--- a/include/mob.hpp
+++ b/include/mob.hpp
@@ -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);
};
diff --git a/include/ui.hpp b/include/ui.hpp
index f1b44bb..7d9b9f5 100644
--- a/include/ui.hpp
+++ b/include/ui.hpp
@@ -95,6 +95,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
diff --git a/src/entities.cpp b/src/entities.cpp
index 442c823..b9acc20 100644
--- a/src/entities.cpp
+++ b/src/entities.cpp
@@ -116,7 +116,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);
@@ -126,7 +126,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;
diff --git a/src/items.cpp b/src/items.cpp
index 99c143b..6c65b59 100644
--- a/src/items.cpp
+++ b/src/items.cpp
@@ -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);
diff --git a/src/mob.cpp b/src/mob.cpp
index db0b88a..1f998f7 100644
--- a/src/mob.cpp
+++ b/src/mob.cpp
@@ -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));
+ }
+ }
+}
diff --git a/src/ui.cpp b/src/ui.cpp
index 2a7c22d..a687a35 100644
--- a/src/ui.cpp
+++ b/src/ui.cpp
@@ -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 });
@@ -519,6 +521,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]);
@@ -948,7 +962,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,
@@ -1165,8 +1183,10 @@ EXIT:
if ((action::make = e.button.button & SDL_BUTTON_RIGHT))
/*player->inv->invHover =*/ edown = false;
- if (dialogBoxExists || pageTexReady) {
- //right click advances dialog
+ textToDraw.clear();
+
+ if (dialogBoxExists || pageTexReady) {
+ // right click advances dialog
if ((e.button.button & SDL_BUTTON_RIGHT))
dialogAdvance();
} else {
diff --git a/src/ui_menu.cpp b/src/ui_menu.cpp
index 25782be..5faf8a2 100644
--- a/src/ui_menu.cpp
+++ b/src/ui_menu.cpp
@@ -154,7 +154,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)), -8.5);
+ drawRect(vec2(offset.x - SCREEN_WIDTH / 2 - 1, offset.y - (SCREEN_HEIGHT / 2)),
+ vec2(offset.x + SCREEN_WIDTH / 2, offset.y + (SCREEN_HEIGHT / 2)), -8.5);
glUseProgram(0);
diff --git a/src/world.cpp b/src/world.cpp
index 005c06f..f6df7d6 100644
--- a/src/world.cpp
+++ b/src/world.cpp
@@ -738,6 +738,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++) {