]> code.bitgloo.com Git - clyne/gamedev.git/commitdiff
Light posts
authordrumsetmonkey <abelleisle@roadrunner.com>
Tue, 12 Jan 2016 12:37:19 +0000 (07:37 -0500)
committerdrumsetmonkey <abelleisle@roadrunner.com>
Tue, 12 Jan 2016 12:37:19 +0000 (07:37 -0500)
assets/lampPost1.png [new file with mode: 0644]
assets/townhall.png [new file with mode: 0644]
include/entities.h
include/world.h
src/entities.cpp
src/ui.cpp
src/world.cpp
test.frag
xml/playerSpawnHill1.xml

diff --git a/assets/lampPost1.png b/assets/lampPost1.png
new file mode 100644 (file)
index 0000000..24f1807
Binary files /dev/null and b/assets/lampPost1.png differ
diff --git a/assets/townhall.png b/assets/townhall.png
new file mode 100644 (file)
index 0000000..7b510e8
Binary files /dev/null and b/assets/townhall.png differ
index f26863e9a9ed11ffc7840957fea16a3c4aea756a..d7ad2c0a16bc6a2ecc63033616fd98e300719551 100644 (file)
@@ -37,12 +37,13 @@ enum MOB_SUB {
 };
 
 enum BUILD_SUB{
-       TOWN_HALL = 1,
-       HOUSE,
-       HOUSE2,
-       HOUSE3,
-       HOUSE4,
-       FOUNTAIN
+       TOWN_HALL = 0,
+       HOUSE = 1,
+       HOUSE2 = 2,
+       HOUSE3 = 3,
+       HOUSE4 = 4,
+       FOUNTAIN = 5,
+       LAMP_POST = 6
 };
 
 typedef struct {
@@ -211,7 +212,7 @@ public:
        Structures();
        ~Structures();
        
-       unsigned int spawn(_TYPE, BUILD_SUB, float, float, World *);
+       unsigned int spawn(BUILD_SUB, float, float, World *);
        
        char *save(void);
        void load(char *s);
index 0e8546290af6fdf113eaa67dbb9a3272e1d6d049..7eb8c0289590d9964284321f6bf626d06306a4cc 100644 (file)
@@ -176,8 +176,8 @@ public:
        std::vector<Particles   *>      particles;
        std::vector<Light        >  light;
        
-       void addStructure(_TYPE t,BUILD_SUB sub,float x,float y,World *inside);
-       void addVillage(int bCount, int npcMin, int npcMax,_TYPE t,World *inside);
+       void addStructure(BUILD_SUB sub,float x,float y,World *inside);
+       void addVillage(int bCount, int npcMin, int npcMax,World *inside);
        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);
index 57a20ef823bd4d6963ba9265fc3855c905a0c31e..627946be0d74fa163085f5478e1d6dc84f81fd30 100644 (file)
@@ -13,6 +13,14 @@ extern Player *player;
 
 extern const char *itemName;
 
+std::string sTexLoc[] = {      "assets/townhall.png",
+                                                       "assets/house1.png", 
+                                                       "assets/house2.png", 
+                                                       "assets/house1.png", 
+                                                       "assets/house1.png", 
+                                                       "assets/fountain1.png",
+                                                       "assets/lampPost1.png"};
+
 void getRandomName(Entity *e){
        unsigned int tempNum,max=0;
        char *bufs;
@@ -119,9 +127,6 @@ Structures::Structures(){ //sets the structure type
        alive = false;
        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;
        
@@ -282,7 +287,7 @@ void Entity::draw(void){            //draws the entities
                        case MS_DOOR:
                        case MS_PAGE:
                        default:
-                               glActiveTexture(GL_TEXTURE0 + 0);
+                               glActiveTexture(GL_TEXTURE0);
                                tex->bind(0);
                                break;
                }
@@ -290,27 +295,25 @@ void Entity::draw(void){          //draws the entities
        case STRUCTURET:
                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);
+                               switch(strt->bsubtype){
+                                       /*case HOUSE:
+                                               glActiveTexture(GL_TEXTURE1);
+                                               ntex->bind(0);
+                                               //When rendering an objectwith this program.
+                                               glActiveTexture(GL_TEXTURE0);
+                                               tex->bind(0);
+                                               //glBindSampler(0, linearFiltering);
+                                               break;*/
+                                       default:
+                                               glActiveTexture(GL_TEXTURE0);
+                                               tex->bind(0);
+                                               break;
                                }
                        }
                } 
                break;
        default:
-               glActiveTexture(GL_TEXTURE0 + 0);
+               glActiveTexture(GL_TEXTURE0);
                tex->bind(0);
                break;
        }
