diff options
author | drumsetmonkey <abelleisle@roadrunner.com> | 2016-05-13 12:48:11 -0400 |
---|---|---|
committer | drumsetmonkey <abelleisle@roadrunner.com> | 2016-05-13 12:48:11 -0400 |
commit | 23f3b1471b2bbfe92252456f32c9ae55a9d1f213 (patch) | |
tree | 97f520b944aaa699854b745e182911615ce10c02 /src | |
parent | 0e24afb4cd060701348398b16f2b1d89b8935b81 (diff) |
Things flash red when hit
Diffstat (limited to 'src')
-rw-r--r-- | src/entities.cpp | 75 | ||||
-rw-r--r-- | src/ui.cpp | 11 |
2 files changed, 47 insertions, 39 deletions
diff --git a/src/entities.cpp b/src/entities.cpp index 6b5e1d3..205e848 100644 --- a/src/entities.cpp +++ b/src/entities.cpp @@ -99,6 +99,8 @@ Entity::Entity(void) ticksToUse = 0; hitCooldown = 0; + hitDuration = maxHitDuration = 0; + inv = nullptr; name = nullptr; } @@ -118,16 +120,21 @@ void Entity::spawn(float x, float y) name[0] = '\0'; else randGetomName(this); + + setCooldown(0); } 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; hitCooldown = cooldown; + hitDuration = maxHitDuration = 350.0f; + // pushback vel.x = player->left ? -0.5f : 0.5f; vel.y = 0.2f; @@ -146,7 +153,8 @@ void Entity::setCooldown(unsigned int c) void Entity::handleHits(void) { - hitCooldown = fmax(hitCooldown - game::time::getDeltaTime(), 0); + hitCooldown = fmax(static_cast<int>(hitCooldown - game::time::getDeltaTime()), 0); + hitDuration = fmax(hitDuration - game::time::getDeltaTime(), 0); if (!forcedMove) return; @@ -418,23 +426,32 @@ void Entity::draw(void) else glColor3ub(255,255,255);*/ - glUseProgram(worldShader); - glUniform1i(worldShader_uniform_texture, 0); - glEnableVertexAttribArray(worldShader_attribute_coord); - glEnableVertexAttribArray(worldShader_attribute_tex); + glUseProgram(worldShader); + // make the entity hit flash red + if (maxHitDuration-hitDuration) { + float flashAmt = 1-(hitDuration/maxHitDuration); + glUniform4f(worldShader_uniform_color, 1.0, flashAmt, flashAmt, 1.0); + } - glVertexAttribPointer(worldShader_attribute_coord, 3, GL_FLOAT, GL_FALSE, 0, coords); - if (left) - glVertexAttribPointer(worldShader_attribute_tex, 2, GL_FLOAT, GL_FALSE, 0 ,tex_coordL); - else - glVertexAttribPointer(worldShader_attribute_tex, 2, GL_FLOAT, GL_FALSE, 0 ,tex_coord); - glDrawArrays(GL_TRIANGLES, 0, 6); + glUniform1i(worldShader_uniform_texture, 0); + glEnableVertexAttribArray(worldShader_attribute_coord); + glEnableVertexAttribArray(worldShader_attribute_tex); + + glVertexAttribPointer(worldShader_attribute_coord, 3, GL_FLOAT, GL_FALSE, 0, coords); + if (left) + glVertexAttribPointer(worldShader_attribute_tex, 2, GL_FLOAT, GL_FALSE, 0 ,tex_coordL); + else + glVertexAttribPointer(worldShader_attribute_tex, 2, GL_FLOAT, GL_FALSE, 0 ,tex_coord); + glDrawArrays(GL_TRIANGLES, 0, 6); + + glUniform4f(worldShader_uniform_color, 1.0, 1.0, 1.0, 1.0); NOPE: if (near && type != MOBT) ui::putStringCentered(loc.x+width/2,loc.y-ui::fontSize-game::HLINE/2,name); if (health != maxHealth) { - glBindTexture(GL_TEXTURE_2D,colorIndex); + static GLuint frontH = Texture::genColor(Color(255,0,0)); + static GLuint backH = Texture::genColor(Color(150,0,0)); glUniform1i(worldShader_uniform_texture, 0); GLfloat coord_back[] = { @@ -456,33 +473,23 @@ if (health != maxHealth) { loc.x, loc.y + height + game::HLINE * 2, z, loc.x, loc.y + height, z, }; - - static const vec2 index1 = Texture::getIndex(Color(0,0,0)); - GLfloat back_tex[] = { - float(.25*index1.x), float(.125*index1.y), - float(.25*index1.x), float(.125*index1.y), - float(.25*index1.x), float(.125*index1.y), - - float(.25*index1.x), float(.125*index1.y), - float(.25*index1.x), float(.125*index1.y), - float(.25*index1.x), float(.125*index1.y), + + glBindTexture(GL_TEXTURE_2D, backH); + GLfloat tex[] = { 0.0, 0.0, + 1.0, 0.0, + 1.0, 1.0, + + 1.0, 1.0, + 0.0, 1.0, + 0.0, 0.0, }; glVertexAttribPointer(worldShader_attribute_coord, 3, GL_FLOAT, GL_FALSE, 0, coord_back); - glVertexAttribPointer(worldShader_attribute_tex, 2, GL_FLOAT, GL_FALSE, 0, back_tex); + glVertexAttribPointer(worldShader_attribute_tex, 2, GL_FLOAT, GL_FALSE, 0, tex); glDrawArrays(GL_TRIANGLES, 0, 6); - static const vec2 index2 = Texture::getIndex(Color(255,0,0)); - GLfloat front_tex[] = { - float(.25*index2.x), float(.125*index2.y), - float(.25*index2.x), float(.125*index2.y), - float(.25*index2.x), float(.125*index2.y), - - float(.25*index2.x), float(.125*index2.y), - float(.25*index2.x), float(.125*index2.y), - float(.25*index2.x), float(.125*index2.y), - }; + glBindTexture(GL_TEXTURE_2D, frontH); glVertexAttribPointer(worldShader_attribute_coord, 3, GL_FLOAT, GL_FALSE, 0, coord_front); - glVertexAttribPointer(worldShader_attribute_tex, 2, GL_FLOAT, GL_FALSE, 0, front_tex); + glVertexAttribPointer(worldShader_attribute_tex, 2, GL_FLOAT, GL_FALSE, 0, tex); glDrawArrays(GL_TRIANGLES, 0, 6); } @@ -820,7 +820,7 @@ namespace ui { offset.x + (SCREEN_WIDTH / 10) - 40, offset.y + (SCREEN_HEIGHT / 5), 1.0}; glActiveTexture(GL_TEXTURE0); - glBindTexture(GL_TEXTURE_2D, getItemTexture(merchTrade.item[0])); + glBindTexture(GL_TEXTURE_2D, getItemTexture(merchTrade.item[1])); glUniform1i(textShader_uniform_texture, 0); glUseProgram(textShader); @@ -831,7 +831,7 @@ namespace ui { glVertexAttribPointer(textShader_attribute_tex, 2, GL_FLOAT, GL_FALSE, 0, item_tex); glDrawArrays(GL_TRIANGLES, 0 ,6); - glBindTexture(GL_TEXTURE_2D, getItemTexture(merchTrade.item[1])); + glBindTexture(GL_TEXTURE_2D, getItemTexture(merchTrade.item[0])); glVertexAttribPointer(textShader_attribute_coord, 3, GL_FLOAT, GL_FALSE, 0, right_item); glVertexAttribPointer(textShader_attribute_tex, 2, GL_FLOAT, GL_FALSE, 0, item_tex); @@ -1103,6 +1103,7 @@ EXIT: auto indoor = dynamic_cast<IndoorWorld *>(currentWorld); Mob *m; // ;lkjfdsa + Entity *en; // used for interaction SDL_Event e; @@ -1153,15 +1154,15 @@ EXIT: if ((action::make = e.button.button & SDL_BUTTON_RIGHT)) /*player->inv->invHover =*/ edown = false; - if (dialogBoxExists || pageTexReady) { + if (dialogBoxExists || pageTexReady) { // right click advances dialog if ((e.button.button & SDL_BUTTON_RIGHT)) dialogAdvance(); } else { // left click uses item if (e.button.button & SDL_BUTTON_LEFT) { - if ((m = currentWorld->getNearMob(*player)) != nullptr) { - player->inv->currentAddInteract(m); + if ((en = currentWorld->getNearMob(*player)) != nullptr) { + player->inv->currentAddInteract(en); player->inv->useCurrent(); } } |