diff options
author | Clyne Sullivan <tullivan99@gmail.com> | 2015-11-03 08:45:29 -0500 |
---|---|---|
committer | Clyne Sullivan <tullivan99@gmail.com> | 2015-11-03 08:45:29 -0500 |
commit | 505027ab6dec50f991e2c21abf270c491128487a (patch) | |
tree | f4ae696cfaeac81fc05a9405f65c204d50625f33 /src | |
parent | f8ebf8fd3d5691cd45566281a1f54c5ecbc43762 (diff) |
ui improvements
Diffstat (limited to 'src')
-rw-r--r-- | src/entities.cpp | 2 | ||||
-rw-r--r-- | src/inventory.cpp | 2 | ||||
-rw-r--r-- | src/ui.cpp | 49 | ||||
-rw-r--r-- | src/world.cpp | 32 |
4 files changed, 70 insertions, 15 deletions
diff --git a/src/entities.cpp b/src/entities.cpp index 42ed5a9..acc45bd 100644 --- a/src/entities.cpp +++ b/src/entities.cpp @@ -176,7 +176,7 @@ void Entity::draw(void){ //draws the entities glMatrixMode(GL_MODELVIEW); glPopMatrix(); if(near){ - ui::setFontSize(10); + ui::setFontSize(14); ui::putText(loc.x,loc.y-ui::fontSize-HLINE/2,"%s",name); } } diff --git a/src/inventory.cpp b/src/inventory.cpp index 11f2ad7..cb33deb 100644 --- a/src/inventory.cpp +++ b/src/inventory.cpp @@ -92,7 +92,7 @@ int Inventory::takeItem(ITEM_ID id,unsigned char count){ void Inventory::draw(void){ unsigned int i=0; float y=SCREEN_HEIGHT/2,xoff; - ui::setFontSize(12); + ui::setFontSize(14); ui::putText(offset.x-SCREEN_WIDTH/2,y,"Inventory:"); while(item[i].count){ y-=HLINE*12; @@ -16,6 +16,8 @@ static GLuint ftex; static char *dialogBoxText; +bool fadeEnable = false; + namespace ui { vec2 mouse; bool debug=false; @@ -139,6 +141,23 @@ namespace ui { }while(s[++i]); return xo; } + char *typeOut(char *str){ + static unsigned int sinc,linc,size; + static char *ret = NULL; + unsigned int i; + if(!ret || size != strlen(str)){ + size=strlen(str); + ret=(char *)calloc(size,sizeof(char)); + linc=0; + sinc=2; + } + if(++sinc==3){ + sinc=0; + strncpy(ret+linc,str+linc,1); + if(linc<size)linc++; + } + return ret; + } float putText(const float x,const float y,const char *str,...){ // putText() simply runs 'str' and the extra arguments though va_list args; // vsnprintf(), which'll store the complete string to a buffer char *buf; // that's then passed to putString() @@ -167,6 +186,21 @@ namespace ui { vsnprintf(dialogBoxText+name_len+2,512-name_len-2,text,dialogArgs); va_end(dialogArgs); } + void importantText(const char *text,...){ + va_list textArgs; + char *ttext; + va_start(textArgs,text); + ttext=(char *)calloc(512,sizeof(char)); + vsnprintf(ttext,512,text,textArgs); + va_end(textArgs); + setFontSize(24); + char *rtext; + rtext=typeOut(ttext); + putString(player->loc.x+player->width/2-SCREEN_WIDTH/2, + SCREEN_HEIGHT/2+fontSize, + rtext); + free(ttext); + } void draw(void){ float x,y; if(dialogBoxExists){ @@ -174,10 +208,12 @@ namespace ui { x=player->loc.x-SCREEN_WIDTH/2+HLINE*8; y=SCREEN_HEIGHT-HLINE*8; glRectf(x,y,x+SCREEN_WIDTH-HLINE*16,y-SCREEN_HEIGHT/4); - setFontSize(12); - putString(x+HLINE,y-fontSize-HLINE,dialogBoxText); + char *rtext; + rtext=typeOut(dialogBoxText); + setFontSize(16); + putString(x+HLINE,y-fontSize-HLINE,rtext); } - setFontSize(12); + setFontSize(14); putText(((SCREEN_WIDTH/2)+offset.x)-125,SCREEN_HEIGHT-fontSize,"Health: %u/%u",player->health>0?(unsigned)player->health:0, (unsigned)player->maxHealth); if(player->alive){ @@ -269,8 +305,9 @@ namespace ui { player->inv->useItem(); } if(SDL_KEY==SDLK_c){ - dialogBox("","You pressed `c`, but nothing happened."); + dialogBox("","You pressed `c`, but nothing happened?"); } + if(SDL_KEY==SDLK_p)toggleBlack(); if(SDL_KEY==SDLK_LSHIFT)player->speed = debug?4:3; // Sprint if(SDL_KEY==SDLK_LCTRL)player->speed = .5; } @@ -304,4 +341,8 @@ namespace ui { } } } + + void toggleBlack(void){ + fadeEnable ^= true; + } } diff --git a/src/world.cpp b/src/world.cpp index 36993b0..0ec0f35 100644 --- a/src/world.cpp +++ b/src/world.cpp @@ -33,6 +33,14 @@ float worldGetYBase(World *w){ } World::World(void){ + /* + * Nullify pointers to other worlds. + */ + + behind = + infront = + toLeft = + toRight = NULL; } void World::generate(unsigned int width){ // Generates the world and sets all variables contained in the World class. @@ -129,15 +137,21 @@ void World::generate(unsigned int width){ // Generates the world and sets all va */ x_start=0 - getWidth(this) / 2; - - /* - * Nullify pointers to other worlds. - */ - - behind = - infront = - toLeft = - toRight = NULL; +} + +void World::generateFunc(unsigned int width,unsigned int (*func)(unsigned int)){ + unsigned int i; + if((lineCount = width) <= 0) + abort(); + line=(struct line_t *)calloc(lineCount,sizeof(struct line_t)); + for(i=0;i<lineCount;i++){ + line[i].y=func(i); + line[i].color=rand() % 20 + 100; + line[i].gh[0]=(getRand() % 16) / 3.5 + 2; + line[i].gh[1]=(getRand() % 16) / 3.5 + 2; + line[i].gs=true; + } + x_start=0 - getWidth(this) / 2; } World::~World(void){ |