]> code.bitgloo.com Git - clyne/gamedev.git/commitdiff
font improvements
authorClyne Sullivan <tullivan99@gmail.com>
Fri, 5 Feb 2016 13:29:56 +0000 (08:29 -0500)
committerClyne Sullivan <tullivan99@gmail.com>
Fri, 5 Feb 2016 13:29:56 +0000 (08:29 -0500)
Changelog
include/entities.h
main.cpp
src/config.cpp
src/gameplay.cpp
src/inventory.cpp
src/ui.cpp
src/world.cpp
ttf/FreePixel.ttf [new file with mode: 0644]
xml/playerSpawnHill1.xml

index 2f5cdf47beda1e6be69d99c7c2b090562cd969a3..2077ac0fb59a4b2b9ce00f8099991a9ec9ad1f64 100644 (file)
--- a/Changelog
+++ b/Changelog
        - removed old, unused and commented codes
        - began working on XML'ing quests
        - improved mouse
+
+2/4/2016:
+=========
+
+       - fixed world boundary glitch
+       - began work on XML'ing triggers
+       - npcs can assign quests through XML
+       - screenshots
+       - improved memory management
+       - more audio sliders
+
+2/5/2016:
+=========
+
+       - improved font rendering codes
+       - added font selection to settings.xml
+       - XML'd important text
index 41f2fffa79735a0776b2f128db3d8e236109ac11..9cc1b310594e5acc6502125b2488df32da2eee5c 100644 (file)
@@ -208,6 +208,7 @@ public:
        bool aggressive;
        double init_y;
        void (*hey)(Mob *callee);
+       std::string heyid;
        
        Mob(int);
        ~Mob();
index c523c65737b06b5ce36e3e15c5de43c11d444dd3..da1790fa5473a71c062a79b4af3db48173ad9f38 100644 (file)
--- a/main.cpp
+++ b/main.cpp
@@ -302,8 +302,8 @@ int main(/*int argc, char *argv[]*/){
         * if they have error.
         */
        
-       ui::initFonts();
-       ui::setFontFace("ttf/VCR_OSD_MONO_1.001.ttf");          // as in gamedev/ttf/<font>
+       //ui::initFonts();
+       //ui::setFontFace("ttf/FreePixel.ttf");         // as in gamedev/ttf/<font>
        
        /*
         * Initialize the random number generator. At the moment, initRand is a macro pointing to libc's
index 8ec361de987b62415576e08312846e71441fca0b..ca6db1b295dde6da4d6f5ef9c66b2fbdbd93a3e4 100644 (file)
@@ -1,5 +1,7 @@
 #include <config.h>
 
+#include <ui.h>
+
 using namespace tinyxml2;
 
 extern unsigned int HLINE;
@@ -44,7 +46,10 @@ void readConfig(){
        VOLUME_MASTER = vol->FirstChildElement("master")->FloatAttribute("volume");
        VOLUME_MUSIC  = vol->FirstChildElement("music")->FloatAttribute("volume");
        VOLUME_SFX    = vol->FirstChildElement("sfx")->FloatAttribute("volume");
-
+       
+       std::cout<<"Loading font through settings.xml..."<<std::endl;
+       ui::initFonts();
+       ui::setFontFace(xml.FirstChildElement("font")->Attribute("path"));
 }
 
 void updateConfig(){
index 1103cfafccd9215a2d19d1e8075f360d276b8f56..00faf70d88308a52656fa3094042596e4b373d78 100644 (file)
@@ -173,7 +173,7 @@ int commonAIFunc(NPC *speaker){
                                                speaker->dialogIndex = 9999;
                                                return 0;
                                        }else if(exml->QueryBoolAttribute("pause",&stop) == XML_NO_ERROR && stop){
-                                               speaker->dialogIndex = 9999;
+                                               //speaker->dialogIndex = 9999;
                                                return 1;
                                        }else return commonAIFunc(speaker);
                                }else{
@@ -191,6 +191,47 @@ int commonAIFunc(NPC *speaker){
        return 0;
 }
 
+void commonTriggerFunc(Mob *callee){
+       static bool lock = false;
+       XMLDocument xml;
+       XMLElement *exml;
+       
+       char *text,*pch;
+       
+       if(!lock){
+               lock = true;
+       
+               xml.LoadFile(currentXML);
+               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;
+       }
+}
+
 void destroyEverything(void);
 void initEverything(void){
        std::vector<std::string> xmlFiles;
@@ -227,17 +268,6 @@ void initEverything(void){
                }
        }
 
-       /*
-        * Spawn the player and begin the game.
-        */
-       
-       player = new Player();
-       player->spawn(200,100);
-
-       currentWorld->bgmPlay(NULL);
-       atexit(destroyEverything);
-       std::cout << "Hey";
-
        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));
@@ -252,6 +282,16 @@ 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.
+        */
+       
+       player = new Player();
+       player->spawn(200,100);
+
+       currentWorld->bgmPlay(NULL);
+       atexit(destroyEverything);
 }
 
 extern std::vector<int (*)(NPC *)> AIpreload;
index de6003054753e83132c0325758e828ce14c8bfcb..93bdeb6cb250ae616e0675ddf94d258c3a9a4403 100644 (file)
@@ -88,6 +88,12 @@ void initInventorySprites(void){
 }
 
 void destroyInventory(void){
+       
+       while(!itemMap.empty()){
+               delete itemMap.front();
+               itemMap.erase(itemMap.begin());
+       }
+       
        Mix_FreeChunk(swordSwing);
 }
 
