From: drumsetmonkey Date: Mon, 11 Jan 2016 02:03:33 +0000 (-0500) Subject: Work on player texture X-Git-Url: https://code.bitgloo.com/?a=commitdiff_plain;h=75a5569ed0d44494da379822aa5de519e4a4025b;p=clyne%2Fgamedev.git Work on player texture --- 75a5569ed0d44494da379822aa5de519e4a4025b diff --cc src/entities.cpp index 3849040,57a20ef..2cb83a8 --- a/src/entities.cpp +++ b/src/entities.cpp @@@ -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(){ diff --cc src/gameplay.cpp index 5184136,6637d23..10de69d --- a/src/gameplay.cpp +++ b/src/gameplay.cpp @@@ -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 npcd; + std::vector earthxml; + std::vector 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 xmlFiles; + static char *file; + bool dialog; + XMLDocument xml; + XMLElement *wxml; + + if(getdir("./xml/",xmlFiles)){ + std::cout<<"Error reading XML files!!!1"<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 5663086,e97ec56..fea0e3e --- a/src/world.cpp +++ b/src/world.cpp @@@ -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 c30ef4d,3b11ebb..9bb5e3d --- a/test.frag +++ b/test.frag @@@ -1,4 -1,26 +1,27 @@@ - #version 120 ++#version 130 + uniform sampler2D sampler; + + uniform int numLight; + uniform vec2 lightLocation[10]; + uniform vec3 lightColor; + uniform float amb; + // uniform float lightStrength; + //uniform float screenHeight; void main(){ - gl_FragColor = vec4(1.0, 1.0, 1.0, 1.0); - } + vec4 color = vec4(0.0f,0.0f,0.0f,0.0f); + for(int i = 0; i < numLight; i++){ + vec2 loc = lightLocation[i]; + //if(loc.x == 0.0f) continue; + float dist = length(loc - gl_FragCoord.xy); + float attenuation=1.0/(1.0+0.01*dist+0.00000000001*dist*dist); + + //vec4 color = vec4(1.0f,1.0f,1.0f,1.0f); + 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); + + color += vec4(amb,amb,amb,1.0f+amb); + gl_FragColor = tex * vec4(color)*tex.a; + }