]> code.bitgloo.com Git - clyne/gamedev.git/commitdiff
Work on player texture
authordrumsetmonkey <abelleisle@roadrunner.com>
Mon, 11 Jan 2016 02:03:33 +0000 (21:03 -0500)
committerdrumsetmonkey <abelleisle@roadrunner.com>
Mon, 11 Jan 2016 02:03:33 +0000 (21:03 -0500)
1  2 
Changelog
include/common.h
src/entities.cpp
src/gameplay.cpp
src/world.cpp
test.frag

diff --cc Changelog
Simple merge
Simple merge
index 38490406f661afc7877679e007c30a6974369f5a,57a20ef823bd4d6963ba9265fc3855c905a0c31e..2cb83a880dd5e92bf7dad619cb9b6cd1be8ff724
@@@ -77,8 -77,8 +77,8 @@@ Player::Player(){ //sets all of the pla
        subtype = 0;    
        health = maxHealth = 100;
        speed = 1;
-       //tex = new Texturec(3, "assets/player1.png", "assets/player.png", "assets/player2.png");
-       tex = new Texturec(3, "assets/maybeplayer.png", "assets/maybeplayer.png", "assets/maybeplayer.png");
 -      tex = new Texturec(3, "assets/player1.png", "assets/player.png", "assets/player2.png");
++      tex = new Texturec(3, "assets/player1.png", "assets/playerk.png", "assets/player2.png");
+       //tex = new Texturec(3, "assets/maybeplayer.png", "assets/maybeplayer.png", "assets/maybeplayer.png");
        inv = new Inventory(PLAYER_INV_SIZE);
  }
  Player::~Player(){
index 518413626bb3515681b2a2b4265040780565213a,6637d239ce265ccda66504bbcff4ea8f324a8671..10de69da60be2c0156324d030ccb947ea62ceea6
@@@ -119,57 -27,125 +27,126 @@@ extern Player   *player
   *    initEverything() start
   */
  
- void destroyEverything(void);
- void initEverything(void){
-       worldSpawnHill1 = new World();
-       worldSpawnHill1->generateFunc(400,gen_worldSpawnHill1);
-       worldSpawnHill1->setBackground(BG_FOREST);
-       worldSpawnHill1->setBGM("assets/music/embark.wav");
-       worldSpawnHill1->addMob(MS_TRIGGER,0,0,worldSpawnHill1_hillBlock);
-       worldSpawnHill2 = new World();
-       worldSpawnHill2->generate(700);
-       worldSpawnHill2->setBackground(BG_FOREST);
-       worldSpawnHill2->setBGM("assets/music/ozone.wav");
-       worldSpawnHill2->addMob(MS_PAGE,-400,0,worldSpawnHill2_infoSprint);
-       worldSpawnHill3 = new World();
-       worldSpawnHill3->generateFunc(1000,gen_worldSpawnHill3);
-       worldSpawnHill3->setBackground(BG_FOREST);
-       worldSpawnHill3->setBGM("assets/music/embark.wav");
-       //worldSpawnHill3->addMob(MS_TRIGGER,-500,0,worldSpawnHill3_itemGet);
-       //worldSpawnHill3->addMob(MS_TRIGGER,0,0,worldSpawnHill3_itemSee);
-       worldSpawnHill3->addObject(FLASHLIGHT,false,"",-200,300);
-       //worldSpawnHill3->addMob(MS_TRIGGER,400,0,worldSpawnHill3_leave);
-       worldSpawnHill3->addHole(800,1000);
-       
-       worldSpawnHill1->toRight = worldSpawnHill2;
-       worldSpawnHill2->toLeft = worldSpawnHill1;
-       worldSpawnHill2->toRight = worldSpawnHill3;
-       worldSpawnHill3->toLeft = worldSpawnHill2;
-       /*
-        *      Spawn some entities.
-       */
-       //playerSpawnHill->addMob(MS_TRIGGER,player->loc.x,0,story);
+ typedef struct {
+       World *ptr;
+       char *file;
+ } WorldXML;
  
-       //playerSpawnHill->addStructure(STRUCTURET,FOUNTAIN,(rand()%120*HLINE)+100*HLINE,100,test,iw);
-       //playerSpawnHill->addStructure(STRUCTURET,HOUSE2,(rand()%120*HLINE)+300*HLINE,100,test,iw);
 +
-       //playerSpawnHill->addVillage(5,1,4,STRUCTURET,rand()%500+120,(float)200,playerSpawnHill,iw);
-       //playerSpawnHill->addMob(MS_TRIGGER,-1300,0,CUTSCENEEE);*/
+ typedef struct {
+       NPC *npc;
+       unsigned int index;
+ } NPCDialog;
  
+ std::vector<NPCDialog>        npcd;
+ std::vector<WorldXML> earthxml;
+ std::vector<World *>  earth;
  
-       worldSpawnHill2_Building1 = new IndoorWorld();
-       worldSpawnHill2_Building1->generate(300);
-       worldSpawnHill2_Building1->setBackground(BG_WOODHOUSE);
-       worldSpawnHill2_Building1->setBGM("assets/music/theme_jazz.wav");
+ int commonAIFunc(NPC *speaker){
+       XMLDocument xml;
+       XMLElement *exml;
+       unsigned int idx;
+       
+       for(auto &n : npcd){
+               if(n.npc == speaker){
+                       idx = n.index;
+                       break;
+               }
+       }
+       
+       for(auto &e : earthxml){
+               if(e.ptr == currentWorld){
+                       xml.LoadFile(e.file);
+                       exml = xml.FirstChildElement("Dialog")->FirstChildElement();
+                       
+                       do{
+                               if(!strcmp(exml->Name(),"text")){
+                                       if(!strcmp(exml->Attribute("name"),speaker->name) && exml->UnsignedAttribute("id") == idx){
+                                               ui::dialogBox(speaker->name,"",false,exml->GetText());
+                                               ui::waitForDialog();
+                                               if(exml->QueryUnsignedAttribute("nextid",&idx) == XML_NO_ERROR){
+                                                       for(auto &n : npcd){
+                                                               if(n.npc == speaker){
+                                                                       n.index = idx;
+                                                                       break;
+                                                               }
+                                                       }
+                                                       return 1;
+                                               }
+                                               return 0;
+                                       }
+                               }
+                               exml = exml->NextSiblingElement();
+                       }while(exml);
+               }
+       }
+       return 0;
+ }
  
-       worldSpawnHill2->addStructure(STRUCTURET,HOUSE,(rand()%120*HLINE),100,worldSpawnHill2_Building1);
-       worldSpawnHill2->getAvailableNPC()->addAIFunc(worldSpawnHill2_Quest1,false);
+ void destroyEverything(void);
+ void initEverything(void){
+       const char *name;
+       std::vector<std::string> xmlFiles;
+       static char *file;
+       bool dialog;
+       XMLDocument xml;
+       XMLElement *wxml;
+       
+       if(getdir("./xml/",xmlFiles)){
+               std::cout<<"Error reading XML files!!!1"<<std::endl;
+               abort();
+       }
+       
+       for(auto x : xmlFiles){
+               if(strncmp(x.c_str(),".",1) && strncmp(x.c_str(),"..",2)){
 -                      file = new char[4 + x.size()];
++                      file = new char[5 + x.size()];
+                       strncpy(file,"xml/",4);
+                       strcpy(file+4,x.c_str());
+                       xml.LoadFile(file);
+                       wxml = xml.FirstChildElement("World")->FirstChildElement();
+                       earth.push_back(new World());
+                       
+                       do{
+                               name = wxml->Name();
+                               
+                               if(!strcmp(name,"style")){
+                                       earth.back()->setBackground((WORLD_BG_TYPE)wxml->UnsignedAttribute("background"));
+                                       earth.back()->setBGM(wxml->Attribute("bgm"));
+                               }else if(!strcmp(name,"generation")){
+                                       if(!strcmp(wxml->Attribute("type"),"Random")){
+                                               earth.back()->generate(wxml->UnsignedAttribute("width"));
+                                       }
+                               }else if(!strcmp(name,"mob")){
+                                       earth.back()->addMob(wxml->UnsignedAttribute("type"),wxml->FloatAttribute("x"),wxml->FloatAttribute("y"));
+                               }else if(!strcmp(name,"npc")){
+                                       earth.back()->addNPC(wxml->FloatAttribute("x"),wxml->FloatAttribute("y"));
+                                       if(wxml->Attribute("name")){
+                                               delete[] earth.back()->npc.back()->name;
+                                               earth.back()->npc.back()->name = new char[strlen(wxml->Attribute("name"))+1];
+                                               strcpy(earth.back()->npc.back()->name,wxml->Attribute("name"));
+                                       }
+                                       dialog = false;
+                                       if(wxml->QueryBoolAttribute("hasDialog",&dialog) == XML_NO_ERROR && dialog){
+                                               for(auto &ex : earthxml){
+                                                       if(ex.ptr == earth.back())
+                                                               goto SKIP;
+                                               }
+                                               earthxml.push_back((WorldXML){earth.back(),new char[64]});
+                                               strcpy(earthxml.back().file,file);
+ SKIP:
+                                               earth.back()->npc.back()->addAIFunc(commonAIFunc,false);
+                                               npcd.push_back((NPCDialog){earth.back()->npc.back(),0});
+                                       }
+                               }
+                               
+                               wxml = wxml->NextSiblingElement();
+                       }while(wxml);
+                       
+                       delete[] file;
+               }
+       }
        
        player = new Player();
        player->spawn(200,100);
diff --cc src/world.cpp
index 5663086d868d64f500e8b77d2243f422570c0292,e97ec5635517e1543a0301dd5f655ff46b4e2f87..fea0e3e1e12fbd14d8ce92c4a8df6289447fa33b
@@@ -581,49 -717,64 +717,63 @@@ LOOP2
        */
        
        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);
++      glUseProgram(0);
+       glDisable(GL_TEXTURE_2D);
 -      //glUseProgram(0);
        /*
         *      Draw non-structure entities.
        */
diff --cc test.frag
index c30ef4d78504e6b986071f0ca6ea4726b0902840,3b11ebb9e49e593499e2fd6c265011a558550551..9bb5e3db8e0e3d87fba7e7cdd6a66dcc9029c257
+++ b/test.frag
@@@ -1,4 -1,26 +1,27 @@@
- #version 120\r
++#version 130\r
+ uniform sampler2D sampler;\r
\r
+ uniform int numLight;\r
+ uniform vec2 lightLocation[10];\r
+ uniform vec3 lightColor;\r
+ uniform float amb;\r
+ // uniform float lightStrength;\r
+ //uniform float screenHeight;\r
  void main(){\r
-       gl_FragColor = vec4(1.0, 1.0, 1.0, 1.0);\r
- }\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
+               //if(loc.x == 0.0f) continue;\r
+               float dist = length(loc - gl_FragCoord.xy);\r
+               float attenuation=1.0/(1.0+0.01*dist+0.00000000001*dist*dist);\r
\r
+               //vec4 color = vec4(1.0f,1.0f,1.0f,1.0f);\r
+               color += vec4(attenuation, attenuation, attenuation, 1.0f) * vec4(lightColor, 1.0f);\r
+               //color = color + vec4((vec3(lightColor.r + amb, lightColor.g + amb, lightColor.b + amb)*0.25f),1.0f);\r
+       }\r
+       vec2 coords = gl_TexCoord[0].st;\r
+       vec4 tex = texture2D(sampler, coords);\r
\r
+       color += vec4(amb,amb,amb,1.0f+amb);\r
+       gl_FragColor = tex * vec4(color)*tex.a;\r
+ }