GLint worldShader_attribute_tex;
GLint worldShader_uniform_texture;
GLint worldShader_uniform_transform;
+GLint worldShader_uniform_color;
// keeps a simple palette of colors for single-color draws
GLuint colorIndex;
/**
* Creating the text shader and its attributes/uniforms
*/
- textShader = create_program("shaders/new.vert", "shaders/new.frag");
- textShader_attribute_coord = get_attrib(textShader, "coord2d");
- textShader_attribute_tex = get_attrib(textShader, "tex_coord");
- textShader_uniform_texture = get_uniform(textShader, "sampler");
- textShader_uniform_transform = get_uniform(textShader, "ortho");
- textShader_uniform_color = get_uniform(textShader, "tex_color");
+ textShader = create_program("shaders/new.vert", "shaders/new.frag");
+ textShader_attribute_coord = get_attrib(textShader, "coord2d");
+ textShader_attribute_tex = get_attrib(textShader, "tex_coord");
+ textShader_uniform_texture = get_uniform(textShader, "sampler");
+ textShader_uniform_transform = get_uniform(textShader, "ortho");
+ textShader_uniform_color = get_uniform(textShader, "tex_color");
/**
* Creating the world's shader and its attributes/uniforms
*/
- worldShader = create_program("shaders/world.vert", "shaders/world.frag");
- worldShader_attribute_coord = get_attrib(worldShader, "coord2d");
- worldShader_attribute_tex = get_attrib(worldShader, "tex_coord");
- worldShader_uniform_texture = get_uniform(worldShader, "sampler");
+ worldShader = create_program("shaders/world.vert", "shaders/world.frag");
+ worldShader_attribute_coord = get_attrib(worldShader, "coord2d");
+ worldShader_attribute_tex = get_attrib(worldShader, "tex_coord");
+ worldShader_uniform_texture = get_uniform(worldShader, "sampler");
worldShader_uniform_transform = get_uniform(worldShader, "ortho");
+ worldShader_uniform_color = get_uniform(worldShader, "tex_color");
//glEnable(GL_MULTISAMPLE);
glUniform4f(textShader_uniform_color, 1.0, 1.0, 1.0, 1.0);
glUseProgram(worldShader);
glUniformMatrix4fv(worldShader_uniform_transform, 1, GL_FALSE, glm::value_ptr(ortho));
-
+ glUniform4f(worldShader_uniform_color, 1.0, 1.0, 1.0, 1.0);
/**************************
**** RENDER STUFF HERE ****
**************************/
ticksToUse = 0;
hitCooldown = 0;
+ hitDuration = maxHitDuration = 0;
+
inv = nullptr;
name = nullptr;
}
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;
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;
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[] = {
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);
}
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);
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);
auto indoor = dynamic_cast<IndoorWorld *>(currentWorld);
Mob *m; // ;lkjfdsa
+ Entity *en; // used for interaction
SDL_Event e;
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();
}
}