diff options
-rw-r--r-- | Changelog | 9 | ||||
-rw-r--r-- | assets/bgWoodTile.png | bin | 65078 -> 75181 bytes | |||
-rw-r--r-- | assets/grass.png | bin | 0 -> 128 bytes | |||
-rw-r--r-- | assets/house1N.png | bin | 0 -> 1464 bytes | |||
-rw-r--r-- | assets/maybeplayer.png | bin | 2898 -> 4146 bytes | |||
-rw-r--r-- | assets/music/theme_jazz.wav | bin | 13193260 -> 13193260 bytes | |||
-rw-r--r-- | assets/names_en-us | 2 | ||||
-rw-r--r-- | assets/pages/gootaGoFast.png | bin | 0 -> 20663 bytes | |||
-rw-r--r-- | assets/sounds/ozone.wav | bin | 12739644 -> 0 bytes | |||
-rw-r--r-- | include/common.h | 8 | ||||
-rw-r--r-- | include/entities.h | 9 | ||||
-rw-r--r-- | include/world.h | 13 | ||||
-rw-r--r-- | main.cpp | 20 | ||||
-rw-r--r-- | src/entities.cpp | 41 | ||||
-rw-r--r-- | src/gameplay.cpp | 22 | ||||
-rw-r--r-- | src/inventory.cpp | 4 | ||||
-rw-r--r-- | src/ui.cpp | 2 | ||||
-rw-r--r-- | src/world.cpp | 223 | ||||
-rw-r--r-- | test.frag | 28 | ||||
-rw-r--r-- | xcf/bgWoodTile.xcf | bin | 511093 -> 511349 bytes | |||
-rw-r--r-- | xcf/maybeplayer.xcf | bin | 7564 -> 3468 bytes |
21 files changed, 253 insertions, 128 deletions
@@ -435,3 +435,12 @@ - checking files for potential divide by 0 errors, due to random floating point errors still have floating point errors - restarted work on real shading (GLSL stuffs) + +12/17/2015: +=========== + + - continued work on player sprite + - continued work on GLSL shaders + - fixed NPC spawning world location stuff + - messed with threads/forks + - re-fixed/added indoor environment; fixed indoor background diff --git a/assets/bgWoodTile.png b/assets/bgWoodTile.png Binary files differindex 0c7c64b..5b631bf 100644 --- a/assets/bgWoodTile.png +++ b/assets/bgWoodTile.png diff --git a/assets/grass.png b/assets/grass.png Binary files differnew file mode 100644 index 0000000..e05fb9b --- /dev/null +++ b/assets/grass.png diff --git a/assets/house1N.png b/assets/house1N.png Binary files differnew file mode 100644 index 0000000..0285533 --- /dev/null +++ b/assets/house1N.png diff --git a/assets/maybeplayer.png b/assets/maybeplayer.png Binary files differindex ee0e49d..c580ff7 100644 --- a/assets/maybeplayer.png +++ b/assets/maybeplayer.png diff --git a/assets/music/theme_jazz.wav b/assets/music/theme_jazz.wav Binary files differindex 1c62bbc..94f888e 100644 --- a/assets/music/theme_jazz.wav +++ b/assets/music/theme_jazz.wav diff --git a/assets/names_en-us b/assets/names_en-us index a841bb8..bc2c212 100644 --- a/assets/names_en-us +++ b/assets/names_en-us @@ -55,7 +55,7 @@ mPingu mShrek mLogan mJohn Cena -mDex Dogtective +mDexDogtective fShani fIsidra fAja diff --git a/assets/pages/gootaGoFast.png b/assets/pages/gootaGoFast.png Binary files differnew file mode 100644 index 0000000..a113f5d --- /dev/null +++ b/assets/pages/gootaGoFast.png diff --git a/assets/sounds/ozone.wav b/assets/sounds/ozone.wav Binary files differdeleted file mode 100644 index 60354e5..0000000 --- a/assets/sounds/ozone.wav +++ /dev/null diff --git a/include/common.h b/include/common.h index 9dcc110..207b95f 100644 --- a/include/common.h +++ b/include/common.h @@ -46,6 +46,12 @@ typedef struct { float y; } vec2; +typedef struct { + float x; + float y; + float z; +} vec3; + /** * This structure contains two sets of coordinates for ray drawing. */ @@ -142,6 +148,8 @@ extern vec2 offset; */ extern unsigned int loops; +extern GLuint shaderProgram; + /** * Prints a formatted debug message to the console, along with the callee's file and line * number. diff --git a/include/entities.h b/include/entities.h index 7a97200..a4bc282 100644 --- a/include/entities.h +++ b/include/entities.h @@ -44,6 +44,8 @@ enum BUILD_SUB{ FOUNTAIN }; +class World; + class Particles{ public: vec2 loc; @@ -124,6 +126,7 @@ public: GENDER gender; Texturec *tex; + Texturec *ntex; unsigned int randDialog; @@ -161,14 +164,14 @@ public: class Structures : public Entity{ public: - void *inWorld; - void *inside; + World *inWorld; + World *inside; BUILD_SUB bsubtype; Structures(); ~Structures(); - unsigned int spawn(_TYPE, BUILD_SUB, float, float); + unsigned int spawn(_TYPE, BUILD_SUB, float, float, World *); }; class Mob : public Entity{ diff --git a/include/world.h b/include/world.h index 0a23965..e10d0dc 100644 --- a/include/world.h +++ b/include/world.h @@ -26,7 +26,7 @@ * Defines how many game ticks it takes for a day to elapse. */ -#define DAY_CYCLE 3000 +#define DAY_CYCLE 12000 /** * The background type enum. @@ -51,6 +51,11 @@ typedef enum { RAIN /**< Rain (not implemented :) )*/ } WEATHER; + +typedef struct{ + vec2 loc; + Color color; +}Light; /** * The line structure. * This structure is used to store the world's ground, stored in vertical @@ -165,14 +170,16 @@ public: std::vector<Entity *> entity; std::vector<Object *> object; std::vector<Particles *> particles; + std::vector<Light > light; - void addStructure(_TYPE t,BUILD_SUB sub,float x,float y,World *outside,World *inside); - void addVillage(int bCount, int npcMin, int npcMax,_TYPE t,float x,float y,World *outside,World *inside); + void addStructure(_TYPE t,BUILD_SUB sub,float x,float y,World *inside); + void addVillage(int bCount, int npcMin, int npcMax,_TYPE t,float x,float y,World *outside); void addMob(int t,float x,float y); void addMob(int t,float x,float y,void (*hey)(Mob *)); void addNPC(float x,float y); void addObject(ITEM_ID, bool, const char *, float, float); void addParticle(float, float, float, float, float, float, Color color, int); + void addLight(vec2, Color); void update(Player *p,unsigned int delta); @@ -4,6 +4,7 @@ */ #include <cstdio> // fopen +#include <thread> #include <common.h> #include <world.h> @@ -197,10 +198,10 @@ extern int fadeIntensity; /******************************************************************************* * MAIN ************************************************************************ *******************************************************************************/ - int main(/*int argc, char *argv[]*/){ //*argv = (char *)argc; gameRunning=false; + /*! * (Attempt to) Initialize SDL libraries so that we can use SDL facilities and eventually * make openGL calls. Exit if there was an error. @@ -298,7 +299,7 @@ int main(/*int argc, char *argv[]*/){ if((err=glewInit()) != GLEW_OK){ std::cout << "GLEW was not able to initialize! Error: " << glewGetErrorString(err) << std::endl; return -1; - } + } /* * Initialize the FreeType libraries and select what font to use using functions from the ui @@ -453,7 +454,7 @@ void mainLoop(void){ if(!currentTime){ // Initialize currentTime if it hasn't been currentTime=millis(); - prevPrevTime=currentTime; + //prevPrevTime=currentTime; } /* @@ -598,7 +599,10 @@ void render(){ player->near=true; // Draw the player's name + //glUniform2f(glGetUniformLocation(shaderProgram, "lightLocation"), 640,100); currentWorld->draw(player); + //glUniform3f(glGetUniformLocation(shaderProgram, "lightColor"), 0,1.0f,0); + /* * Apply shaders if desired. @@ -676,15 +680,9 @@ void render(){ glUseProgramObjectARB(0); } - glUseProgramObjectARB(shaderProgram); - glUniform2f(glGetUniformLocation(shaderProgram, "lightLocation"), 250,250); - glUniform3f(glGetUniformLocation(shaderProgram, "lightColor"), 1,0,0); - glColor4f(0.0f,0.0f,0.0f,1.0f); - glRectf(-SCREEN_WIDTH/2,0,SCREEN_WIDTH/2,SCREEN_HEIGHT); - glUseProgramObjectARB(0); - - player->inv->draw(); + player->inv->draw(); + /* * Here we draw a black overlay if it's been requested. */ diff --git a/src/entities.cpp b/src/entities.cpp index cd8d29e..d12a1ca 100644 --- a/src/entities.cpp +++ b/src/entities.cpp @@ -1,6 +1,8 @@ #include <entities.h> #include <ui.h> +#include <unistd.h> + extern FILE* names; extern unsigned int loops; @@ -77,7 +79,7 @@ void Entity::spawn(float x, float y){ //spawns the entity you pass to it based o Player::Player(){ //sets all of the player specific traits on object creation width = HLINE * 10; - height = HLINE * 16; + height = HLINE * 15; type = PLAYERT; //set type to player subtype = 0; @@ -126,6 +128,7 @@ Structures::Structures(){ //sets the structure type near = false; tex = new Texturec(3,"assets/house1.png", "assets/house2.png", "assets/fountain1.png"); + ntex = new Texturec(1, "assets/house1N.png"); inWorld = NULL; name = NULL; @@ -196,6 +199,7 @@ Object::~Object(){ void Entity::draw(void){ //draws the entities glPushMatrix(); glColor3ub(255,255,255); + //glUniform1i(glGetUniformLocation(shaderProgram, "sampler"), 0); if(type==NPCT){ if(NPCp(this)->aiFunc.size()){ glColor3ub(255,255,0); @@ -222,23 +226,29 @@ void Entity::draw(void){ //draws the entities //currentWorld->addParticle(loc.x,loc.y-HLINE,HLINE,HLINE,0,0,{0.0f,.17f,0.0f},1000); if(up){ if(++texState==2)up=false; + glActiveTexture(GL_TEXTURE0); tex->bindNext(); }else{ if(!--texState)up=true; + glActiveTexture(GL_TEXTURE0); tex->bindPrev(); } } if(!ground){ + glActiveTexture(GL_TEXTURE0 + 0); tex->bind(0); }else if(vel.x){ + glActiveTexture(GL_TEXTURE0 + 0); tex->bind(texState); }else{ + glActiveTexture(GL_TEXTURE0 + 0); tex->bind(1); } break; case MOBT: switch(subtype){ case MS_RABBIT: + glActiveTexture(GL_TEXTURE0 + 0); tex->bind(!ground); break; case MS_TRIGGER: @@ -247,6 +257,7 @@ void Entity::draw(void){ //draws the entities case MS_BIRD: case MS_DOOR: default: + glActiveTexture(GL_TEXTURE0 + 0); tex->bind(0); break; } @@ -255,26 +266,39 @@ void Entity::draw(void){ //draws the entities for(auto &strt : currentWorld->build){ if(this == strt){ if(strt->bsubtype == HOUSE){ + glActiveTexture(GL_TEXTURE1); + ntex->bind(0); + //When rendering an objectwith this program. + glActiveTexture(GL_TEXTURE0 + 0); tex->bind(0); + //glBindSampler(0, linearFiltering); + + }else if(strt->bsubtype == HOUSE2){ + glActiveTexture(GL_TEXTURE0 + 0); tex->bind(1); }else if(strt->bsubtype == FOUNTAIN){ + glActiveTexture(GL_TEXTURE0 + 0); tex->bind(2); } } } break; default: + glActiveTexture(GL_TEXTURE0 + 0); tex->bind(0); break; } glColor3ub(255,255,255); + glUseProgram(shaderProgram); + glUniform1i(glGetUniformLocation(shaderProgram, "sampler"), 0); glBegin(GL_QUADS); glTexCoord2i(0,1);glVertex2i(loc.x, loc.y); glTexCoord2i(1,1);glVertex2i(loc.x + width, loc.y); glTexCoord2i(1,0);glVertex2i(loc.x + width, loc.y + height); glTexCoord2i(0,0);glVertex2i(loc.x, loc.y + height); glEnd(); + glUseProgram(0); NOPE: glDisable(GL_TEXTURE_2D); glMatrixMode(GL_MODELVIEW); @@ -393,7 +417,7 @@ void Object::interact(void){ * point to have non-normal traits so it could be invisible or invincible... */ -unsigned int Structures::spawn(_TYPE t, BUILD_SUB sub, float x, float y){ +unsigned int Structures::spawn(_TYPE t, BUILD_SUB sub, float x, float y, World *oi){ loc.x = x; loc.y = y; type = t; @@ -404,6 +428,8 @@ unsigned int Structures::spawn(_TYPE t, BUILD_SUB sub, float x, float y){ height = 40 * HLINE; bsubtype = sub; + inWorld = oi; + /* * tempN is the amount of entities that will be spawned in the village. Currently the village * will spawn bewteen 2 and 7 villagers for the starting hut. @@ -418,10 +444,7 @@ unsigned int Structures::spawn(_TYPE t, BUILD_SUB sub, float x, float y){ * with type NPC. */ - //((World*)(inWorld))->addNPC(loc.x + i * HLINE ,100); - //inWorld->addNPC(loc.x + i * HLINE, 100); - currentWorld->addNPC(loc.x + i * HLINE ,100); - + inWorld->addNPC(loc.x + i * HLINE ,100); } @@ -463,7 +486,11 @@ void Mob::wander(int timeRun){ case MS_TRIGGER: if(player->loc.x + player->width / 2 > loc.x && player->loc.x + player->width / 2 < loc.x + width ){ - hey(this); + //if(!vfork()){ + hey(this); + /*_exit(0); + }*/ + } break; case MS_DOOR: diff --git a/src/gameplay.cpp b/src/gameplay.cpp index d439814..1c83bd8 100644 --- a/src/gameplay.cpp +++ b/src/gameplay.cpp @@ -42,6 +42,7 @@ float gen_worldSpawnHill3(float x){ */ void worldSpawnHill1_hillBlock(Mob *callee){ + std::cout<<"oi"; player->vel.x = 0; player->loc.x = callee->loc.x + callee->width; ui::dialogBox(player->name,NULL,false,"This hill seems to steep to climb up..."); @@ -93,6 +94,8 @@ static World *worldSpawnHill1; static World *worldSpawnHill2; static World *worldSpawnHill3; +static IndoorWorld *worldSpawnHill2_Building1; + /* * initEverything() start */ @@ -118,8 +121,8 @@ void initEverything(void){ worldSpawnHill3->setBGM("assets/music/ozone.wav"); worldSpawnHill3->addMob(MS_TRIGGER,-500,0,worldSpawnHill3_itemGet); worldSpawnHill3->addMob(MS_TRIGGER,0,0,worldSpawnHill3_itemSee); - worldSpawnHill3->addObject(TEST_ITEM,false,"",-200,300); - worldSpawnHill3->addMob(MS_TRIGGER,400,0,worldSpawnHill3_leave); + worldSpawnHill3->addObject(FLASHLIGHT,false,"",-200,300); + worldSpawnHill3->addMob(MS_TRIGGER,650,0,worldSpawnHill3_leave); worldSpawnHill3->addHole(800,1000); worldSpawnHill1->toRight = worldSpawnHill2; @@ -140,15 +143,20 @@ void initEverything(void){ //playerSpawnHill->addMob(MS_TRIGGER,-1300,0,CUTSCENEEE);*/ - currentWorld = worldSpawnHill1; - worldSpawnHill2->addStructure(STRUCTURET,HOUSE,(rand()%120*HLINE),100,worldSpawnHill1,worldSpawnHill2); + worldSpawnHill2_Building1 = new IndoorWorld(); + worldSpawnHill2_Building1->generate(300); + worldSpawnHill2_Building1->setBackground(BG_WOODHOUSE); + worldSpawnHill2_Building1->setBGM("assets/music/theme_jazz.wav"); + + worldSpawnHill2->addStructure(STRUCTURET,HOUSE,(rand()%120*HLINE),100,worldSpawnHill2_Building1); + worldSpawnHill2->addLight({300,100},{1.0f,1.0f,1.0f}); - worldSpawnHill2->addStructure(STRUCTURET,HOUSE,(rand()%120*HLINE),100,worldSpawnHill1,worldSpawnHill2); + //worldSpawnHill2->addStructure(STRUCTURET,HOUSE,(rand()%120*HLINE),100,worldSpawnHill1,worldSpawnHill2); player = new Player(); player->spawn(200,100); - + + currentWorld = worldSpawnHill1; currentWorld->bgmPlay(NULL); - atexit(destroyEverything); } diff --git a/src/inventory.cpp b/src/inventory.cpp index c0f4163..b6819d1 100644 --- a/src/inventory.cpp +++ b/src/inventory.cpp @@ -291,7 +291,8 @@ void itemDraw(Player *p,ITEM_ID id,ITEM_TYPE type){ default: hangle = 0.0f; } - + glUseProgram(shaderProgram); + glUniform1i(glGetUniformLocation(shaderProgram, "sampler"), 0); glTranslatef(itemLoc.x,itemLoc.y,0); glRotatef(hangle, 0.0f, 0.0f, 1.0f); glTranslatef(-itemLoc.x,-itemLoc.y,0); @@ -307,6 +308,7 @@ void itemDraw(Player *p,ITEM_ID id,ITEM_TYPE type){ glDisable(GL_TEXTURE_2D); glTranslatef(player->loc.x*2,0,0); glPopMatrix(); + glUseProgram(0); } int Inventory::useItem(void){ @@ -512,7 +512,7 @@ namespace ui { glVertex2f(x+1+SCREEN_WIDTH-HLINE*16,y+1); glVertex2f(x+1+SCREEN_WIDTH-HLINE*16,y-1-SCREEN_HEIGHT/4); glVertex2f(x-1 ,y-1-SCREEN_HEIGHT/4); - glVertex2f(x-1 ,y+2); + glVertex2f(x ,y+1); glEnd(); glColor3ub(0,0,0); diff --git a/src/world.cpp b/src/world.cpp index 0ecf7ee..b539a87 100644 --- a/src/world.cpp +++ b/src/world.cpp @@ -33,6 +33,8 @@ const char *bgPaths[2][7]={ NULL} }; +Texturec *grassT; + const float bgDraw[3][3]={ {100,240,.6 }, {150,250,.4 }, @@ -88,6 +90,7 @@ World::World(void){ star = new vec2[100]; memset(star,0,100 * sizeof(vec2)); + grassT = new Texturec(1,"assets/grass.png"); } void World::deleteEntities(void){ @@ -383,27 +386,24 @@ LLLOOP: width = (-x_start) << 1; glEnable(GL_TEXTURE_2D); - + bgTex->bind(0); safeSetColorA(255,255,255,255 - worldShade * 4); - glBegin(GL_QUADS); glTexCoord2i(0,0);glVertex2i( cx_start,SCREEN_HEIGHT); glTexCoord2i(1,0);glVertex2i(-cx_start,SCREEN_HEIGHT); glTexCoord2i(1,1);glVertex2i(-cx_start,0); glTexCoord2i(0,1);glVertex2i( cx_start,0); glEnd(); - + bgTex->bindNext(); - safeSetColorA(255,255,255,worldShade * 4); - + safeSetColorA(255,255,255,worldShade * 4); glBegin(GL_QUADS); glTexCoord2i(0,0);glVertex2i( cx_start,SCREEN_HEIGHT); glTexCoord2i(1,0);glVertex2i(-cx_start,SCREEN_HEIGHT); glTexCoord2i(1,1);glVertex2i(-cx_start,0); glTexCoord2i(0,1);glVertex2i( cx_start,0); glEnd(); - glDisable(GL_TEXTURE_2D); /* @@ -426,13 +426,13 @@ LLLOOP: } } + glEnable(GL_TEXTURE_2D); /* * Draw the mountains. */ - bgTex->bindNext(); safeSetColorA(150-bgshade,150-bgshade,150-bgshade,220); @@ -551,79 +551,108 @@ LOOP2: bool hey=false; glEnable(GL_TEXTURE_2D); + glActiveTexture(GL_TEXTURE0); bgTex->bindNext(); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); //for the s direction glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); //for the t direction + glUseProgram(shaderProgram); + glUniform1i(glGetUniformLocation(shaderProgram, "sampler"), 0); + glUniform1f(glGetUniformLocation(shaderProgram, "amb"), float(shade+50.0f)/100.0f); + if(light.size() == 0){ + glUniform2f(glGetUniformLocation(shaderProgram, "lightLocation"), 0,-1000); + glUniform3f(glGetUniformLocation(shaderProgram, "lightColor"), 0.0f,0.0f,0.0f); + }else{ + for(auto &l : light){ + glUniform2f(glGetUniformLocation(shaderProgram, "lightLocation"), l.loc.x-offset.x,l.loc.y); + glUniform3f(glGetUniformLocation(shaderProgram, "lightColor"), l.color.red,l.color.green,l.color.blue); + } + } + glBegin(GL_QUADS); - for(i=is;i<(unsigned)ie-GEN_INC;i++){ - cline[i].y+=(yoff-DRAW_Y_OFFSET); // Add the y offset - if(!cline[i].y){ - cline[i].y=base; - hey=true; - glColor4ub(0,0,0,255); - }else - safeSetColorA(150+shade*2,150+shade*2,150+shade*2,255); - glTexCoord2i(0,0);glVertex2i(cx_start+i*HLINE ,cline[i].y-GRASS_HEIGHT); - glTexCoord2i(1,0);glVertex2i(cx_start+i*HLINE+HLINE,cline[i].y-GRASS_HEIGHT); - glTexCoord2i(1,(int)(cline[i].y/64)+cline[i].color);glVertex2i(cx_start+i*HLINE+HLINE,0); - glTexCoord2i(0,(int)(cline[i].y/64)+cline[i].color);glVertex2i(cx_start+i*HLINE ,0); - cline[i].y-=(yoff-DRAW_Y_OFFSET); // Restore the line's y value - if(hey){ - hey=false; - cline[i].y=0; - } + for(i=is;i<(unsigned)ie-GEN_INC;i++){ + cline[i].y+=(yoff-DRAW_Y_OFFSET); // Add the y offset + if(!cline[i].y){ + cline[i].y=base; + hey=true; + glColor4ub(0,0,0,255); + }else safeSetColorA(150+shade*2,150+shade*2,150+shade*2,255); + glTexCoord2i(0,0);glVertex2i(cx_start+i*HLINE ,cline[i].y-GRASS_HEIGHT); + glTexCoord2i(1,0);glVertex2i(cx_start+i*HLINE+HLINE,cline[i].y-GRASS_HEIGHT); + glTexCoord2i(1,(int)(cline[i].y/64)+cline[i].color);glVertex2i(cx_start+i*HLINE+HLINE,0); + glTexCoord2i(0,(int)(cline[i].y/64)+cline[i].color);glVertex2i(cx_start+i*HLINE ,0); + cline[i].y-=(yoff-DRAW_Y_OFFSET); // Restore the line's y value + if(hey){ + hey=false; + cline[i].y=0; } + } glEnd(); + glUseProgram(0); glDisable(GL_TEXTURE_2D); - /* * Draw grass on every line. */ float cgh[2]; - glBegin(GL_QUADS); - for(i=is;i<(unsigned)ie-GEN_INC;i++){ - - /* - * Load the current line's grass values - */ - - if(cline[i].y)memcpy(cgh,cline[i].gh,2*sizeof(float)); - else memset(cgh,0 ,2*sizeof(float)); - - - - /* - * Flatten the grass if the player is standing on it. - */ - - if(!cline[i].gs){ - cgh[0]/=4; - cgh[1]/=4; - } - - /* - * Actually draw the grass. - */ - - cline[i].y+=(yoff-DRAW_Y_OFFSET); - - safeSetColor(shade,100+shade*1.5,shade); - - glVertex2i(cx_start+i*HLINE ,cline[i].y+cgh[0]); - glVertex2i(cx_start+i*HLINE+HLINE/2,cline[i].y+cgh[0]); - glVertex2i(cx_start+i*HLINE+HLINE/2,cline[i].y-GRASS_HEIGHT); - glVertex2i(cx_start+i*HLINE ,cline[i].y-GRASS_HEIGHT); - - glVertex2i(cx_start+i*HLINE+HLINE/2,cline[i].y+cgh[1]); - glVertex2i(cx_start+i*HLINE+HLINE ,cline[i].y+cgh[1]); - glVertex2i(cx_start+i*HLINE+HLINE ,cline[i].y-GRASS_HEIGHT); - glVertex2i(cx_start+i*HLINE+HLINE/2,cline[i].y-GRASS_HEIGHT); - - cline[i].y-=(yoff-DRAW_Y_OFFSET); + + glEnable(GL_TEXTURE_2D); + glActiveTexture(GL_TEXTURE0); + grassT->bind(0); + glUseProgram(shaderProgram); + glUniform1i(glGetUniformLocation(shaderProgram, "sampler"), 0); + //glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); //for the s direction + //glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); //for the t direction + //glBegin(GL_QUADS); + + for(i=is;i<(unsigned)ie-GEN_INC;i++){ + + /* + * Load the current line's grass values + */ + + if(cline[i].y)memcpy(cgh,cline[i].gh,2*sizeof(float)); + else memset(cgh,0 ,2*sizeof(float)); + + + + /* + * Flatten the grass if the player is standing on it. + */ + + if(!cline[i].gs){ + cgh[0]/=4; + cgh[1]/=4; } - glEnd(); - + + /* + * Actually draw the grass. + */ + + cline[i].y+=(yoff-DRAW_Y_OFFSET); + safeSetColorA(255,255,255,255); + glBegin(GL_QUADS); + glTexCoord2i(0,0);glVertex2i(cx_start+i*HLINE ,cline[i].y+cgh[0]); + glTexCoord2i(1,0);glVertex2i(cx_start+i*HLINE+HLINE/2,cline[i].y+cgh[0]); + glTexCoord2i(1,1);glVertex2i(cx_start+i*HLINE+HLINE/2,cline[i].y-GRASS_HEIGHT); + glTexCoord2i(0,1);glVertex2i(cx_start+i*HLINE ,cline[i].y-GRASS_HEIGHT); + glEnd(); + + glBegin(GL_QUADS); + glTexCoord2i(0,0);glVertex2i(cx_start+i*HLINE+HLINE/2,cline[i].y+cgh[1]); + glTexCoord2i(1,0);glVertex2i(cx_start+i*HLINE+HLINE ,cline[i].y+cgh[1]); + glTexCoord2i(1,1);glVertex2i(cx_start+i*HLINE+HLINE ,cline[i].y-GRASS_HEIGHT); + glTexCoord2i(0,1);glVertex2i(cx_start+i*HLINE+HLINE/2,cline[i].y-GRASS_HEIGHT); + glEnd(); + + cline[i].y-=(yoff-DRAW_Y_OFFSET); + } + //glEnd(); + //glUseProgram(0); + glDisable(GL_TEXTURE_2D); + + //glUseProgram(0); + /* * Draw non-structure entities. */ @@ -903,16 +932,17 @@ LOOOOP: goto LOOOOP; } } -void World::addStructure(_TYPE t,BUILD_SUB sub, float x,float y,World *outside,World *inside){ +void World::addStructure(_TYPE t,BUILD_SUB sub, float x,float y,World *inside){ build.push_back(new Structures()); - build.back()->spawn(t,sub,x,y); - build.back()->inWorld=outside; - build.back()->inside=inside; + build.back()->spawn(t,sub,x,y,this); + build.back()->inWorld=this; + build.back()->inside = (World *)inside; + ((IndoorWorld *)inside)->outside = this; entity.push_back(build.back()); } -void World::addVillage(int bCount, int npcMin, int npcMax,_TYPE t,float x,float y,World *outside,World *inside){ +void World::addVillage(int bCount, int npcMin, int npcMax,_TYPE t,float x,float y,World *outside){ std::cout << npcMin << ", " << npcMax << std::endl; int xwasd; for(int i = 0; i < bCount; i++){ @@ -921,7 +951,7 @@ void World::addVillage(int bCount, int npcMin, int npcMax,_TYPE t,float x,float for(auto &bu : build){ if(xwasd > bu->loc.x && xwasd < bu->loc.x+bu->width)goto HERE; } - addStructure(t,HOUSE,xwasd,y,outside,inside); + addStructure(t,HOUSE,xwasd,y,outside); } } void World::addMob(int t,float x,float y){ @@ -958,6 +988,12 @@ void World::addParticle(float x, float y, float w, float h, float vx, float vy, particles.back()->canMove = true; } +void World::addLight(vec2 loc, Color color){ + light.push_back(Light()); + light.back().loc = loc; + light.back().color = color; +} + /*void World::removeObject(Object i){ object.delete[](i); }*/ @@ -1094,44 +1130,64 @@ void IndoorWorld::generate(unsigned int width){ // Generates a flat area of wid void IndoorWorld::draw(Player *p){ unsigned int i,ie; - int j,x,v_offset; + //int j,x,v_offset; + int x; /* * Draw the background. */ glEnable(GL_TEXTURE_2D); + glUseProgram(shaderProgram); + glUniform1i(glGetUniformLocation(shaderProgram, "sampler"), 0); + glUniform1f(glGetUniformLocation(shaderProgram, "amb"), 0.0f); + if(light.size() == 0){ + glUniform2f(glGetUniformLocation(shaderProgram, "lightLocation"), 0,-1000); + glUniform3f(glGetUniformLocation(shaderProgram, "lightColor"), 0.0f,0.0f,0.0f); + }else{ + for(auto &l : light){ + glUniform2f(glGetUniformLocation(shaderProgram, "lightLocation"), l.loc.x-offset.x,l.loc.y); + glUniform3f(glGetUniformLocation(shaderProgram, "lightColor"), l.color.red,l.color.green,l.color.blue); + } + } bgTex->bind(0); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); //for the s direction + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); //for the t direction glColor4ub(255,255,255,255); glBegin(GL_QUADS); - for(j = x_start - SCREEN_WIDTH / 2;j < -x_start + SCREEN_WIDTH / 2; j += 512){ - glTexCoord2i(1,1);glVertex2i(j ,0); - glTexCoord2i(0,1);glVertex2i(j+512,0); - glTexCoord2i(0,0);glVertex2i(j+512,512); - glTexCoord2i(1,0);glVertex2i(j ,512); - } + //for(j = x_start - SCREEN_WIDTH / 2;j < -x_start + SCREEN_WIDTH / 2; j += 512){ + glTexCoord2i(0,1); glVertex2i( x_start - SCREEN_WIDTH / 2,0); + glTexCoord2i((-x_start*2+SCREEN_WIDTH)/512,1);glVertex2i(-x_start + SCREEN_WIDTH / 2,0); + glTexCoord2i((-x_start*2+SCREEN_WIDTH)/512,0);glVertex2i(-x_start + SCREEN_WIDTH / 2,SCREEN_HEIGHT); + glTexCoord2i(0,0); glVertex2i( x_start - SCREEN_WIDTH / 2,SCREEN_HEIGHT); + //} glEnd(); + glUseProgram(0); glDisable(GL_TEXTURE_2D); /* * Calculate the starting and ending points to draw the ground from. */ - v_offset = (p->loc.x - x_start) / HLINE; + /*v_offset = (p->loc.x - x_start) / HLINE; j = v_offset - (SCREEN_WIDTH / 2 / HLINE) - GEN_INC; if(j < 0)j = 0; i = j; ie = v_offset + (SCREEN_WIDTH / 2 / HLINE) - GEN_INC; - if(ie > lineCount)ie = lineCount; + if(ie > lineCount)ie = lineCount;*/ + + i = 0; + ie = lineCount; /* * Draw the ground. */ - + glUseProgram(shaderProgram); + glUniform1i(glGetUniformLocation(shaderProgram, "sampler"), 0); glBegin(GL_QUADS); for(;i < ie - GEN_INC;i++){ safeSetColor(150,100,50); @@ -1143,6 +1199,7 @@ void IndoorWorld::draw(Player *p){ glVertex2i(x ,line[i].y - 50); } glEnd(); + glUseProgram(0); /* * Draw all entities. @@ -1,17 +1,23 @@ +uniform sampler2D sampler;
+
uniform vec2 lightLocation;
uniform vec3 lightColor;
-uniform float screenHeight;
+uniform float amb;
+// uniform float lightStrength;
+//uniform float screenHeight;
+void main() {
+ float lightAdd = 1.0f;
-float radius = 4.9;
-float minLight = .01;
-float a = .01;
-float b = 1.0 / (radius*radius * minLight);
+ float dist = length(lightLocation - gl_FragCoord.xy);
+ float attenuation=1.0/(1.0+0.01*dist+0.00000000001*dist*dist);
-void main() {
- float distance = length(lightLocation - gl_FragCoord.xy);
- //float attenuation = 1.0 / (1.0 + a*distance + b*distance*distance);
- float attenuation = clamp(1.0 - distance*distance/(radius*radius), 0.0, 1.0); attenuation *= attenuation;
- vec4 color = vec4(attenuation, attenuation, attenuation, attenuation) * vec4(lightColor, 1);
+ //vec4 color = vec4(1.0f,1.0f,1.0f,1.0f);
+ vec4 color = vec4(attenuation, attenuation, attenuation, 1.0f) * vec4(lightColor, 1.0f);
+ //color = color + vec4((vec3(lightColor.r + amb, lightColor.g + amb, lightColor.b + amb)*0.25f),1.0f);
+
+ vec2 coords = gl_TexCoord[0].st;
+ vec4 tex = texture2D(sampler, coords);
- gl_FragColor = color;
+ color += vec4(amb,amb,amb,1.0f+amb);
+ gl_FragColor = tex * vec4(color)*tex.a;
}
\ No newline at end of file diff --git a/xcf/bgWoodTile.xcf b/xcf/bgWoodTile.xcf Binary files differindex 9aa0005..867e556 100644 --- a/xcf/bgWoodTile.xcf +++ b/xcf/bgWoodTile.xcf diff --git a/xcf/maybeplayer.xcf b/xcf/maybeplayer.xcf Binary files differindex fb885fc..c16b7c6 100644 --- a/xcf/maybeplayer.xcf +++ b/xcf/maybeplayer.xcf |