diff options
-rw-r--r-- | Changelog | 9 | ||||
-rw-r--r-- | assets/style/classic/stallFruit.png | bin | 0 -> 641 bytes | |||
-rw-r--r-- | include/common.h | 25 | ||||
-rw-r--r-- | include/entities.h | 1 | ||||
-rw-r--r-- | include/inventory.h | 14 | ||||
-rw-r--r-- | include/ui.h | 6 | ||||
-rw-r--r-- | include/world.h | 1 | ||||
-rw-r--r-- | main.cpp | 15 | ||||
-rw-r--r-- | src/entities.cpp | 90 | ||||
-rw-r--r-- | src/gameplay.cpp | 122 | ||||
-rw-r--r-- | src/inventory.cpp | 292 | ||||
-rw-r--r-- | src/ui.cpp | 190 | ||||
-rw-r--r-- | src/world.cpp | 9 |
13 files changed, 518 insertions, 256 deletions
@@ -789,3 +789,12 @@ - (WIP) made ui options dynamic (boxes can have 'infinite' options) - can scroll through inventory with mouse wheel - added text transparency support + +3/18/2016: +========== + + - worked on keeping multiple-sizes fonts in memory (importantText lag) + - c++'d more ui stuff + - game can run on *BSD systems.. + - fixed abort bug on exit + - added light that follows player diff --git a/assets/style/classic/stallFruit.png b/assets/style/classic/stallFruit.png Binary files differnew file mode 100644 index 0000000..d9378d7 --- /dev/null +++ b/assets/style/classic/stallFruit.png diff --git a/include/common.h b/include/common.h index 58d561f..6f453b0 100644 --- a/include/common.h +++ b/include/common.h @@ -1,6 +1,6 @@ /** @file common.h * @brief Common items needed by most other files. - * + * * This file contains headers, variables and functions that are needed in * most other files included in this project. */ @@ -14,12 +14,13 @@ #include <string> #include <vector> #include <string> -#include <fstream> +#include <fstream> #include <thread> #include <mutex> #include <future> #include <math.h> #include <threadpool.h> +#include <algorithm> #define GLEW_STATIC #include <GL/glew.h> @@ -48,6 +49,17 @@ N abso(N v){ return v; } +template<class A> +float averagef(A v){ + float avg = 0; + for(auto &a : v){ + avg += a; + } + avg /= v.size(); + return avg; +} + + extern GLuint colorIndex; // Texture.cpp? /** @@ -130,7 +142,7 @@ extern std::mutex mtx; * definition was made. Every item being drawn to the screen and most object detection/physic * handling is done based off of this number. Increasing it will give the game a zoomed-in * feel, while decreasing it will do the opposite. - * + * */ extern unsigned int HLINE; @@ -159,7 +171,7 @@ extern float VOLUME_SFX; * Included in common.h is a prototype for DEBUG_prints, which writes a formatted * string to the console containing the callee's file and line number. This macro simplifies * it to a simple printf call. - * + * * DEBUG must be defined for this macro to function. */ @@ -181,7 +193,7 @@ extern unsigned int deltaTime; /** * References the variable in main.cpp, used for drawing with the player. */ - + extern vec2 offset; /** @@ -211,11 +223,12 @@ void safeSetColor(int r,int g,int b); void safeSetColorA(int r,int g,int b,int a); + /** * We've encountered many problems when attempting to create delays for triggering * the logic function. As a result, we decided on using the timing libraries given * by <chrono> in the standard C++ library. This function simply returns the amount - * of milliseconds that have passed sine the epoch. + * of milliseconds that have passed since the epoch. */ #ifdef __WIN32__ diff --git a/include/entities.h b/include/entities.h index ef421f5..450975f 100644 --- a/include/entities.h +++ b/include/entities.h @@ -219,6 +219,7 @@ public: class Merchant : public NPC{ public: std::vector<Trade>trade; + uint currTrade; void interact(); diff --git a/include/inventory.h b/include/inventory.h index 69cf073..7369642 100644 --- a/include/inventory.h +++ b/include/inventory.h @@ -11,11 +11,11 @@ class Item{ public: std::string name,type; - + float width; float height; int maxStackSize; - + std::string texloc; Texturec *tex; @@ -45,16 +45,18 @@ public: Inventory(unsigned int s); // Creates an inventory of size 's' ~Inventory(void); // Free's allocated memory - + int addItem(std::string name,uint count); int takeItem(std::string name,uint count); int hasItem(std::string name); - + int useItem(void); bool detectCollision(vec2,vec2); - + void setSelection(unsigned int s); - + void setSelectionUp(); + void setSelectionDown(); + void draw(void); // Draws a text list of items in this inventory (should only be called for the player for now) }; diff --git a/include/ui.h b/include/ui.h index 072d418..2a7518f 100644 --- a/include/ui.h +++ b/include/ui.h @@ -6,6 +6,7 @@ #define UI_H #include <common.h> +#include <inventory.h> #include <cstdarg> #include <config.h> @@ -106,11 +107,13 @@ namespace ui { extern bool posFlag; extern unsigned char dialogOptChosen; + extern unsigned char merchOptChosen; extern bool dialogBoxExists; extern bool dialogImportant; extern bool dialogPassive; extern unsigned int textWrapLimit; + extern int fontTransInv; /* * Initializes the FreeType system. @@ -126,6 +129,7 @@ namespace ui { void setFontFace(const char *ttf); void setFontSize(unsigned int size); + void setFontColor(unsigned char r,unsigned char g,unsigned char b, unsigned char a); /* * Draw a centered string. @@ -148,10 +152,10 @@ namespace ui { void dialogBox(const char *name,const char *opt,bool passive,const char *text,...); void merchantBox(const char *name,Trade trade,const char *opt,bool passive,const char *text,...); void merchantBox(); + void closeBox(); void waitForDialog(void); void drawPage( std::string path ); - /* * Draws a larger string in the center of the screen. Drawing is done inside this function. */ diff --git a/include/world.h b/include/world.h index 3a2d445..152d654 100644 --- a/include/world.h +++ b/include/world.h @@ -53,6 +53,7 @@ enum class WorldWeather : unsigned char { typedef struct { vec2 loc; /**< Light location */ Color color; /**< Light color */ + float radius; } Light; /** @@ -417,7 +417,6 @@ int main(int argc, char *argv[]){ //currentWorld->mob.back()->followee = player; gameRunning = true; - while ( gameRunning ) mainLoop(); @@ -494,6 +493,13 @@ void mainLoop(void){ prevPrevTime = currentTime; } + /* + * Update player and entity coordinates. + */ + + /*pool.Enqueue([](){ + currentWorld->update(player,deltaTime); + });*/ currentWorld->update( player, deltaTime ); /* @@ -772,9 +778,9 @@ void logic(){ if(n->canMove) n->wander((rand() % 120 + 30)); - /*if(!player->inv->usingi) n->hit = false; + if(!player->inv->usingi) n->hit = false; - if(player->inv->usingi && !n->hit && player->inv->detectCollision((vec2){n->loc.x, n->loc.y},(vec2){n->loc.x+n->width,n->loc.y+n->height})){ + if(player->inv->usingi && !n->hit && player->inv->detectCollision({n->loc.x, n->loc.y},{n->loc.x+n->width,n->loc.y+n->height})){ n->health -= 25; n->hit = true; for(int r = 0; r < (rand()%5);r++) @@ -783,8 +789,7 @@ void logic(){ for(int r = 0; r < (rand()%30)+15;r++) currentWorld->addParticle(rand()%HLINE*3 + n->loc.x - .05f,n->loc.y + n->height*.5, HLINE,HLINE, -(rand()%10)*.01,((rand()%10)*.01-.05), {(rand()%75)+10/100.0f,0,0}, 10000); } - }*/ - + } /* * Don't bother handling the NPC if another has already been handled. */ diff --git a/src/entities.cpp b/src/entities.cpp index 7d906ea..c047eff 100644 --- a/src/entities.cpp +++ b/src/entities.cpp @@ -169,6 +169,7 @@ Merchant::Merchant(){ //sets all of the Merchant specific traits on object creat canMove = true; trade.reserve(100); + currTrade = 0; //tex = new Texturec(1,"assets/NPC.png"); //inv = new Inventory(NPC_INV_SIZE); @@ -433,50 +434,68 @@ void NPC::clearAIFunc(void){ } void NPC::interact(){ //have the npc's interact back to the player - int (*func)(NPC *); - loc.y += 5; - - canMove=false; - left = (player->loc.x < loc.x); - right = !left; - - if(aiFunc.size()){ - func=aiFunc.front(); + std::thread([this]{ + int (*func)(NPC *); + loc.y += 5; + + canMove=false; + left = (player->loc.x < loc.x); + right = !left; - if(!func(this)){ - if(aiFunc.size())aiFunc.erase(aiFunc.begin()); + if(aiFunc.size()){ + func=aiFunc.front(); + + if(!func(this)){ + if(aiFunc.size())aiFunc.erase(aiFunc.begin()); + } + }else{ + ui::dialogBox(name,NULL,false,randomDialog[randDialog]); } - }else{ - ui::dialogBox(name,NULL,false,randomDialog[randDialog]); - } - ui::waitForDialog(); - canMove=true; + ui::waitForDialog(); + canMove=true; + }).detach(); } void Merchant::interact(){ - ui::merchantBox(name, trade.back(), ":Accept:Good-Bye", false, "Welcome to Smithy\'s. Buy your sausages here you freaking meme lording screw-face"); - ui::waitForDialog(); - if(ui::dialogOptChosen == 1){ - std::cout << "Gimme ye' munny" << std::endl; - if(player->inv->takeItem(trade.back().item[1],trade.back().quantity[1]) >= 0) - player->inv->addItem(trade.back().item[0],trade.back().quantity[0]); - }else{ - std::cout << "See ye!" << std::endl; - } + std::thread([this]{ + ui::merchantBox(name, trade[currTrade], ":Accept:Good-Bye", false, "Welcome to Smithy\'s. Buy your sausages here you freaking meme lording screw-face"); + ui::waitForDialog(); + if(ui::dialogOptChosen == 1){ + std::cout << "Gimme ye' munny" << std::endl; + if(!(player->inv->takeItem(trade[currTrade].item[1],trade[currTrade].quantity[1]))) + player->inv->addItem(trade[currTrade].item[0],trade[currTrade].quantity[0]); + }else if(ui::dialogOptChosen == 2){ + std::cout << "See ye!" << std::endl; + }else if(ui::merchOptChosen == 1){ + if(currTrade != 0){ + currTrade--; + std::cout << "Last trade" << std::endl; + interact(); + } + }else if(ui::merchOptChosen == 2){ + if(currTrade < trade.size()){ + currTrade++; + std::cout << "Next trade" << std::endl; + interact(); + } + } + }).detach(); } void Object::interact(void){ - if(questObject && alive){ - ui::dialogBox( player->name, ":Yes:No", false, pickupDialog.c_str()); - ui::waitForDialog(); - if(ui::dialogOptChosen == 1){ - player->inv->addItem( iname, 1 ); + std::thread([this]{ + if(questObject && alive){ + ui::dialogBox( player->name, ":Yes:No", false, pickupDialog.c_str()); + ui::waitForDialog(); + if(ui::dialogOptChosen == 1){ + player->inv->addItem( iname, 1 ); + alive = false; + } + }else{ alive = false; + player->inv->addItem(iname, 1); } - }else{ - alive = false; - player->inv->addItem(iname, 1); - } + }).detach(); } void Entity:: @@ -603,7 +622,8 @@ 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); + std::thread([this]{hey(this);}).detach(); + //hey(this); break; case MS_PAGE: if(player->loc.x > loc.x - 100 && diff --git a/src/gameplay.cpp b/src/gameplay.cpp index 7155678..075aec3 100644 --- a/src/gameplay.cpp +++ b/src/gameplay.cpp @@ -29,33 +29,33 @@ inline void segFault() { int commonAIFunc(NPC *speaker){ XMLDocument xml; XMLElement *exml,*oxml; - + static unsigned int oldidx = 9999; - + const char *name; unsigned int idx = 0; bool stop = false; - + /* * Load the current world's XML file into memory for reading. */ - + xml.LoadFile(currentXML.c_str()); exml = xml.FirstChildElement("Dialog"); - + /* * Search for the correct dialog block. */ - + while(strcmp(exml->Attribute("name"),speaker->name)) exml = exml->NextSiblingElement(); - + exml = exml->FirstChildElement(); - + /* * Search for which text block should be used. */ - + do{ if(!strcmp(exml->Name(),"text")){ if(exml->UnsignedAttribute("id") == (unsigned)speaker->dialogIndex){ @@ -63,10 +63,10 @@ int commonAIFunc(NPC *speaker){ /* * Handle any quest tags */ - + if((oxml = exml->FirstChildElement("quest"))){ std::string qname; - + while ( oxml ) { if ( !(qname = oxml->StrAttribute("assign")).empty() ) player->qh.assign(qname,"None",(std::string)oxml->GetText()); @@ -78,8 +78,8 @@ int commonAIFunc(NPC *speaker){ speaker->dialogIndex = oxml->UnsignedAttribute("fail"); return commonAIFunc(speaker); } - } - + } + oxml = oxml->NextSiblingElement(); } } @@ -89,68 +89,68 @@ CONT: /* * Handle any 'give' requests. */ - + if((oxml = exml->FirstChildElement("give"))){ while(oxml){ player->inv->addItem(oxml->Attribute("id"),oxml->UnsignedAttribute("count")); oxml = oxml->NextSiblingElement(); } } - + /* * Handle any 'take' requests. */ - + if((oxml = exml->FirstChildElement("take"))){ while(oxml){ player->inv->takeItem(oxml->Attribute("id"),oxml->UnsignedAttribute("count")); oxml = oxml->NextSiblingElement(); } } - + /* * Handle dialog options. */ - + if((oxml = exml->FirstChildElement("option"))){ - + /* * Convert the list of options into a single colon-separated string. */ - + std::string optstr; while(oxml){ - + /* * Create a buffer big enough for the next option. */ - + optstr.append((std::string)":" + oxml->Attribute("text")); - + /* * Append the next option. */ - + dopt.push_back(oxml); - + oxml = oxml->NextSiblingElement(); } - + /* * Get the player's choice, then set the XMLElement to the option's block. */ - + ui::dialogBox(speaker->name,optstr.c_str(),false,exml->GetText()+1); ui::waitForDialog(); - + if(ui::dialogOptChosen) exml = dopt[ui::dialogOptChosen-1]; - + while(!dopt.empty()) dopt.pop_back(); }else{ - + /* * No options - simply print the text. */ @@ -158,11 +158,11 @@ CONT: ui::dialogBox(speaker->name,NULL,false,exml->GetText()); ui::waitForDialog(); } - + /* * Give another NPC dialog if requested. */ - + if((name = exml->Attribute("call"))){ for(auto &n : currentWorld->npc){ if(!strcmp(n->name,name)){ @@ -173,14 +173,14 @@ CONT: } } } - + /* * Handle the next dialog block if this one leads to another. */ - + if(exml->QueryUnsignedAttribute("nextid",&idx) == XML_NO_ERROR){ speaker->dialogIndex = idx; - + if(exml->QueryBoolAttribute("stop",&stop) == XML_NO_ERROR && stop){ speaker->dialogIndex = 9999; return 0; @@ -201,11 +201,11 @@ CONT: //return 1; } } - + exml = exml->NextSiblingElement(); - + }while(exml); - + return 0; } @@ -228,37 +228,37 @@ void commonTriggerFunc(Mob *callee){ static bool lock = false; XMLDocument xml; XMLElement *exml; - - char *text,*pch; + + char *text,*pch; if(!lock){ lock = true; - + xml.LoadFile(currentXML.c_str()); exml = xml.FirstChildElement("Trigger"); - + while(strcmp(exml->Attribute("id"),callee->heyid.c_str())) exml = exml->NextSiblingElement(); - + player->vel.x = 0; ui::toggleBlackFast(); ui::waitForCover(); - + text = new char[256]; strcpy(text,exml->GetText()); pch = strtok(text,"\n"); - + while(pch){ ui::importantText(pch); ui::waitForDialog(); - + pch = strtok(NULL,"\n"); } - + delete[] text; - + ui::toggleBlackFast(); - + callee->alive = false; lock = false; } @@ -267,38 +267,38 @@ void commonTriggerFunc(Mob *callee){ void initEverything(void){ std::vector<std::string> xmlFiles; XMLDocument xml; - + /* * Read the XML directory into an array. */ - + if(getdir("./xml/",xmlFiles)){ std::cout<<"Error reading XML files!!!1"<<std::endl; abort(); } - + /* * Sort the files alphabetically. */ - + strVectorSortAlpha(&xmlFiles); - + /* * Load the first file found as currentWorld. */ - + for(unsigned int i=0;i<xmlFiles.size();i++){ if(xmlFiles[i] != "." && xmlFiles[i] != ".." && strcmp(xmlFiles[i].c_str()+xmlFiles[i].size()-3,"dat")){ - + /* * Read in the XML file. */ - + currentWorld = loadWorldFromXML(xmlFiles[i]); break; } } - + pauseMenu.items.push_back(ui::createParentButton({-256/2,0},{256,75},{0.0f,0.0f,0.0f}, "Resume")); pauseMenu.items.push_back(ui::createChildButton({-256/2,-100},{256,75},{0.0f,0.0f,0.0f}, "Options")); pauseMenu.items.push_back(ui::createButton({-256/2,-200},{256,75},{0.0f,0.0f,0.0f}, "Save and Quit", ui::quitGame)); @@ -313,7 +313,7 @@ void initEverything(void){ optionsMenu.child = NULL; optionsMenu.parent = &pauseMenu; // optionsMenu.push_back(ui::createButton({-256/2,-200},{256,75},{0.0f,0.0f,0.0f}, (const char*)("Save and Quit"), ); - + /* * Spawn the player and begin the game. */ @@ -327,9 +327,9 @@ void initEverything(void){ void destroyEverything(void){ currentWorld->save(); - delete currentWorld; + //delete currentWorld; //delete[] currentXML; - + while(!AIpreload.empty()) AIpreload.pop_back(); while(!AIpreaddr.empty()) diff --git a/src/inventory.cpp b/src/inventory.cpp index 795fb55..7ba5909 100644 --- a/src/inventory.cpp +++ b/src/inventory.cpp @@ -11,6 +11,7 @@ static float hangle = 0.0f; static bool swing = false; //static float xc,yc; static vec2 itemLoc; +static const unsigned char numSlot = 7; Mix_Chunk* swordSwing; static std::vector<Item *> itemMap; @@ -23,18 +24,18 @@ void items(void){ xml.LoadFile("config/items.xml"); exml = xml.FirstChildElement("item"); while(exml){ - + itemMap.push_back(new Item()); itemMap.back()->width = exml->FloatAttribute("width") * HLINE; itemMap.back()->height = exml->FloatAttribute("height") * HLINE; itemMap.back()->maxStackSize = exml->UnsignedAttribute("maxstack"); - + itemMap.back()->name = exml->Attribute("name"); itemMap.back()->type = exml->Attribute("type"); itemMap.back()->texloc = exml->Attribute("sprite"); exml = exml->NextSiblingElement(); - } + } } int Inventory::addItem(std::string name,uint count){ @@ -55,25 +56,25 @@ int Inventory::addItem(std::string name,uint count){ int Inventory::takeItem(std::string name,uint count){ unsigned int id = 999999; - + /* * Name to ID lookup */ - + for(unsigned int i=0;i<itemMap.size();i++){ if(itemMap[i]->name == name){ id = i; break; } } - + if(id == 999999) return -1; //if no such item exists - + /* * Inventory lookup */ - + for(unsigned int i=0;i<items.size();i++){ if(items[i].id == id){ if(count > items[i].count) @@ -98,7 +99,7 @@ int Inventory::hasItem(std::string name){ break; } } - + if(id == 999999) return 0; @@ -106,15 +107,15 @@ int Inventory::hasItem(std::string name){ if(i.id == id) return i.count; } - + return 0; } void initInventorySprites(void){ - + items(); itemtex = new GLuint[itemMap.size()]; - + for(unsigned int i = 0;i<itemMap.size();i++){ itemtex[i] = Texture::loadTexture(getItemTexturePath(itemMap[i]->name)); } @@ -124,12 +125,12 @@ void initInventorySprites(void){ } void destroyInventory(void){ - + while(!itemMap.empty()){ delete itemMap.front(); itemMap.erase(itemMap.begin()); } - + Mix_FreeChunk(swordSwing); } @@ -178,27 +179,71 @@ void Inventory::setSelection(unsigned int s){ sel=s; } +void Inventory::setSelectionUp(){ + if(!sel--)sel++; +} + +void Inventory::setSelectionDown(){ + sel++; + if(sel>=numSlot)sel=numSlot-1; +} + void Inventory::draw(void){ static unsigned int lop = 0; - const unsigned int numSlot = 7; + //const unsigned int numSlot = 7; static std::vector<int>dfp(numSlot); static std::vector<Ray>iray(numSlot); static std::vector<vec2>curCoord(numSlot); static int range = 200; + + static std::vector<int>curdfp(4); + static std::vector<Ray>curRay(4); + static std::vector<vec2>curCurCoord(4); + static int curRange = 100; + + static std::vector<int>massDfp(32); + static std::vector<vec2>massRay(32); + static std::vector<int>massOrder = {9,10,11,12,13,14,22,21,20,19,18,17,16,8,0,1,2,3,4,5,6,7,15,23,31,30,29,28,27,26,25,24}; + static std::vector<int>massOrderClosing = {31,30,23,29,22,15,28,21,14,7,27,20,13,6,26,19,12,5,25,18,11,4,24,17,10,3,16,9,2,8,1,0}; + static int massRange = 200; + static int itemWide = 45; float angleB = (float)180/(float)numSlot; float angle = float(angleB/2.0f); unsigned int a = 0; - unsigned int end = 0; + static bool end = false; static vec2 mouseStart = {0,0}; - + for(auto &r : iray){ r.start.x = player->loc.x + (player->width/2); r.start.y = player->loc.y + (player->height/2); curCoord[a++] = r.start; }a=0; - - if(invOpening){ + + for(auto &cr : curRay){ + cr.start.x = (offset.x + SCREEN_WIDTH/2); + cr.start.y = offset.y - (a*itemWide*1.5); + curCurCoord[a++] = cr.start; + }a=0; + + for(int r = 0; r < 4; r++){ + for(int c = 0; c < 8; c++){ + //std::cout << a << ","; + massRay[a].x = ((offset.x - SCREEN_WIDTH/2) + itemWide) + c*itemWide*1.5; + massRay[a++].y = ((offset.y + SCREEN_HEIGHT/2) - itemWide*1.5) - r*itemWide*1.5; + //std::cout << massRay[a-1].x << "," << massRay[a-1].y << " " << std::endl; + } + //std::cout << std::endl; + }a=0; + //std::cout << std::endl; + + ui::fontTransInv = 255*(averagef(dfp)/range); + if(ui::fontTransInv > 255) + ui::fontTransInv = 255; + if(ui::fontTransInv < 0) + ui::fontTransInv = 0; + + if(invOpening){ for(auto &d : dfp){ if(!a || dfp[a - 1] > 50) d += 1.65 * deltaTime; @@ -206,24 +251,87 @@ void Inventory::draw(void){ d = range; a++; }a=0; - + for(auto &cd : curdfp){ + if(!a || curdfp[a-1] > 90) + cd += 1.5 * deltaTime; + if(cd >= curRange) + cd = curRange; + a++; + }a=0; + for(uint i = 0; i < massOrder.size();i++){ + if(!a || massDfp[massOrder[a-1]] > massRange*.75) + massDfp[massOrder[a]] += 5.00 * deltaTime; + if(massDfp[massOrder[a]] >= massRange) + massDfp[massOrder[a]] = massRange; + a++; + }a=0; + if(numSlot > 0)invOpen=true; }else{ for(auto &d : dfp){ if(d > 0){ d -= 1.65 * deltaTime; - }else end++; + } } - if(end >= numSlot) + for(auto &cd : curdfp){ + if(cd > 0){ + cd -= 1.0 * deltaTime; + } + } + + for(uint i = 0; i < massRay.size();i++){ + if(!a || massDfp[massOrderClosing[a-1]] <= 0) + massDfp[massOrderClosing[a]] -= 10.0f * deltaTime; + if(massDfp[massOrderClosing[a-1]] <= 0){ + massDfp[massOrderClosing[a-1]] = 0; + } + a++; + }a=0; + end = std::all_of(std::begin(massDfp),std::end(massDfp),[](auto d){return d <= 0;}); + + if(end){ invOpen = false; + for(auto &md : massDfp){ + if(md < 0){ + md = 0; + } + } + } + } - + /* * a = 0 */ - + if(invOpen){ - + + for(auto &mr : massRay){ + glColor4f(0.0f,0.0f,0.0f, ((float)massDfp[a]/(float)massRange)*.5f); + glBegin(GL_QUADS); + glVertex2i(mr.x-(itemWide/2), mr.y-(itemWide/2)); + glVertex2i(mr.x-(itemWide/2)+itemWide,mr.y-(itemWide/2)); + glVertex2i(mr.x-(itemWide/2)+itemWide,mr.y-(itemWide/2)+itemWide); + glVertex2i(mr.x-(itemWide/2), mr.y-(itemWide/2)+itemWide); + glEnd(); + a++; + }a=0; + + for(auto &cr : curRay){ + curCurCoord[a].x -= float((curdfp[a]) * cos(-1)); + curCurCoord[a].y += float((curdfp[a]) * sin(0)); + cr.end = curCurCoord[a]; + + glColor4f(0.0f, 0.0f, 0.0f, ((float)curdfp[a]/(float)(curRange?curRange:1))*0.5f); + glBegin(GL_QUADS); + glVertex2i(cr.end.x-(itemWide/2), cr.end.y-(itemWide/2)); + glVertex2i(cr.end.x-(itemWide/2)+itemWide,cr.end.y-(itemWide/2)); + glVertex2i(cr.end.x-(itemWide/2)+itemWide,cr.end.y-(itemWide/2)+itemWide); + glVertex2i(cr.end.x-(itemWide/2), cr.end.y-(itemWide/2)+itemWide); + glEnd(); + a++; + }a=0; + for(auto &r : iray){ angle = 180 - (angleB * a) - angleB / 2.0f; curCoord[a].x += float((dfp[a]) * cos(angle*PI/180)); @@ -260,16 +368,47 @@ void Inventory::draw(void){ ui::putText(r.end.x-(itemWide/2)+(itemWide*.85),r.end.y-(itemWide/2),"%d",items[a].count); } - a++; - - if(sel == a - 1){ - glBegin(GL_LINES); - glColor4f(1.0f, 0.0f, 0.0f, 0.0f); - glVertex2i(r.start.x,r.start.y); - glColor4f(1.0f, 0.0f, 0.0f, 0.8f); - glVertex2i(r.end.x+20, r.end.y-20); + if(sel == a){ + static float sc = 1; + static bool up; + up ? sc += .01 : sc -= .01; + if(sc > 1.2){ + up = false; + sc = 1.2; + } + if(sc < 1.0){ + up = true; + sc = 1.0; + } + glPushMatrix(); + glLoadIdentity(); + //glTranslatef(-sc, -sc, 0); + //glScalef(sc,sc,0.0f); + glBegin(GL_QUADS); + glColor4f(1.0f, 1.0f, 1.0f, ((float)dfp[a]/(float)(range?range:1))); + glVertex2f(r.end.x - (itemWide*sc)/2 - (itemWide*sc)*.09,r.end.y - (itemWide*sc)/2 - (itemWide*sc)*.09); + glVertex2f(r.end.x + (itemWide*sc)/2 + (itemWide*sc)*.09,r.end.y - (itemWide*sc)/2 - (itemWide*sc)*.09); + glVertex2f(r.end.x + (itemWide*sc)/2 + (itemWide*sc)*.09,r.end.y - (itemWide*sc)/2); + glVertex2f(r.end.x - (itemWide*sc)/2 - (itemWide*sc)*.09,r.end.y - (itemWide*sc)/2); + + glVertex2f(r.end.x - (itemWide*sc)/2 - (itemWide*sc)*.09,r.end.y + (itemWide*sc)/2 + (itemWide*sc)*.09); + glVertex2f(r.end.x + (itemWide*sc)/2 + (itemWide*sc)*.09,r.end.y + (itemWide*sc)/2 + (itemWide*sc)*.09); + glVertex2f(r.end.x + (itemWide*sc)/2 + (itemWide*sc)*.09,r.end.y + (itemWide*sc)/2); + glVertex2f(r.end.x - (itemWide*sc)/2 - (itemWide*sc)*.09,r.end.y + (itemWide*sc)/2); + + glVertex2f(r.end.x - (itemWide*sc)/2 - (itemWide*sc)*.09,r.end.y - (itemWide*sc)/2 - (itemWide*sc)*.09); + glVertex2f(r.end.x - (itemWide*sc)/2 ,r.end.y - (itemWide*sc)/2 - (itemWide*sc)*.09); + glVertex2f(r.end.x - (itemWide*sc)/2 ,r.end.y + (itemWide*sc)/2 + (itemWide*sc)*.09); + glVertex2f(r.end.x - (itemWide*sc)/2 - (itemWide*sc)*.09,r.end.y + (itemWide*sc)/2 + (itemWide*sc)*.09); + + glVertex2f(r.end.x + (itemWide*sc)/2 ,r.end.y - (itemWide*sc)/2 - (itemWide*sc)*.09); + glVertex2f(r.end.x + (itemWide*sc)/2 + (itemWide*sc)*.09,r.end.y - (itemWide*sc)/2 - (itemWide*sc)*.09); + glVertex2f(r.end.x + (itemWide*sc)/2 + (itemWide*sc)*.09,r.end.y + (itemWide*sc)/2 + (itemWide*sc)*.09); + glVertex2f(r.end.x + (itemWide*sc)/2 ,r.end.y + (itemWide*sc)/2 + (itemWide*sc)*.09); glEnd(); + glPopMatrix(); } + a++; } }else if(invHover){ static unsigned int highlight = 0; @@ -279,14 +418,23 @@ void Inventory::draw(void){ if(!mouseSel){ mouseStart.x = ui::mouse.x - offset.x; + std::cout << "Setting highlight" << std::endl; highlight = sel; + std::cout << "Setting thing" << std::endl; thing = sel; + std::cout << "Setting mouseSel" << std::endl; mouseSel=true; + std::cout << "Done" << std::endl; }else{ + std::cout << "Is mousex greater than the start" << std::endl; if((ui::mouse.x - offset.x) >= mouseStart.x){ + std::cout << "Thing" << std::endl; thing = (ui::mouse.x - offset.x - mouseStart.x)/80; + std::cout << "Highlight" << std::endl; highlight=sel+thing; + std::cout << "Highlight Check" << std::endl; if(highlight>numSlot-1)highlight=numSlot-1; + std::cout << "Left Click" << std::endl; if(SDL_GetMouseState(NULL, NULL) & SDL_BUTTON(SDL_BUTTON_LEFT)){ sel = highlight; mouseSel=false; @@ -297,7 +445,7 @@ void Inventory::draw(void){ if((ui::mouse.x - offset.x) < mouseStart.x){ thing = (mouseStart.x - (ui::mouse.x - offset.x))/80; if((int)sel-(int)thing<0)highlight=0; - else highlight=sel-thing; + else highlight=sel-thing; if(SDL_GetMouseState(NULL, NULL) & SDL_BUTTON(SDL_BUTTON_LEFT)){ sel = highlight; mouseSel=false; @@ -306,12 +454,17 @@ void Inventory::draw(void){ } } } + std::cout << "Rays" << std::endl; for(auto &r : iray){ + std::cout << "Setting angle" << std::endl; angle=180-(angleB*a) - angleB/2.0f; + std::cout << "Currcourd" << std::endl; curCoord[a].x += float(range) * cos(angle*PI/180); curCoord[a].y += float(range) * sin(angle*PI/180); + std::cout << "Ray.end" << std::endl; r.end = curCoord[a]; + std::cout << "Draw" << std::endl; glColor4f(0.0f, 0.0f, 0.0f, a == highlight ? 0.5f : 0.1f); glBegin(GL_QUADS); glVertex2i(r.end.x-(itemWide/2), r.end.y-(itemWide/2)); @@ -320,29 +473,36 @@ void Inventory::draw(void){ glVertex2i(r.end.x-(itemWide/2), r.end.y+(itemWide/2)); glEnd(); - glEnable(GL_TEXTURE_2D); - glBindTexture(GL_TEXTURE_2D, itemtex[items[a].id]); - glColor4f(1.0f, 1.0f, 1.0f, a == highlight ? 0.8f : 0.2f); - glBegin(GL_QUADS); - if(itemMap[items[a].id]->height > itemMap[items[a].id]->width){ - glTexCoord2i(0,1);glVertex2i(r.end.x-((itemWide/2)*((float)itemMap[items[a].id]->width/(float)itemMap[items[a].id]->height)),r.end.y-(itemWide/2)); - glTexCoord2i(1,1);glVertex2i(r.end.x+((itemWide/2)*((float)itemMap[items[a].id]->width/(float)itemMap[items[a].id]->height)),r.end.y-(itemWide/2)); - glTexCoord2i(1,0);glVertex2i(r.end.x+((itemWide/2)*((float)itemMap[items[a].id]->width/(float)itemMap[items[a].id]->height)),r.end.y+(itemWide/2)); - glTexCoord2i(0,0);glVertex2i(r.end.x-((itemWide/2)*((float)itemMap[items[a].id]->width/(float)itemMap[items[a].id]->height)),r.end.y+(itemWide/2)); - }else{ - glTexCoord2i(0,1);glVertex2i(r.end.x-(itemWide/2),r.end.y-(itemWide/2)*((float)itemMap[items[a].id]->height/(float)itemMap[items[a].id]->width)); - glTexCoord2i(1,1);glVertex2i(r.end.x+(itemWide/2),r.end.y-(itemWide/2)*((float)itemMap[items[a].id]->height/(float)itemMap[items[a].id]->width)); - glTexCoord2i(1,0);glVertex2i(r.end.x+(itemWide/2),r.end.y+(itemWide/2)*((float)itemMap[items[a].id]->height/(float)itemMap[items[a].id]->width)); - glTexCoord2i(0,0);glVertex2i(r.end.x-(itemWide/2),r.end.y+(itemWide/2)*((float)itemMap[items[a].id]->height/(float)itemMap[items[a].id]->width)); - } - glEnd(); - glDisable(GL_TEXTURE_2D); - - a++; + std::cout << "Draw items" << std::endl; + if(!items.empty() && a < items.size() && items[a].count){ + std::cout << "Jamie" << std::endl; + glEnable(GL_TEXTURE_2D); + glBindTexture(GL_TEXTURE_2D, itemtex[items[a].id]); + glColor4f(1.0f, 1.0f, 1.0f, a == highlight ? 0.8f : 0.2f); + std::cout << "Done Binding" << std::endl; + glBegin(GL_QUADS); + std::cout << "jdjdjd" << std::endl; + if(itemMap[items[a].id]->height > itemMap[items[a].id]->width){ + std::cout << "map" << std::endl; + glTexCoord2i(0,1);glVertex2i(r.end.x-((itemWide/2)*((float)itemMap[items[a].id]->width/(float)itemMap[items[a].id]->height)),r.end.y-(itemWide/2)); + glTexCoord2i(1,1);glVertex2i(r.end.x+((itemWide/2)*((float)itemMap[items[a].id]->width/(float)itemMap[items[a].id]->height)),r.end.y-(itemWide/2)); + glTexCoord2i(1,0);glVertex2i(r.end.x+((itemWide/2)*((float)itemMap[items[a].id]->width/(float)itemMap[items[a].id]->height)),r.end.y+(itemWide/2)); + glTexCoord2i(0,0);glVertex2i(r.end.x-((itemWide/2)*((float)itemMap[items[a].id]->width/(float)itemMap[items[a].id]->height)),r.end.y+(itemWide/2)); + }else{ + glTexCoord2i(0,1);glVertex2i(r.end.x-(itemWide/2),r.end.y-(itemWide/2)*((float)itemMap[items[a].id]->height/(float)itemMap[items[a].id]->width)); + glTexCoord2i(1,1);glVertex2i(r.end.x+(itemWide/2),r.end.y-(itemWide/2)*((float)itemMap[items[a].id]->height/(float)itemMap[items[a].id]->width)); + glTexCoord2i(1,0);glVertex2i(r.end.x+(itemWide/2),r.end.y+(itemWide/2)*((float)itemMap[items[a].id]->height/(float)itemMap[items[a].id]->width)); + glTexCoord2i(0,0);glVertex2i(r.end.x-(itemWide/2),r.end.y+(itemWide/2)*((float)itemMap[items[a].id]->height/(float)itemMap[items[a].id]->width)); + } + glEnd(); + glDisable(GL_TEXTURE_2D); + std::cout << "Adding a" << std::endl; + a++; + } } ui::putStringCentered(player->loc.x+player->width/2, player->loc.y + range*.75,itemMap[items[highlight].id]->name.c_str()); } - + if(!items.empty() && items.size() > sel && items[sel].count) itemDraw(player,items[sel].id); lop++; @@ -352,9 +512,9 @@ void itemDraw(Player *p,uint id){ itemLoc.y = p->loc.y+(p->height/3); itemLoc.x = p->left?p->loc.x:p->loc.x+p->width; glPushMatrix(); - + if(!id)return; - + if(itemMap[id]->type == "Sword"){ if(p->left){ if(hangle < 15){ @@ -368,7 +528,7 @@ void itemDraw(Player *p,uint id){ } } }else hangle = 0.0f; - + glUseProgram(shaderProgram); glUniform1i(glGetUniformLocation(shaderProgram, "sampler"), 0); glTranslatef(itemLoc.x,itemLoc.y,0); @@ -392,9 +552,9 @@ void itemDraw(Player *p,uint id){ int Inventory::useItem(void){ static bool up = false; if(!invHover){ - + if(itemMap[items[sel].id]->type == "Sword"){ - + if(swing){ if(!player->left){ if(hangle==-15){up=true;Mix_PlayChannel(2,swordSwing,0);} @@ -417,9 +577,10 @@ int Inventory::useItem(void){ bool Inventory::detectCollision(vec2 one, vec2 two){ (void)one; (void)two; - //float i = 0.0f; - - /*if(items.empty() || !items[sel].count) + float xc, yc; + float i = 0.0f; + + if(items.empty() || !items[sel].count) return false; if(itemMap[items[sel].id]->type == "Sword"){ std::cout<<"Collision???"<<std::endl; @@ -428,11 +589,11 @@ bool Inventory::detectCollision(vec2 one, vec2 two){ xc += float(i) * cos((hangle+90)*PI/180); yc += float(i) * sin((hangle+90)*PI/180); - *glColor4f(1.0f,1.0f,1.0f,1.0f); + /*glColor4f(1.0f,1.0f,1.0f,1.0f); glBegin(GL_LINES); glVertex2f(player->loc.x,player->loc.y+player->height/3); glVertex2f(xc,yc); - glEnd();* + glEnd();*/ if(xc >= one.x && xc <= two.x){ if(yc >= one.y && yc <= two.y){ @@ -442,7 +603,6 @@ bool Inventory::detectCollision(vec2 one, vec2 two){ i+=HLINE; } - }*/ + } return false; } - @@ -38,10 +38,6 @@ extern unsigned int tickCount; static FT_Library ftl; static FT_Face ftf; -static GLuint ftex[93]; -/*static vec2 ftexwh[93]; -static vec2 ftexbl[93]; -static vec2 ftexad[93];*/ typedef struct { vec2 wh; @@ -49,19 +45,19 @@ typedef struct { vec2 ad; } FT_Info; -static FT_Info ftdat[93]; +static std::vector<FT_Info> ftdat ( 93, { { 0, 0 }, { 0, 0 }, { 0, 0 } } ); +static std::vector<GLuint> ftex ( 93, 0 ); -static unsigned char fontColor[3] = {255,255,255}; +static unsigned char fontColor[4] = {255,255,255,255}; /* * Variables for dialog boxes / options. -*/ + */ -static std::string dialogBoxText; static std::vector<std::pair<std::string,vec3>> dialogOptText; -static float merchAOptLoc[2][3]; -static float dialogOptLoc[4][3]; -static bool typeOutDone = true; +static std::string dialogBoxText; +static vec3 merchArrowLoc[2]; +static bool typeOutDone = true; /* * Menu-related objects @@ -76,12 +72,12 @@ static Mix_Chunk *dialogClick; extern void mainLoop(void); /* - * Toggled by pressing 'q', disables some controls when true. -*/ + * Fade effect flags + */ bool fadeEnable = false; -bool fadeWhite = false; -bool fadeFast = false; +bool fadeWhite = false; +bool fadeFast = false; unsigned int fadeIntensity = 0; bool inBattle = false; @@ -133,6 +129,7 @@ namespace ui { int dialogPassiveTime = 0; Trade merchTrade; + int fontTransInv = 255; /* * Dialog stuff that needs to be 'public'. @@ -161,8 +158,7 @@ namespace ui { std::cout<<"Error! Couldn't initialize freetype."<<std::endl; abort(); } - fontSize=0; - memset(&ftex,0,93*sizeof(GLuint)); + fontSize = 0; #ifdef DEBUG DEBUG_printf("Initialized FreeType2.\n",NULL); #endif // DEBUG @@ -200,6 +196,7 @@ namespace ui { */ void setFontSize(unsigned int size){ + mtx.lock(); unsigned int i,j; fontSize=size; @@ -209,8 +206,8 @@ namespace ui { * Pre-render 'all' the characters. */ - glDeleteTextures(93,ftex); // delete[] any already-rendered textures - glGenTextures(93,ftex); // Generate new texture name/locations? + glDeleteTextures(93,ftex.data()); // delete[] any already-rendered textures + glGenTextures(93,ftex.data()); // Generate new texture name/locations? for(i=33;i<126;i++){ @@ -255,6 +252,7 @@ namespace ui { glTexImage2D(GL_TEXTURE_2D,0,GL_RGBA,ftf->glyph->bitmap.width,ftf->glyph->bitmap.rows,0,GL_RGBA,GL_UNSIGNED_BYTE,buf.data()); } + mtx.unlock(); } /* @@ -265,6 +263,14 @@ namespace ui { fontColor[0]=r; fontColor[1]=g; fontColor[2]=b; + fontColor[3]=255; + } + + void setFontColor(unsigned char r,unsigned char g,unsigned char b, unsigned char a){ + fontColor[0]=r; + fontColor[1]=g; + fontColor[2]=b; + fontColor[3]=a; } /* @@ -293,7 +299,7 @@ namespace ui { glPushMatrix(); glTranslatef(0,-c2.y,0); glBegin(GL_QUADS); - glColor3ub(fontColor[0],fontColor[1],fontColor[2]); + glColor4ub(fontColor[0],fontColor[1],fontColor[2],fontColor[3]); glTexCoord2f(0,1);glVertex2f(c1.x ,c1.y ); glTexCoord2f(1,1);glVertex2f(c1.x+c2.x,c1.y ); glTexCoord2f(1,0);glVertex2f(c1.x+c2.x,c1.y+c2.y); @@ -318,7 +324,7 @@ namespace ui { * Loop on each character: */ - do { + do{ if(i && ((i / 110.0) == (i / 110))){ o.y -= fontSize * 1.05f; o.x = x; @@ -381,7 +387,6 @@ namespace ui { break; } } while(s[++i]); - putString(floor(x-width/2),y,s); return width; } @@ -473,7 +478,6 @@ namespace ui { dialogOptText.clear(); dialogOptChosen = 0; - memset(&dialogOptLoc,0,sizeof(float)*12); if ( opt ) { std::string soptbuf = opt; @@ -522,7 +526,7 @@ namespace ui { dialogOptText.clear(); dialogOptChosen = 0; - memset(&dialogOptLoc, 0, sizeof(float) * 12); + merchOptChosen = 0; // handle options if desired if(opt){ @@ -556,8 +560,9 @@ namespace ui { void waitForDialog(void){ do{ - mainLoop(); - }while(ui::dialogBoxExists); + //std::thread(dialogAdvance); + //mainLoop(); + }while(dialogBoxExists); } void waitForCover(void){ do{ @@ -709,26 +714,26 @@ namespace ui { glEnd(); glDisable(GL_TEXTURE_2D); - merchAOptLoc[0][0] = offset.x - (SCREEN_WIDTH / 8.5) - 16; - merchAOptLoc[1][0] = offset.x + (SCREEN_WIDTH / 8.5) + 16; - merchAOptLoc[0][1] = offset.y + (SCREEN_HEIGHT *.2); - merchAOptLoc[1][1] = offset.y + (SCREEN_HEIGHT *.2); - merchAOptLoc[0][2] = offset.x - (SCREEN_WIDTH / 8.5); - merchAOptLoc[1][2] = offset.x + (SCREEN_WIDTH / 8.5); + merchArrowLoc[0].x = offset.x - (SCREEN_WIDTH / 8.5) - 16; + merchArrowLoc[1].x = offset.x + (SCREEN_WIDTH / 8.5) + 16; + merchArrowLoc[0].y = offset.y + (SCREEN_HEIGHT *.2); + merchArrowLoc[1].y = offset.y + (SCREEN_HEIGHT *.2); + merchArrowLoc[0].z = offset.x - (SCREEN_WIDTH / 8.5); + merchArrowLoc[1].z = offset.x + (SCREEN_WIDTH / 8.5); for(i = 0; i < 2; i++){ - if(((merchAOptLoc[i][0] < merchAOptLoc[i][2]) ? - (mouse.x > merchAOptLoc[i][0] && mouse.x < merchAOptLoc[i][2]) : - (mouse.x < merchAOptLoc[i][0] && mouse.x > merchAOptLoc[i][2])) && - mouse.y > merchAOptLoc[i][1] - 8 && mouse.y < merchAOptLoc[i][1] + 8){ + if(((merchArrowLoc[i].x < merchArrowLoc[i].z) ? + (mouse.x > merchArrowLoc[i].x && mouse.x < merchArrowLoc[i].z) : + (mouse.x < merchArrowLoc[i].x && mouse.x > merchArrowLoc[i].z) ) && + mouse.y > merchArrowLoc[i].y - 8 && mouse.y < merchArrowLoc[i].y + 8 ) { glColor3ub(255,255, 0); }else{ glColor3ub(255,255,255); } glBegin(GL_TRIANGLES); - glVertex2f(merchAOptLoc[i][0],merchAOptLoc[i][1]); - glVertex2f(merchAOptLoc[i][2],merchAOptLoc[i][1]-8); - glVertex2f(merchAOptLoc[i][2],merchAOptLoc[i][1]+8); + glVertex2f(merchArrowLoc[i].x,merchArrowLoc[i].y); + glVertex2f(merchArrowLoc[i].z,merchArrowLoc[i].y-8); + glVertex2f(merchArrowLoc[i].z,merchArrowLoc[i].y+8); glEnd(); } @@ -738,18 +743,18 @@ namespace ui { setFontColor(255, 255, 255); // draw option - tmp = putStringCentered(offset.x, dialogOptLoc[i][1], dialogOptText[i].first); + tmp = putStringCentered(offset.x, dialogOptText[i].second.y, dialogOptText[i].first); // get coordinate information on option - dialogOptLoc[i][2] = offset.x + tmp; - dialogOptLoc[i][0] = offset.x - tmp; - dialogOptLoc[i][1] = y - SCREEN_HEIGHT / 2 - (fontSize + HLINE) * (i + 1); + dialogOptText[i].second.z = offset.x + tmp; + dialogOptText[i].second.x = offset.x - tmp; + dialogOptText[i].second.y = y - SCREEN_HEIGHT / 2 - (fontSize + HLINE) * (i + 1); // make text yellow if the mouse hovers over the text - if(mouse.x > dialogOptLoc[i][0] && mouse.x < dialogOptLoc[i][2] && - mouse.y > dialogOptLoc[i][1] && mouse.y < dialogOptLoc[i][1] + 16 ){ + if(mouse.x > dialogOptText[i].second.x && mouse.x < dialogOptText[i].second.z && + mouse.y > dialogOptText[i].second.y && mouse.y < dialogOptText[i].second.y + 16 ){ setFontColor(255, 255, 0); - putStringCentered(offset.x, dialogOptLoc[i][1], dialogOptText[i].first); + putStringCentered(offset.x, dialogOptText[i].second.y, dialogOptText[i].first); } } @@ -764,10 +769,10 @@ namespace ui { glBegin(GL_LINE_STRIP); glVertex2i(x-1 ,y+1); - glVertex2i(x+1 +SCREEN_WIDTH-HLINE*16,y+1); + glVertex2i(x+1+SCREEN_WIDTH-HLINE*16,y+1); glVertex2i(x+1+SCREEN_WIDTH-HLINE*16,y-1-SCREEN_HEIGHT/4); glVertex2i(x-1 ,y-1-SCREEN_HEIGHT/4); - glVertex2i( x - 1, y + 1 ); + glVertex2i(x-1 ,y+1); glEnd(); glColor3ub(0,0,0); @@ -779,16 +784,16 @@ namespace ui { for(i=0;i<dialogOptText.size();i++){ setFontColor(255,255,255); - tmp = putStringCentered(offset.x,dialogOptLoc[i][1],dialogOptText[i].first); - dialogOptLoc[i][2] = offset.x + tmp; - dialogOptLoc[i][0] = offset.x - tmp; - dialogOptLoc[i][1] = y - SCREEN_HEIGHT / 4 + (fontSize + HLINE) * (i + 1); - if(mouse.x > dialogOptLoc[i][0] && - mouse.x < dialogOptLoc[i][2] && - mouse.y > dialogOptLoc[i][1] && - mouse.y < dialogOptLoc[i][1] + 16 ){ // fontSize + tmp = putStringCentered(offset.x,dialogOptText[i].second.y,dialogOptText[i].first); + dialogOptText[i].second.z = offset.x + tmp; + dialogOptText[i].second.x = offset.x - tmp; + dialogOptText[i].second.y = y - SCREEN_HEIGHT / 4 + (fontSize + HLINE) * (i + 1); + if(mouse.x > dialogOptText[i].second.x && + mouse.x < dialogOptText[i].second.z && + mouse.y > dialogOptText[i].second.y && + mouse.y < dialogOptText[i].second.y + 16 ){ // fontSize setFontColor(255,255,0); - putStringCentered(offset.x,dialogOptLoc[i][1],dialogOptText[i].first); + putStringCentered(offset.x,dialogOptText[i].second.y,dialogOptText[i].first); } } setFontColor(255,255,255); @@ -824,6 +829,7 @@ namespace ui { * Lists all of the quests the player is currently taking. */ + setFontColor(255,255,255,fontTransInv); if(player->inv->invOpen){ hub.y = player->loc.y + fontSize * 8; hub.x = player->loc.x;// + player->width / 2; @@ -834,7 +840,18 @@ namespace ui { hub.y -= fontSize * 1.15; putStringCentered(hub.x,hub.y,c.title.c_str()); } + + hub.y = offset.y + 40*1.2; + hub.x = offset.x + SCREEN_WIDTH/2 - 40*1.5; + + putStringCentered(hub.x,hub.y,"Equipment:"); + + hub.y = offset.y + SCREEN_HEIGHT/2 - 20; + hub.x = offset.x - SCREEN_WIDTH/2 + 45*4*1.5; + + putStringCentered(hub.x,hub.y,"Inventory:"); } + setFontColor(255,255,255,255); } } @@ -1172,6 +1189,11 @@ namespace ui { fclose(bmp); } + void closeBox(){ + dialogBoxExists = false; + dialogMerchant = false; + } + void dialogAdvance(void){ unsigned char i; @@ -1187,29 +1209,45 @@ namespace ui { } for(i=0;i<dialogOptText.size();i++){ - if(mouse.x > dialogOptLoc[i][0] && - mouse.x < dialogOptLoc[i][2] && - mouse.y > dialogOptLoc[i][1] && - mouse.y < dialogOptLoc[i][1] + 16 ){ // fontSize + if(mouse.x > dialogOptText[i].second.x && + mouse.x < dialogOptText[i].second.z && + mouse.y > dialogOptText[i].second.y && + mouse.y < dialogOptText[i].second.y + 16 ){ // fontSize dialogOptChosen = i + 1; - goto DONE; + goto EXIT; + } + } + if(dialogMerchant){ + for(i=0;i<2;i++){ + if(((merchArrowLoc[i].x < merchArrowLoc[i].z) ? + (mouse.x > merchArrowLoc[i].x && mouse.x < merchArrowLoc[i].z) : + (mouse.x < merchArrowLoc[i].x && mouse.x > merchArrowLoc[i].z) && + mouse.y > merchArrowLoc[i].y - 8 && mouse.y < merchArrowLoc[i].y + 8)){ + merchOptChosen = i + 1; + goto EXIT; + } } } -DONE: + + +EXIT: + //if(!dialogMerchant)closeBox(); + dialogBoxExists = false; + dialogMerchant = false; + + //DONE: // handle important text if(dialogImportant){ dialogImportant = false; setFontSize(16); } - - if(dialogMerchant) dialogMerchant = false; - dialogBoxExists = false; } void handleEvents(void){ static bool left=true,right=false; static int heyOhLetsGo = 0; + static int mouseWheelUpCount = 0, mouseWheelDownCount = 0; World *tmp; vec2 oldpos,tmppos; SDL_Event e; @@ -1241,7 +1279,19 @@ DONE: if ( ( e.button.button & SDL_BUTTON_LEFT ) && !dialogBoxExists ) player->inv->usingi = true; break; - + case SDL_MOUSEWHEEL: + if (e.wheel.y < 0){ + if(mouseWheelUpCount++ && mouseWheelUpCount%5==0){ + player->inv->setSelectionUp(); + mouseWheelUpCount = 0; + } + }else{ + if(mouseWheelDownCount-- && mouseWheelDownCount%5==0){ + player->inv->setSelectionDown(); + mouseWheelDownCount = 0; + } + } + break; // key presses case SDL_KEYDOWN: @@ -1394,12 +1444,6 @@ DONE: } heyOhLetsGo = 0; break; - case SDLK_LEFT: - if(player->inv->sel)player->inv->sel--; - break; - case SDLK_RIGHT: - player->inv->sel++; - break; case SDLK_l: player->light^=true; break; diff --git a/src/world.cpp b/src/world.cpp index 2c7e06d..1a7322f 100644 --- a/src/world.cpp +++ b/src/world.cpp @@ -220,7 +220,6 @@ World:: Mix_FreeMusic(bgmObj); delete bgTex; - deleteEntities(); } @@ -786,6 +785,7 @@ singleDetect( Entity *e ) */ } else { + if(e->type == STRUCTURET && e->loc.y > 2000){ e->loc.y = worldData[i].groundHeight; e->vel.y = 0; @@ -985,6 +985,7 @@ setToRight( std::string file ) return (toRight = file); } +//what is this clyne why are they differnet World *World:: goWorldLeft( Player *p ) { @@ -1131,9 +1132,11 @@ void World::save(void){ } data.append("dOnE\0"); + std::cout << "Writing to the file" << std::endl; out.write(data.c_str(),data.size()); out.close(); + std::cout << "Done saving" << std::endl; } void World::load(void){ @@ -1536,8 +1539,6 @@ loadWorldFromXMLNoSave( std::string path ) { tmp->addMerchant(0,100); if(vil->FirstChildElement("buy")){ std::cout << "Buy" << std::endl; - //Trade goodMeme(1,"Dank MayMay",1,"Sword"); - //tmp->merchant.back()->trade.push_back(Trade()); }if(vil->FirstChildElement("sell")){ std::cout << "Sell" << std::endl; }if(vil->FirstChildElement("trade")){ @@ -1546,7 +1547,9 @@ loadWorldFromXMLNoSave( std::string path ) { vil->FirstChildElement("trade")->Attribute("item"), vil->FirstChildElement("trade")->IntAttribute("quantity1"), vil->FirstChildElement("trade")->Attribute("item1"))); + tmp->merchant.back()->trade.push_back(Trade(1,"Wood Sword", 420, "Dank MayMay")); } + std::cout << "new trade" << std::endl; strcpy(tmp->merchant.back()->name,"meme"); }else if(!strcmp(vil->Attribute("type"),"trader")){ |