index 937367c522dd744920cebcc047fdf1704622e6d1..56a88a33376cde51f9b3e55f83b80a2b622b472b 100644 (file)
@@ -227,8 +227,8 @@ namespace ui {
                                buf[j*4  ]=fontColor[0];
                                buf[j*4+1]=fontColor[1];
                                buf[j*4+2]=fontColor[2];
-                               //buf[j*4+3]=ftf->glyph->bitmap.buffer[j] == 255 ? 255 : 0;
-                               buf[j*4+3]=ftf->glyph->bitmap.buffer[j];
+                               buf[j*4+3]=ftf->glyph->bitmap.buffer[j] ? 255 : 0;
+                               //buf[j*4+3]=ftf->glyph->bitmap.buffer[j];
                        }
                        
                        ftexwh[i-33].x=ftf->glyph->bitmap.width;
@@ -537,7 +537,7 @@ namespace ui {
                                  
                dialogBoxExists = true;
                dialogImportant = true;
-               toggleBlack();
+               //toggleBlack();
        }
        void draw(void){
                unsigned char i;
@@ -976,7 +976,7 @@ namespace ui {
                fwrite(&bgr, 1,3*SCREEN_WIDTH*SCREEN_HEIGHT,bmp);
 
                delete[] pixels;
-
+               
                fclose(bmp);
        }
 
@@ -1000,8 +1000,10 @@ DONE:
                if(dialogImportant){
                        dialogImportant = false;
                        setFontSize(16);
-                       toggleBlack();
+                       //toggleBlack();
                }
+               /*if(ui::fontSize != 16)
+                       setFontSize(16);*/
 
                dialogBoxExists = false;
        }
index 71260952e4bfa3dddf37eda950b504bc78138a0e..6118851ff0b0f803077904aa2e636a071238667c 100644 (file)
@@ -895,10 +895,10 @@ void World::singleDetect(Entity *e){
                 *      Insure that the entity doesn't fall off either edge of the world.
                */
                
-               if(e->loc.x<x_start){                                                                                           // Left bound
+               if(e->loc.x < x_start){                                                                                         // Left bound
                        
                        e->vel.x=0;
-                       e->loc.x=x_start + HLINE / 2;
+                       e->loc.x=(float)x_start + HLINE / 2;
                        
                }else if(e->loc.x + e->width + HLINE > x_start + getWidth(this)){       // Right bound
                        
@@ -1071,6 +1071,7 @@ char *World::setToRight(const char *file){
 
 World *World::goWorldLeft(Player *p){
        World *tmp;
+       
        if(toLeft && p->loc.x < x_start + HLINE * 15){
                tmp = loadWorldFromXML(toLeft);
                
@@ -1200,7 +1201,8 @@ void World::save(void){
 
 #include <sstream>
 
-extern int commonAIFunc(NPC *);
+extern int  commonAIFunc(NPC *);
+extern void commonTriggerFunc(Mob *);
 
 void World::load(void){
        std::string save,data,line;
@@ -1449,8 +1451,6 @@ World *loadWorldFromXML(const char *path){
        strcpy(currentXML,"xml/");
        strcat(currentXML,path);
        
-       //std::cout<<currentXML<<std::endl;
-       
        xml.LoadFile(currentXML);
        wxml = xml.FirstChildElement("World");
 
@@ -1523,7 +1523,11 @@ World *loadWorldFromXML(const char *path){
                                tmp->addStructure((BUILD_SUB)wxml->UnsignedAttribute("type"),getRand() % tmp->getTheWidth() / 2.0f,100,ptr);
                        else
                                tmp->addStructure((BUILD_SUB)wxml->UnsignedAttribute("type"),spawnx,wxml->FloatAttribute("y"),ptr);
+               }else if(!strcmp(name,"trigger")){
+                       tmp->addMob(MS_TRIGGER,wxml->FloatAttribute("x"),0,commonTriggerFunc);
+                       tmp->mob.back()->heyid = wxml->Attribute("id");
                }
+               
                wxml = wxml->NextSiblingElement();
        }
        
diff --git a/ttf/FreePixel.ttf b/ttf/FreePixel.ttf
new file mode 100644 (file)
index 0000000..d22b2a2
Binary files /dev/null and b/ttf/FreePixel.ttf differ
index 53e6a3cfc58fc338d80d7fb7fa3fd33e8349d3de..55612d3a3c5f84153734005f19a4ce80e1eb60d7 100644 (file)
@@ -7,12 +7,19 @@
        
        <mob type="1" aggressive="false" />
        
+       <trigger x="-300" id="Test" />
+       
        <npc name="Ralph" hasDialog="true" />
        <npc name="Johnny" hasDialog="true" />
        <structure type="5" inside="playerSpawnHill1_Building1.xml" />
 
 </World>
 
+<Trigger id="Test">It was a dark and stormy night...
+Except it was the middle of the day.
+And it wasn't stormy.
+...</Trigger>
+
 <Dialog name="Ralph">
        
        <text id="0">
 </Dialog>
 
 <Dialog name="Johnny">
-       <text id="0" nextid="1" stop="true">
+       <text id="0" nextid="1" pause="true">
                Sup bro!
                <quest assign="Quest #1" />
        </text>
        
-       <text id="1" >
+       <text id="1" stop="true">
                My name's Johnny.
                <give id="Dank Maymay" count="1" />
        </text>