]> code.bitgloo.com Git - clyne/gamedev.git/commitdiff
Villages!
authordrumsetmonkey <abelleisle@roadrunner.com>
Tue, 23 Feb 2016 12:29:25 +0000 (07:29 -0500)
committerdrumsetmonkey <abelleisle@roadrunner.com>
Tue, 23 Feb 2016 12:29:25 +0000 (07:29 -0500)
12 files changed:
1  2 
assets/style/classic/bg/bgWoodTile.png
assets/style/classic/bg/forestTileFar.png
assets/style/rustic/bg/bgWoodTile.png
assets/style/rustic/bg/forestTileFar.png
include/common.h
include/ui.h
include/world.h
main.cpp
src/entities.cpp
src/ui.cpp
src/world.cpp
xml/playerSpawnHill1.xml

index 0000000000000000000000000000000000000000,0000000000000000000000000000000000000000..5b631bfbecb53de73c0393d7fbe6ef94b741b56a
new file mode 100644 (file)
Binary files differ
index 0000000000000000000000000000000000000000,0000000000000000000000000000000000000000..241e47962aedcd5243c310d80837ef12d0d139d2
new file mode 100644 (file)
Binary files differ
index 0000000000000000000000000000000000000000,0000000000000000000000000000000000000000..5b631bfbecb53de73c0393d7fbe6ef94b741b56a
new file mode 100644 (file)
Binary files differ
index 0000000000000000000000000000000000000000,0000000000000000000000000000000000000000..241e47962aedcd5243c310d80837ef12d0d139d2
new file mode 100644 (file)
Binary files differ
index f141afd34d4a63d05dab424ebc4b0622f71accfb,34260c95403cb18042703dd36e2af6c0378b3556..a99e3529421c3a9e179ec449275f7b46eb30805c
@@@ -16,7 -16,6 +16,8 @@@
  #include <string>
  #include <fstream>    
  #include <thread>
 +#include <mutex>
++#include <future>
  
  #define GLEW_STATIC
  #include <GL/glew.h>
diff --cc include/ui.h
index 8d479a4c57293296982f3c00c9e9d6966b1f2ce4,ccc16af8f802b99b939ff40a2704d3e5deec20af..a3084eb0f43debcf275f61115ec51b9390f104bf
@@@ -50,6 -50,6 +50,12 @@@ public
        std::vector<menuItem>items;
        Menu *child;
        Menu *parent;
++      ~Menu(){
++              child = NULL;
++              parent = NULL;
++              delete child;
++              delete parent;
++      }
  
        void gotoChild();
        void gotoParent();
@@@ -147,6 -146,6 +153,7 @@@ namespace ui 
        */
        
        void importantText(const char *text,...);
++      void passiveImportantText(int duration,const char *text,...);
        
        /*
         *      Draw various UI elements (dialogBox, player health)
diff --cc include/world.h
index edf7ebbc760aed4379698c05b7791d51850a28bc,48ab40969a8f2810f510e605a453a927b135953e..f9e952e7d5fe3fe35b282b420b44f1416febcdac
@@@ -81,23 -81,6 +81,26 @@@ typedef struct line_t 
        unsigned char color;    /**< Lightness of dirt (brown) */
  } line_t;
  
-       std::vector<std::shared_ptr<Entity>>     entity;
-       std::vector<std::shared_ptr<Structures>> build;
-       std::vector<std::shared_ptr<NPC>>                npc;
 +/*
 + * Handle all logic that has to do with villages
 + */
 +
 +
 +struct Village{
 +      std::string name;
++      vec2 start;
++      vec2 end;
++      bool in;
 +
++      std::vector<Structures *> build;
 +      Village(const char *meme){
 +              name = meme;
++              end.x = -0xffffffff;
++              start.x = 0xffffffff;
++              in = false;
 +      }
 +};
 +
  /**
   * The world class. This class does everything a world should do.
   */
diff --cc main.cpp
index eb53c9936f39b7ed561bf791c0c69c0d26a56f72,805fa000af09239faa37ba853071e4fdb3fe92ad..ecff5c6755ce4aaef8a7e9abc9d2cd22707e4fdf
+++ b/main.cpp
@@@ -569,7 -573,7 +574,8 @@@ void render()
        glMatrixMode(GL_PROJECTION);
        glPushMatrix();
        glLoadIdentity();
