aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorClyne Sullivan <tullivan99@gmail.com>2016-03-08 08:42:20 -0500
committerClyne Sullivan <tullivan99@gmail.com>2016-03-08 08:42:20 -0500
commit82c75b0a97eba2f78206d3b97d47eaa580a82f0c (patch)
tree90116b676fc5b8cef16fbea8b07c4951dd645ea4 /src
parent02419534e3a0753abc74d8d15b1dc8ac0e3b31a7 (diff)
world lighting fixed
Diffstat (limited to 'src')
-rw-r--r--src/entities.cpp8
-rw-r--r--src/ui.cpp4
-rw-r--r--src/world.cpp15
3 files changed, 23 insertions, 4 deletions
diff --git a/src/entities.cpp b/src/entities.cpp
index 06269d6..8a10428 100644
--- a/src/entities.cpp
+++ b/src/entities.cpp
@@ -8,6 +8,7 @@ extern std::istream *names;
extern Player *player; // main.cpp
extern World *currentWorld; // main.cpp
extern unsigned int loops; // main.cpp
+extern unsigned int tickCount; // main.cpp
GLuint waterTex;
@@ -295,6 +296,10 @@ void Object::reloadTexture(void){
void Entity::draw(void){ //draws the entities
glPushMatrix();
glColor3ub(255,255,255);
+
+ if ( !alive )
+ return;
+
if(type==NPCT){
if(NPCp(this)->aiFunc.size()){
glColor3ub(255,255,0);
@@ -626,6 +631,7 @@ void Player::save(void){
data.append(std::to_string((int)loc.y) + "\n");
data.append(std::to_string((int)health) + "\n");
data.append(std::to_string((int)maxHealth) + "\n");
+ data.append(std::to_string((int)tickCount) + "\n");
data.append(std::to_string((int)inv->items.size()) + "\n");
for(auto &i : inv->items)
@@ -666,6 +672,8 @@ void Player::sspawn(float x,float y){
health = std::stoi(ddata);
std::getline(data,ddata);
maxHealth = std::stoi(ddata);
+ std::getline(data,ddata);
+ tickCount = std::stoi(ddata);
std::getline(data,ddata);
for(i = std::stoi(ddata);i;i--){
diff --git a/src/ui.cpp b/src/ui.cpp
index 97121b4..eb25e2e 100644
--- a/src/ui.cpp
+++ b/src/ui.cpp
@@ -30,6 +30,7 @@ extern std::vector<NPC *> AIpreaddr;
*/
extern bool gameRunning;
+extern unsigned int tickCount;
/*
* Freetype variables, and a GLuint for referencing rendered letters.
@@ -1276,6 +1277,9 @@ DONE:
} else if ( !dialogBoxExists || dialogPassive ) {
tmp = currentWorld;
switch(SDL_KEY){
+ case SDLK_t:
+ tickCount += 50;
+ break;
case SDLK_a:
if(fadeEnable)break;
player->vel.x=-.15;
diff --git a/src/world.cpp b/src/world.cpp
index 4de6e39..0a84c20 100644
--- a/src/world.cpp
+++ b/src/world.cpp
@@ -407,6 +407,13 @@ draw( Player *p )
// world width in pixels
int width = worldData.size() * HLINE;
+ // shade value for GLSL
+ float shadeAmbient = -worldShade / 50.0f + 0.5f; // -0.5f to 1.5f
+ if ( shadeAmbient < 0 )
+ shadeAmbient = 0;
+ else if ( shadeAmbient > 0.9f )
+ shadeAmbient = 1;
+
/*
* Draw background images.
*/
@@ -459,7 +466,7 @@ draw( Player *p )
glEnable( GL_TEXTURE_2D );
bgTex->bindNext();
- safeSetColorA( 150 - shadeBackground, 150 - shadeBackground, 150 - shadeBackground, 220 );
+ safeSetColorA( 150 + shadeBackground * 2, 150 + shadeBackground * 2, 150 + shadeBackground * 2, 255 );
glBegin( GL_QUADS );
for ( i = 0; i <= (int)(worldData.size() * HLINE / 1920); i++ ) {
@@ -472,7 +479,7 @@ draw( Player *p )
for ( i = 0; i < 4; i++ ) {
bgTex->bindNext();
- safeSetColorA( bgDraw[i][0] - shadeBackground, bgDraw[i][0] - shadeBackground, bgDraw[i][0] - shadeBackground, bgDraw[i][1] );
+ safeSetColorA( bgDraw[i][0] + shadeBackground * 2, bgDraw[i][0] + shadeBackground * 2, bgDraw[i][0] + shadeBackground * 2, bgDraw[i][1] );
glBegin( GL_QUADS );
for( int j = worldStart; j <= -worldStart; j += 600 ){
@@ -534,7 +541,7 @@ draw( Player *p )
glUseProgram( shaderProgram );
glUniform1i( glGetUniformLocation( shaderProgram, "sampler"), 0 );
- glUniform1f( glGetUniformLocation( shaderProgram, "amb" ), -worldShade / 50.0f );
+ glUniform1f( glGetUniformLocation( shaderProgram, "amb" ), shadeAmbient );
if ( p->light ) {
pointArray[2 * (light.size() + 1) ] = (float)( p->loc.x + SCREEN_WIDTH / 2 );
@@ -1196,7 +1203,7 @@ void IndoorWorld::draw(Player *p){
glUseProgram( shaderProgram );
glUniform1i( glGetUniformLocation( shaderProgram, "sampler"), 0 );
- glUniform1f( glGetUniformLocation( shaderProgram, "amb" ), 0.5f - worldShade / 50.0f );
+ glUniform1f( glGetUniformLocation( shaderProgram, "amb" ), 0.3f );
if ( p->light ) {
pointArray[2 * (light.size() + 1) ] = (float)( p->loc.x + SCREEN_WIDTH / 2 );