diff options
author | Clyne Sullivan <tullivan99@gmail.com> | 2015-11-13 08:49:37 -0500 |
---|---|---|
committer | Clyne Sullivan <tullivan99@gmail.com> | 2015-11-13 08:49:37 -0500 |
commit | 5b41789c0e129c1e276917ef91ed53a1559cf31b (patch) | |
tree | db16627d239cda95cdbf9e3a597113bc996805d5 | |
parent | 180733d411b0844e878574e4c9f9b34690510367 (diff) | |
parent | a32339dc700759ab44a360953c9c24d009b11ecc (diff) |
major font fixes
-rw-r--r-- | Makefile | 2 | ||||
-rw-r--r-- | include/common.h | 2 | ||||
-rw-r--r-- | include/entities.h | 8 | ||||
-rw-r--r-- | include/world.h | 7 | ||||
-rw-r--r-- | main.cpp | 55 | ||||
-rw-r--r-- | src/Makefile | 2 | ||||
-rw-r--r-- | src/entities.cpp | 23 | ||||
-rw-r--r-- | src/gameplay.cpp | 8 | ||||
-rw-r--r-- | src/world.cpp | 34 |
9 files changed, 115 insertions, 26 deletions
@@ -1,4 +1,4 @@ -LIBS = -lGL -lGLEW -lSDL2main -lSDL2 -lfreetype -lSDL2_image -lSDL2_mixer
+LIBS = -lGL -lGLEW -lSDL2 -lfreetype -lSDL2_image -lSDL2_mixer
WIN_LIBS = -lopengl32 -lglew32 -lmingw32 -lSDL2main -lSDL2 -lSDL2_image -lSDL2_mixer -lfreetype
diff --git a/include/common.h b/include/common.h index 93735fa..bfd9db6 100644 --- a/include/common.h +++ b/include/common.h @@ -36,7 +36,7 @@ typedef unsigned int uint; * This flag lets the compiler know that we are using shaders */ -#define SHADERSd +#define SHADERSs /* * Create a basic 2-point structure for coordinate saving diff --git a/include/entities.h b/include/entities.h index 53efc63..b590c8d 100644 --- a/include/entities.h +++ b/include/entities.h @@ -15,6 +15,7 @@ #define NPC_INV_SIZE 3 // Size of an NPC's inventory enum _TYPE { //these are the main types of entities + OBJECTT = -2, STRUCTURET = -1, PLAYERT, NPCT, @@ -106,6 +107,13 @@ public: void wander(int); }; +class Object : public Entity{ +public: + Object(int); + void interact(); +private: + int ID; +}; #endif // ENTITIES_H /** diff --git a/include/world.h b/include/world.h index fffdb9d..437f138 100644 --- a/include/world.h +++ b/include/world.h @@ -76,10 +76,17 @@ public: std::vector<Structures *> build; std::vector<Mob *> mob; std::vector<Entity *> entity; + std::vector<Object *> object; + //template<class T> + //void getEntityLocation(std::vector<T*>&, unsigned int); + void addStructure(_TYPE t,float x,float y,World *outside,World *inside); void addMob(int t,float x,float y); void addNPC(float x,float y); + void addObject(int, float, float); + + //void removeObjet(Object); void update(Player *p,unsigned int delta); @@ -85,7 +85,6 @@ float handAngle; World *currentWorld=NULL; Player *player; - /* * Tells if player is currently inside a structure. */ @@ -215,7 +214,7 @@ typedef enum { RAIN } WEATHER; -#define DAY_CYCLE 2000 +#define DAY_CYCLE 300 static WEATHER weather = SUNNY; static vec2 star[100]; @@ -530,6 +529,7 @@ void mainLoop(void){ logic(); prevPrevTime = currentTime; } + //ui::handleMouse(); /* * Update player and entity coordinates. @@ -541,15 +541,15 @@ void mainLoop(void){ * Update debug variables if necessary */ - if(ui::debug){ - if(++debugDiv==20){ - debugDiv=0; - fps=1000/deltaTime; - }else if(!(debugDiv%10)){ - debugY = player->loc.y; - } - } - + if(++debugDiv==20){ + debugDiv=0; + + fps=1000/deltaTime; + + }else if(!(debugDiv%10)){ + debugY = player->loc.y; + } + render(); // Call the render loop } @@ -675,12 +675,15 @@ void render(){ * Draws stars if it is an appropriate time of day for them. */ + int base = 40 - (int)worldGetYBase(currentWorld); + int shade = worldShade*2; + if(((weather==DARK )&(tickCount%DAY_CYCLE)<DAY_CYCLE/2) || ((weather==SUNNY)&(tickCount%DAY_CYCLE)>DAY_CYCLE*.75) ){ if(tickCount%DAY_CYCLE){ // The above if statement doesn't check for exact midnight. - glColor4ub(255,255,255,255); + safeSetColorA(255,255,255,shade); for(unsigned int i=0;i<100;i++){ glRectf(star[i].x+offset.x*.9,star[i].y,star[i].x+offset.x*.9+HLINE,star[i].y+HLINE); } @@ -693,9 +696,6 @@ void render(){ * background elements should be. */ - int base = 40 - (int)worldGetYBase(currentWorld); - int shade = worldShade*2; - glEnable(GL_TEXTURE_2D); /* @@ -881,7 +881,7 @@ void render(){ ui::putText(offset.x-SCREEN_WIDTH/2, (offset.y+SCREEN_HEIGHT/2)-ui::fontSize, - "FPS: %d\nG:%d\nRes: %ux%u\nE: %d\nPOS: (x)%+.2f\n (y)%+.2f\nTc: %u\nQc: %u\n HA: %+.2f", + "FPS: %d\nG:%d\nRes: %ux%u\nE: %d\nPOS: (x)%+.2f\n (y)%+.2f\nTc: %u\nHA: %+.2f", fps, player->ground, SCREEN_WIDTH, // Window dimensions @@ -890,7 +890,6 @@ void render(){ player->loc.x, // The player's x coordinate debugY, // The player's y coordinate tickCount, - player->qh.current.size(), // Active quest count handAngle ); @@ -1075,6 +1074,28 @@ void logic(){ } } + unsigned int i = 0; + for(auto &o : currentWorld->object){ + if(o->alive){ + if(pow((o->loc.x - player->loc.x),2) + pow((o->loc.y - player->loc.y),2) <= pow(40*HLINE,2)){ + + /* + * Check for a right click, and allow the Object to interact with the + * player if one was made. + */ + + if(SDL_GetMouseState(NULL, NULL) & SDL_BUTTON(SDL_BUTTON_RIGHT)){ + std::cout << "Picking up!\n"; + o->interact(); + } + } + } + if(!(o->alive)){ + currentWorld->object.erase(currentWorld->object.begin()+i); + } + i++; + } + /* * Switch between day and night (SUNNY and DARK) if necessary. */ diff --git a/src/Makefile b/src/Makefile index a243846..972edcb 100644 --- a/src/Makefile +++ b/src/Makefile @@ -1,4 +1,4 @@ -LIBS = -lGL -lSDL2main -lSDL2 -lSDL2_image -lSDL2_mixer -lfreetype +LIBS = -lGL -lSDL2 -lSDL2_image -lSDL2_mixer -lfreetype FLAGS = -m32 -std=c++11 -I../include -I../include/freetype2 diff --git a/src/entities.cpp b/src/entities.cpp index 0320b60..a8e9bfb 100644 --- a/src/entities.cpp +++ b/src/entities.cpp @@ -6,6 +6,8 @@ extern unsigned int loops; extern World *currentWorld; +extern Player *player; + void Entity::spawn(float x, float y){ //spawns the entity you pass to it based off of coords and global entity settings loc.x = x; loc.y = y; @@ -89,6 +91,18 @@ Mob::Mob(int sub){ inv = new Inventory(NPC_INV_SIZE); } +Object::Object(int id):ID(id){ + type = OBJECTT; + alive = true; + near = false; + width = HLINE * 8; + height = HLINE * 8; + + maxHealth = health = 1; + tex = new Texturec(1, "assets/items/ITEM_SWORD.png"); +} + + void Entity::draw(void){ //draws the entities glPushMatrix(); if(type==NPCT){ @@ -161,6 +175,8 @@ void Entity::draw(void){ //draws the entities default: break; } + }else if(type == OBJECTT){ + tex->bind(0); }else{ tex->bind(0); } @@ -278,6 +294,11 @@ void NPC::interact(){ //have the npc's interact back to the player } } +void Object::interact(){ + this->alive = false; + player->inv->addItem((ITEM_ID)(ID), (char)1); +} + /* * This spawns the structures * @@ -358,4 +379,4 @@ void Mob::wander(int timeRun){ default: break; } -} +}
\ No newline at end of file diff --git a/src/gameplay.cpp b/src/gameplay.cpp index 4e67bb8..fcc501c 100644 --- a/src/gameplay.cpp +++ b/src/gameplay.cpp @@ -5,7 +5,6 @@ extern World *currentWorld; extern Player *player; - extern void mainLoop(void); void waitForDialog(void){ @@ -52,7 +51,6 @@ void initEverything(void){ /* * World creation: */ - World *test=new World(); World *playerSpawnHill=new World(); @@ -109,8 +107,10 @@ void initEverything(void){ * Spawn a mob. */ - currentWorld->addMob(MS_RABBIT,200,100); - currentWorld->addMob(MS_BIRD,-500,500); + test->addMob(MS_RABBIT,200,100); + test->addMob(MS_BIRD,-500,500); + + currentWorld->addObject(2, 500,200); /* * Link all the entities that were just created to the initial world, and setup a test AI function. diff --git a/src/world.cpp b/src/world.cpp index 9d41623..7b1580a 100644 --- a/src/world.cpp +++ b/src/world.cpp @@ -286,7 +286,9 @@ LOOP2: /* * Draw the layer up until the grass portion, which is done later. */ - + /* + * TODO: CLYNE CHANGE THE NAME OF THIS + */ bool hey=false; glBegin(GL_QUADS); for(i=is;i<ie-GEN_INC;i++){ @@ -372,6 +374,13 @@ LOOP2: m->draw(); m->loc.y-=(yoff-DRAW_Y_OFFSET); } + for(auto &o : current->object){ + if(o->alive){ + o->loc.y+=(yoff-DRAW_Y_OFFSET); + o->draw(); + o->loc.y-=(yoff-DRAW_Y_OFFSET); + } + } /* * If we're drawing the closest/last world, handle and draw the player. @@ -549,6 +558,18 @@ void World::addStructure(_TYPE t,float x,float y,World *outside,World *inside){ entity.push_back(build.back()); } +/*template<class T> +void World::getEntityLocation(std::vector<T*>&vecBuf, unsigned int n){ + T bufVar = vecBuf.at(n); + unsigned int i = 0; + for(auto &e : entity){ + if(entity.at(i) == bufVar){ + entity.erase(entity.begin()+i); + } + i++; + } +}*/ + void World::addMob(int t,float x,float y){ mob.push_back(new Mob(t)); mob.back()->spawn(x,y); @@ -563,6 +584,17 @@ void World::addNPC(float x,float y){ entity.push_back(npc.back()); } +void World::addObject(int i, float x, float y){ + object.push_back(new Object(i)); + object.back()->spawn(x,y); + + entity.push_back(object.back()); +} + +/*void World::removeObject(Object i){ + object.delete(i); +}*/ + /* * The rest of these functions are explained well enough in world.h ;) */ |