]> code.bitgloo.com Git - clyne/gamedev.git/commitdiff
more fonts, entity name displays
authorClyne Sullivan <tullivan99@gmail.com>
Wed, 30 Sep 2015 23:46:44 +0000 (19:46 -0400)
committerClyne Sullivan <tullivan99@gmail.com>
Wed, 30 Sep 2015 23:46:44 +0000 (19:46 -0400)
Changelog
include/entities.h
src/entities.cpp
src/main.cpp
src/ui.cpp
src/world.cpp
ttf/8-BIT WONDER.TTF [new file with mode: 0644]
ttf/PIXEAB__.TTF [new file with mode: 0644]
ttf/PIXEARG_.TTF [new file with mode: 0644]
ttf/Perfect DOS VGA 437 Win.ttf [new file with mode: 0644]
ttf/Perfect DOS VGA 437.ttf [new file with mode: 0644]

index 901918d528e3cbbeb134fdc3dde75707183f6617..fa7b5dea5332e76954a0064b1b4ccbf12fd09a60 100644 (file)
--- a/Changelog
+++ b/Changelog
@@ -54,3 +54,6 @@
        - began work on giving names to NPCs
        - began working on config file
        - created a bug file
+       
+       - added displaying of entity names on mouse hover
+       - found more fonts
index 3d2bbefb4fd04f2191f9a65fa9fd104693eb85f2..b58d56946bd088798feba05e74aa03b3ee9d80d4 100644 (file)
@@ -23,6 +23,7 @@ public:
                        //              |->  1 Merchant
        vec2 loc; //location and velocity of the entity
        vec2 vel;
+       bool near;
        bool right,left, canMove; //movement variables
        bool alive;                               //the flag for whether or not the entity is alive
        unsigned char ground;     //variable for testing what ground the entity is on to apply certain traits