@@ -442,16 +445,16 @@ 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, World *oi){
+unsigned int Structures::spawn(BUILD_SUB sub, float x, float y, World *oi){
        loc.x = x;
        loc.y = y;
-       type = t;
-       
+       type = STRUCTURET;
+
        alive = true;
 
-       width =  50 * HLINE;
-       height = 40 * HLINE;
        bsubtype = sub;
+       int s = -1;
+       s = sub;
 
        inWorld = oi;
 
@@ -459,20 +462,45 @@ unsigned int Structures::spawn(_TYPE t, BUILD_SUB sub, float x, float y, World *
         *      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.
        */
-       
+       /* tex = new Texturec(7,"assets/townhall.png",
+                                                       "assets/house1.png", 
+                                                       "assets/house2.png", 
+                                                       "assets/house1.png", 
+                                                       "assets/house1.png", 
+                                                       "assets/fountain1.png",
+                                                       "assets/lampPost1.png")*/;
+
        unsigned int tempN = (getRand() % 5 + 2);
-       
-       for(unsigned int i = 0;i < tempN;i++){
-               
-               /*
-                *      This is where the entities actually spawn. A new entity is created
-                *      with type NPC.
-               */
-               
-               inWorld->addNPC(loc.x + i * HLINE ,100);
-               
+       switch(s){
+               case HOUSE:
+                       tex = new Texturec(1, sTexLoc[s].c_str());
+                       width =  50 * HLINE;
+                       height = 40 * HLINE;
+                       for(unsigned int i = 0;i < tempN;i++){
+                       
+                               /*
+                                *      This is where the entities actually spawn. A new entity is created
+                                *      with type NPC.
+                               */
+                       
+                               oi->addNPC(loc.x + i * HLINE ,100);
+                       
+                       }
+                       break;
+               case FOUNTAIN:
+                       tex = new Texturec(1, sTexLoc[s].c_str());
+                       width =  50 * HLINE;
+                       height = 40 * HLINE;
+                       break;
+               case LAMP_POST:
+                       tex = new Texturec(1, sTexLoc[s].c_str());
+                       width =  10 * HLINE;
+                       height = 40 * HLINE;
+                       oi->addLight({x+SCREEN_WIDTH/2,y+30*HLINE},{1.0f,1.0f,1.0f});
+                       break;
+               default:
+                       break;
        }
-
        return 0;
 }
 
index 64ebe92062af0f3fc5a7db8ef7fc490e648d4d35..0d01033d0f6a2da55724c4ff6bb049a2146fe321 100644 (file)
@@ -822,6 +822,9 @@ DONE:
                                case SDLK_f:
                                        currentWorld->addLight({player->loc.x + SCREEN_WIDTH/2, player->loc.y},{1.0f,1.0f,1.0f});
                                        break;
+                               case SDLK_g:
+                                       currentWorld->addStructure(LAMP_POST, player->loc.x, player->loc.y, currentWorld);
+                                       break;
                                default:
                                        break;
                                }
index e66fb0d64c37bae4d2da6ace5cc9dd33d4abb16c..b06802c6b3683c2c43045c7a04f16de0bb1ac065 100644 (file)
@@ -1055,9 +1055,9 @@ LOOOOP:
                goto LOOOOP;
        }
 }
-void World::addStructure(_TYPE t,BUILD_SUB sub, float x,float y,World *inside){
+void World::addStructure(BUILD_SUB sub, float x,float y,World *inside){
        build.push_back(new Structures());
-       build.back()->spawn(t,sub,x,y,this);
+       build.back()->spawn(sub,x,y,this);
        build.back()->inWorld=this;
        build.back()->inside = (World *)inside;
        ((IndoorWorld *)inside)->outside = this;
@@ -1065,11 +1065,11 @@ void World::addStructure(_TYPE t,BUILD_SUB sub, float x,float y,World *inside){
        entity.push_back(build.back());
 }
        
-void World::addVillage(int bCount, int npcMin, int npcMax,_TYPE t,World *inside){
+void World::addVillage(int bCount, int npcMin, int npcMax,World *inside){
        std::cout << npcMin << ", " << npcMax << std::endl;
        //int xwasd;
        for(int i = 0; i < bCount; i++){
-               addStructure(t,HOUSE,x_start + (i * 300),100,inside);
+               addStructure(HOUSE,x_start + (i * 300),100,inside);
                /*std::cout<<"1\n";
                HERE:
                xwasd = (rand()%(int)x+1000*HLINE);
index 083fc0bc6b2b54010fb6a4df8dfa35a29fafd87a..80c741b8284633cb70f400631a1645f3be3ca578 100644 (file)
--- a/test.frag
+++ b/test.frag
@@ -1,17 +1,22 @@
-#version 130\r
+#version 120\r
 uniform sampler2D sampler;\r
 \r
 uniform int numLight;\r
-uniform vec2 lightLocation[255];\r
+uniform vec2 lightLocation[1024];\r
 uniform vec3 lightColor;\r
 uniform float amb;\r
 \r
+float b = .0005;\r
+float minLight = .05;\r
+float radius = sqrt(1.0 / (b * minLight));\r
+\r
 void main(){\r
        vec4 color = vec4(0.0f,0.0f,0.0f,0.0f);\r
        for(int i = 0; i < numLight; i++){\r
                vec2 loc = lightLocation[i];\r
                float dist = length(loc - gl_FragCoord.xy);\r
-               float attenuation=1.0/(1.0+0.01*dist+0.00000000001*dist*dist);\r
+               //float attenuation=1.0/(1.0+0.01*dist+0.00000000001*dist*dist);\r
+               float attenuation = clamp(1.0 - dist*dist/(radius*radius), 0.0, 1.0); attenuation *= attenuation;\r
 \r
                color += vec4(attenuation, attenuation, attenuation, 1.0f) * vec4(lightColor, 1.0f);\r
        }\r
@@ -20,4 +25,13 @@ void main(){
 \r
        color += vec4(amb,amb,amb,1.0f+amb);\r
        gl_FragColor = tex * vec4(color)*tex.a;\r
-}
\ No newline at end of file
+}\r
+\r
+/*b values\r
+       .002            10\r
+       .008            50\r
+       .0005           200\r
+       .00008          500\r
+       .00002          1000\r
+       .00005          2000\r
+*/
\ No newline at end of file
index 5a0e51f690d38621d1405581864b5710fc0913aa..60f7e7aacd986d940b3f3685a75fff04ac5e53d5 100644 (file)
@@ -7,6 +7,7 @@
        
        <npc name="Ralph" hasDialog="true" />
        <npc name="Johnny" hasDialog="true" />
+       <structure type="6"/>
 
 </World>