-       glOrtho((offset.x-SCREEN_WIDTH/2),(offset.x+SCREEN_WIDTH/2),(offset.y-SCREEN_HEIGHT/2),(offset.y+SCREEN_HEIGHT/2),-1,1);
++      // glOrtho((offset.x-SCREEN_WIDTH/2),(offset.x+SCREEN_WIDTH/2),(offset.y-SCREEN_HEIGHT/2),(offset.y+SCREEN_HEIGHT/2),-1,1);
+       glOrtho(floor(offset.x-SCREEN_WIDTH/2),floor(offset.x+SCREEN_WIDTH/2),floor(offset.y-SCREEN_HEIGHT/2),floor(offset.y+SCREEN_HEIGHT/2),-1,1);
        glMatrixMode(GL_MODELVIEW);
        glPushMatrix();
        glLoadIdentity();
index e020f8b64fa461aff9a9423d516d8e43e174a842,71a0890aa9fae8f9ebed06913f539e8eed185bda..922a07c97fcce59192871ea6bbb67a5784bfbc21
@@@ -62,7 -62,7 +62,7 @@@ void Entity::spawn(float x, float y){ /
        right   = true;
        left    = false;
        near    = false;
--      canMove = true;
++      //canMove       = true;
        ground  = false;
        hit     = false;
        
@@@ -88,6 -88,6 +88,8 @@@ Player::Player(){ //sets all of the pla
        subtype = 0;    
        health = maxHealth = 100;
        speed = 1;
++      canMove = true;
++
        tex = new Texturec(9,   "assets/player/playerk.png",
                                                        "assets/player/playerk1.png",
                                                        "assets/player/playerk2.png",
@@@ -115,6 -115,6 +117,7 @@@ NPC::NPC(){        //sets all of the NPC speci
        health = maxHealth = 100;
        
        maxHealth = health = 100;
++      canMove = true;
        
        tex = new Texturec(1,"assets/NPC.png");
        inv = new Inventory(NPC_INV_SIZE);
@@@ -141,6 -141,6 +144,7 @@@ Structures::Structures(){ //sets the st
        name = NULL;
        
        inv = NULL;
++      canMove = false;
  }
  Structures::~Structures(){
        delete tex;
@@@ -155,6 -155,6 +159,7 @@@ Mob::Mob(int sub)
        aggressive = false;
        
        maxHealth = health = 50;
++      canMove = true;
        
        switch((subtype = sub)){
        case MS_RABBIT:
@@@ -198,6 -198,6 +203,7 @@@ Object::Object()
        near = false;
        width  = 0;
        height = 0;
++      canMove = false;
  
        maxHealth = health = 1;
        
@@@ -267,7 -267,7 +273,7 @@@ void Entity::draw(void){           //draws the e
        switch(type){
        case PLAYERT:
                static int texState = 0;
--              if(speed && !(loops % (int)(2.0f/(float)speed))){
++              if(speed && !(loops % ((2.0f/speed) < 1 ? 1 : (int)((float)2.0f/(float)speed)))){
                        if(++texState==9)texState=1;
                        glActiveTexture(GL_TEXTURE0);
                        tex->bind(texState);
diff --cc src/ui.cpp
index 43706e77812d5ea79303bf520d72f2369fea0261,2d0045348c29cf56f030049cd5216a99d3473578..6e616a7576908df733b0307d68b55843c1c4d6e4
@@@ -113,8 -114,6 +113,9 @@@ namespace ui 
        
        bool debug=false;
        bool posFlag=false;
 +      bool dialogPassive = false;
++      int dialogPassiveTime = 0;
 +
        
        /*
         *      Dialog stuff that needs to be 'public'.
                dialogImportant = true;
                //toggleBlack();
        }
++      void passiveImportantText(int duration, const char *text,...){
++              va_list textArgs;
++
++              //if(!player->ground)return;
++
++              memset(dialogBoxText,0,512);
++
++              va_start(textArgs,text);
++              vsnprintf(dialogBoxText,512,text,textArgs);
++              va_end(textArgs);
++
++              dialogBoxExists = true;
++              dialogImportant = true;
++              dialogPassive = true;
++              dialogPassiveTime = duration;
++      }
++
++
        void draw(void){
                unsigned char i;
                float x,y,tmp;
                        
                        if(dialogImportant){
                                setFontColor(255,255,255);
 -                              if(fadeIntensity == 255){
++                              if(dialogPassive){
++                                      dialogPassiveTime -= deltaTime;
++                                      if(dialogPassiveTime < 0){
++                                              dialogPassive = false;
++                                              dialogImportant = false;
++                                              dialogBoxExists = false;
++                                      }
++                              }
 +                              if(fadeIntensity == 255 || dialogPassive){
                                        setFontSize(24);
                                        putStringCentered(offset.x,offset.y,rtext);
 +                                      setFontSize(16);
                                }
                        }else{
                        
        }
  
        void quitGame(){
++              dialogBoxExists = false;
++              currentMenu = NULL;
++              delete[] currentMenu;
                gameRunning = false;
                updateConfig();
                saveConfig();
diff --cc src/world.cpp
index d039bca858e1894c82457c4e4e0cd7298be5e23d,51efaf2a193c79acf80888d002947e25c60bcc4c..6e72328325c9f2ae49b120ebb728f93edce29c94
@@@ -82,18 -95,18 +82,18 @@@ void World::setStyle(const char* pre)
        for(uint i = 0; i < arrAmt(buildPaths);i++){
                sTexLoc.push_back(prefix);
                sTexLoc.back() += buildPaths[i];
--              std::cout << sTexLoc.back() << std::endl;
++              //std::cout << sTexLoc.back() << std::endl;
        }
        prefix += "bg/";
        for(uint i = 0; i < arrAmt(bgPaths[0]);i++){
                bgFiles.push_back(prefix);
                bgFiles.back() += bgPaths[0][i];
--              std::cout << bgFiles.back() << std::endl;
++              //std::cout << bgFiles.back() << std::endl;
        }
        for(uint i = 0; i < arrAmt(bgPaths[1]);i++){
                bgFilesIndoors.push_back(prefix);
                bgFilesIndoors.back() += bgPaths[1][i];
--              std::cout << bgFilesIndoors.back() << std::endl;
++              //std::cout << bgFilesIndoors.back() << std::endl;
        }
  }
  
@@@ -940,17 -952,13 +937,13 @@@ void World::singleDetect(Entity *e)
  }
  
  void World::detect(Player *p){
-       //static std::thread villageThread;
--      World *hey = this;
        
        /*
         *      Handle the player. 
        */
        
--      singleDetect(p);
-       //villageLogic(this);
-       //villageThread = std::thread(villageLogic, this);
++      //auto pl = std::async(&World::singleDetect,this,p);
++      std::thread(&World::singleDetect,this, p).detach();
                
        /*
         *      Handle all remaining entities in this world. 
        
  //LOOOOP:
        static int what = 0;
--      for(auto &e : hey->entity)
--              hey->singleDetect(e);
++      for(auto &e : entity)
++              std::thread(&World::singleDetect,this,e).detach();
++              //hey->singleDetect(e);
        for(auto &part : particles){
                int l;
                unsigned int i;
                }
                what++;
        }what=0;
 +      for(auto &b : build){
 +              switch(b->bsubtype){
 +                      case FOUNTAIN:
 +                              for(int r = 0; r < (rand()%25)+10;r++){
 +                                      addParticle(    rand()%HLINE*3 + b->loc.x + b->width/2,
 +                                                                                              b->loc.y + b->height, 
 +                                                                                              HLINE*1.25,
 +                                                                                              HLINE*1.25, 
 +                                                                                              rand()%2 == 0?-(rand()%7)*.01:(rand()%7)*.01,
 +                                                                                              ((4+rand()%6)*.05), 
 +                                                                                              {0,0,255}, 
 +                                                                                              2500);
 +
 +                                      particles.back()->fountain = true;
 +                              }
 +                              break;
 +                      case FIRE_PIT:
 +                              for(int r = 0; r < (rand()%20)+10;r++){
 +                                      addParticle(rand()%(int)(b->width/2) + b->loc.x+b->width/4, b->loc.y+3*HLINE, HLINE, HLINE, rand()%2 == 0?-(rand()%3)*.01:(rand()%3)*.01,((4+rand()%6)*.005), {255,0,0}, 400);
 +                                      particles.back()->gravity = false;
 +                                      particles.back()->behind = true;
 +                              }
 +                              break;
 +                      default: break;
 +              }
 +      }
 +
++      for(auto &v : village){
++              if(p->loc.x > v.start.x && p->loc.x < v.end.x){
++                      if(!v.in){
++                              ui::passiveImportantText(5000,"Welcome to %s",v.name.c_str());
++                              v.in = true;
++                      }
++              }else{
++                      v.in = false;
++              }
++      }
++
        /*if(hey->infront){
                hey = hey->infront;
                goto LOOOOP;
        }*/
-       //villageThread.join();
  }
++
  void World::addStructure(BUILD_SUB sub, float x,float y, char *tex, const char *inside){
        build.push_back(new Structures());
        build.back()->inWorld = this;
@@@ -1494,12 -1474,20 +1499,21 @@@ char *currentXML = NULL
  extern World *currentWorld;
  
  World *loadWorldFromXML(const char *path){
+       if(currentXML){
+               currentWorld->save();
+               delete[] currentXML;
+       }
+       
+       return loadWorldFromXMLNoSave(path);
+ }
+ World *loadWorldFromXMLNoSave(const char *path){
        XMLDocument xml;
        XMLElement *wxml;
 +      XMLElement *vil;
        
        World *tmp;
--      float spawnx;
++      float spawnx, randx;
        bool dialog,Indoor;
        
        const char *ptr,*name;
                        tmp->addMob(MS_TRIGGER,wxml->FloatAttribute("x"),0,commonTriggerFunc);
                        tmp->mob.back()->heyid = wxml->Attribute("id");
                }
 -              
 +
                wxml = wxml->NextSiblingElement();
        }
-                                                          vil->QueryFloatAttribute("x",&spawnx) != XML_NO_ERROR ? 
-                                                                               getRand() % tmp->getTheWidth() / 2.0f : 
-                                                                               spawnx,
 +
++      if(vil){
++              tmp->village.push_back(vil->Attribute("name"));
++
++              vil = vil->FirstChildElement();
++      }
++
 +      while(vil){
 +              name = vil->Name();
++              randx = getRand() % tmp->getTheWidth() - (tmp->getTheWidth() / 2.0f);
++
++              /**
++               *      READS DATA ABOUT STRUCTURE CONTAINED IN VILLAGE
++               */
 +              if(!strcmp(name,"structure")){
 +                      ptr = vil->Attribute("inside");
 +                      tmp->addStructure((BUILD_SUB)vil->UnsignedAttribute("type"),
-                       //tmp->village.back().build.push_back(tmp->build.back());
++                                                         vil->QueryFloatAttribute("x", &spawnx) != XML_NO_ERROR ? 
++                                                         randx : spawnx,
 +                                                         100,
 +                                                         (char*)vil->Attribute("texture"),
 +                                                         ptr);
 +
++                      tmp->village.back().build.push_back(tmp->build.back());
++              }
++              if(tmp->village.back().build.back()->loc.x < tmp->village.back().start.x){
++                      tmp->village.back().start.x = tmp->village.back().build.back()->loc.x;
 +              }
++              if(tmp->village.back().build.back()->loc.x + tmp->village.back().build.back()->width > tmp->village.back().end.x){
++                      tmp->village.back().end.x = tmp->village.back().build.back()->loc.x + tmp->village.back().build.back()->width;
++              }
++
++              //go to the next element in the village block
 +              vil = vil->NextSiblingElement();
 +      }
        
        std::ifstream dat (((std::string)currentXML + ".dat").c_str());
        if(dat.good()){
index b0fb163e6b841681b44ab1bd2bebea4e023db965,c5e736b960df556e200c785357dc466b29475940..269b393ffe0c6969ab399ae57a5c015e9ea238ca
        
        <npc name="Ralph" hasDialog="true" />
        <npc name="Johnny" hasDialog="false" />
--      <structure type="5" inside="playerSpawnHill1_Building1.xml" />
++      <!-- <structure type="5" inside="playerSpawnHill1_Building1.xml" /> -->
 +      <village name="Meme-Town">
-               <structure type="0" inside="playerSpawnHill1_Building1.xml" />
-               <structure type="5" inside="playerSpawnHill1_Building1.xml" />
++              <structure type="0" x="-100" inside="playerSpawnHill1_Building1.xml"/>
++              <structure type="5" x="-500" inside="playerSpawnHill1_Building1.xml"/>
 +      </village>
  
  </World>