index 85505ce6c04f51a2b3bb9d07e836d4925f5266ac..8ccd5e1ce87833692b009dc8923298f24a71df3c 100644 (file)
@@ -11,6 +11,7 @@ void Entity::spawn(float x, float y){ //spawns the entity you pass to it based o
        vel.y = 0;
        right = false;
        left = false;
+       near = false;
        ticksToUse = 0;
        canMove = false;
        ground = false;
@@ -62,8 +63,9 @@ void Entity::getName(){
        if((fgets(bufs,16,(FILE*)names)) != NULL){
                std::puts(bufs);
                bufs[strlen(bufs)-1] = 0;
-               name = bufs;
+               strcpy(name,bufs);
        }
+       free(bufs);
        //delete(bufs);
 }
 
@@ -89,6 +91,7 @@ NPC::NPC(){   //sets all of the NPC specific traits on object creation
        subtype = 0;
        alive = true;
        canMove = true;
+       near = false;
 }
 
 void NPC::addAIFunc(int (*func)(NPC *)){
@@ -110,6 +113,7 @@ Structures::Structures(){ //sets the structure type
        type = STRUCTURET;
        speed = 0;
        alive = true;
+       near = false;
 }
 
 unsigned int Structures::spawn(_TYPE t, float x, float y){ //spawns a structure based off of type and coords
index ea196681ffb12e9e47ac762c4ef5f2607789647b..d39bd92d99a0c3a8f7e57a56ed2a53628aac7202 100644 (file)
@@ -76,8 +76,7 @@ int main(int argc, char *argv[]){
     }
 
        ui::initFonts();
-       ui::setFontFace("ttf/VCR_OSD_MONO_1.001.ttf");
-       ui::setFontSize(16);
+       ui::setFontFace("ttf/Perfect DOS VGA 437.ttf");
        initRand(millis()); // fix
 
        glViewport(0,0,SCREEN_WIDTH, SCREEN_HEIGHT);
@@ -187,8 +186,9 @@ void render(){
                }else if(debugDiv%10==0){
                        rndy = player->loc.y;
                }
-               ui::putText(player->loc.x-SCREEN_WIDTH/2,SCREEN_HEIGHT-ui::fontSize,"FPS: %d\nD: %d G:%d\nRes: %ux%u\nE: %d\nPOS: (x)%+.2f\n     (y)%+.2f",
-                                       fps,d,player->ground,SCREEN_WIDTH,SCREEN_HEIGHT,entity.size(),player->loc.x,rndy);
+               ui::setFontSize(16);
+               ui::putText(player->loc.x-SCREEN_WIDTH/2,SCREEN_HEIGHT-ui::fontSize,"FPS: %d\nD: %d G:%d\nRes: %ux%u\nE: %d\nPOS: (x)%+.2f\n     (y)%+.2f\nQc: %u",
+                                       fps,d,player->ground,SCREEN_WIDTH,SCREEN_HEIGHT,entity.size(),player->loc.x,rndy,player->qh.current.size());
        }
 
        ui::draw();                                                     // Draw any UI elements if they need to be
@@ -213,8 +213,6 @@ void render(){
                glVertex2i(mx,my-HLINE*3.5);
        glEnd();
 
-       ui::putText(player->loc.x-SCREEN_WIDTH/2,SCREEN_HEIGHT/2,"Quest count: %d",player->qh.current.size());
-
        glPopMatrix();                                                                  //take the matrix(s) off the stack to pass them to the renderer
        SDL_GL_SwapWindow(window);                                              //give the stack to SDL to render it
 }
@@ -226,11 +224,13 @@ void logic(){
                if(entity[i]->alive&&entity[i]->type == NPCT){
                        entity[i]->wander((rand()%120 + 30), &entity[i]->vel);
                        if( pow((entity[i]->loc.x - player->loc.x),2) + pow((entity[i]->loc.y - player->loc.y),2) <= pow(40*HLINE,2)){
-                               if(mx >= entity[i]->loc.x && mx <= entity[i]->loc.x + entity[i]->width && my >= entity[i]->loc.y && my <= entity[i]->loc.y + entity[i]->width
-                                && (SDL_GetMouseState(NULL, NULL) & SDL_BUTTON(SDL_BUTTON_RIGHT))){
-                                       entity[i]->interact();
-                                       std::cout <<"["<<i<<"] -> "<< entity[i]->name << ", " << (std::string)(entity[i]->gender == MALE ? "Male" : "Female") << std::endl;
-                               }
+                               if(mx >= entity[i]->loc.x && mx <= entity[i]->loc.x + entity[i]->width && my >= entity[i]->loc.y && my <= entity[i]->loc.y + entity[i]->width){
+                                       entity[i]->near=true;
+                                       if(SDL_GetMouseState(NULL, NULL)&SDL_BUTTON(SDL_BUTTON_RIGHT)){
+                                               entity[i]->interact();
+                                               std::cout <<"["<<i<<"] -> "<< entity[i]->name << ", " << (std::string)(entity[i]->gender == MALE ? "Male" : "Female") << std::endl;
+                                       }
+                               }else entity[i]->near=false;
                        }
                }
        }
index c14b4ff69f91e0afb1e41dab5d8dca159cab585f..de875b9281d423c88d7bcbcb242dfa3ec1c429e5 100644 (file)
@@ -78,7 +78,25 @@ namespace ui {
                h=ftf->glyph->bitmap.rows;
                glEnable(GL_TEXTURE_2D);
                glBindTexture(GL_TEXTURE_2D,ftex);
-               if(c=='-')y+=fontSize/3;
+               switch(c){
+               case '^':
+               case '*':
+               case '`':
+               case '\'':
+               case '\"':
+               case '-':y+=fontSize/3;break;
+               case '~':
+               case '<':
+               case '>':
+               case '+':
+               case '=':y+=fontSize/5;break;
+               case 'g':
+               case 'q':
+               case 'y':
+               case 'p':
+               case 'j':y-=fontSize/4;break;
+               default:break;
+               }
                glBegin(GL_QUADS);
                        glColor3ub(255,255,255);
                        glTexCoord2f(0,1);glVertex2f(x,y);
@@ -97,7 +115,7 @@ namespace ui {
                float xo=x,yo=y;
                do{
                        if(s[i]=='\n'){
-                               yo-=fontSize*1.15;
+                               yo-=fontSize*1.05;
                                xo=x;
                        }else if(s[i]==' '){
                                xo+=fontSize/2;
@@ -125,6 +143,7 @@ namespace ui {
                if(dialogBoxExists){
                        glColor3ub(0,0,0);
                        glRectf(player->loc.x-SCREEN_WIDTH/2,SCREEN_HEIGHT,player->loc.x+SCREEN_WIDTH/2,SCREEN_HEIGHT-SCREEN_HEIGHT/4);
+                       setFontSize(16);
                        putString(player->loc.x-SCREEN_WIDTH/2,SCREEN_HEIGHT-fontSize,dialogBoxText);
                }
        }
index 1d56643871280b8b318a6e8db6a8ff144a5f5165..2a0e471cebc10e4da776d531aaa21e0ace2f6929 100644 (file)
@@ -117,7 +117,10 @@ LOOP2:                                                                                                     // Draw each world
                for(i=0;i<entity.size()+1;i++){
                        if(entity[i]->inWorld==this){
                                entity[i]->draw();
-                               ui::putText(entity[i]->loc.x,entity[i]->loc.y,"%d",i);
+                               if(entity[i]->near){
+                                       ui::setFontSize(14);
+                                       ui::putText(entity[i]->loc.x,entity[i]->loc.y-ui::fontSize-HLINE/2,"%s",entity[i]->name);
+                               }
                        }
                }
        }
diff --git a/ttf/8-BIT WONDER.TTF b/ttf/8-BIT WONDER.TTF
new file mode 100644 (file)
index 0000000..6d9b397
Binary files /dev/null and b/ttf/8-BIT WONDER.TTF differ
diff --git a/ttf/PIXEAB__.TTF b/ttf/PIXEAB__.TTF
new file mode 100644 (file)
index 0000000..c0cc3d9
Binary files /dev/null and b/ttf/PIXEAB__.TTF differ
diff --git a/ttf/PIXEARG_.TTF b/ttf/PIXEARG_.TTF
new file mode 100644 (file)
index 0000000..8eaf339
Binary files /dev/null and b/ttf/PIXEARG_.TTF differ
diff --git a/ttf/Perfect DOS VGA 437 Win.ttf b/ttf/Perfect DOS VGA 437 Win.ttf
new file mode 100644 (file)
index 0000000..d03b1c5
Binary files /dev/null and b/ttf/Perfect DOS VGA 437 Win.ttf differ
diff --git a/ttf/Perfect DOS VGA 437.ttf b/ttf/Perfect DOS VGA 437.ttf
new file mode 100644 (file)
index 0000000..f5cbfc0
Binary files /dev/null and b/ttf/Perfect DOS VGA 437.ttf differ