]> code.bitgloo.com Git - clyne/gamedev.git/commitdiff
entity following
authorClyne Sullivan <tullivan99@gmail.com>
Fri, 4 Mar 2016 13:45:53 +0000 (08:45 -0500)
committerClyne Sullivan <tullivan99@gmail.com>
Fri, 4 Mar 2016 13:45:53 +0000 (08:45 -0500)
14 files changed:
Changelog
Makefile
include/common.h
include/entities.h
main.cpp
src/Quest.cpp
src/Texture.cpp
src/common.cpp
src/entities.cpp
src/gameplay.cpp
src/inventory.cpp
src/ui.cpp
src/world.cpp
xml/playerSpawnHill1.xml

index f6309bf4a2bc215aeb0a866fc54b8b0ff57b964a..624281e33467bbde5710ab065fef483363f0a911 100644 (file)
--- a/Changelog
+++ b/Changelog
        - added StrAttribute() to TinyXML2
        - more merchant stuff, trading????
        - improved village XML loading
+
+3/4/2016:
+=========
+
+       - added following functionality to entities
+       - fixed some world shading issues
+       - re-added stars, but stars draw midday
+       - restarted work on arenas
+       - began implementing currency system
+       - made the moon!
+       - merchants are a-o-kay
index 1df683c0d8e8be6463ea31eb4c8f4b95feda70ee..db9226097bc1421e754208c875ab7971b728804b 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -12,9 +12,9 @@ ifeq ($(TARGET_OS),win32)
               -lSDL2main -lSDL2 -lSDL2_image -lSDL2_mixer -lfreetype
 endif
 
-CXXFLAGS = -m$(TARGET_BITS) -std=c++11
+CXXFLAGS = -m$(TARGET_BITS) -std=c++14
 CXXINC   = -Iinclude -Iinclude/freetype2
-CXXWARN  = -Wall -Wextra -Werror
+CXXWARN  = -Wall -Wextra -Werror -pedantic-errors
 
 CXXSRCDIR = src
 CXXOUTDIR = out
@@ -32,7 +32,10 @@ clean:
        rm -f $(EXEC)
        rm -f out/*.o
 
-$(EXEC): $(CXXOUTDIR)/$(CXXOBJ)
+cleandata:
+       rm -rf xml/*.dat
+
+$(EXEC): $(CXXOUTDIR)/$(CXXOBJ) main.cpp
        @echo "  CXX/LD  main"
        @$(CXX) $(CXXFLAGS) $(CXXINC) $(CXXWARN) -o $(EXEC) main.cpp out/*.o $(LIBS)
 
index 9650f4993fb6cc9366b8e5084e22047c2347f0d8..58d561fe6c2ba260330be23510a6bc2ff1940dba 100644 (file)
@@ -8,16 +8,17 @@
 #ifndef COMMON_H
 #define COMMON_H
 
+// holy moly
 #include <iostream>
 #include <cstdlib>
 #include <string>
 #include <vector>
-#include <math.h>
 #include <string>
 #include <fstream>     
 #include <thread>
 #include <mutex>
 #include <future>
+#include <math.h>
 #include <threadpool.h>
 
 #define GLEW_STATIC
@@ -47,7 +48,7 @@ N abso(N v){
                return v;
 }
 
-extern GLuint colorIndex;
+extern GLuint colorIndex;      // Texture.cpp?
 
 /**
  * This structure contains a set of coordinates for ease of coding.
@@ -104,7 +105,7 @@ typedef col Color;
  * Define the game's name (displayed in the window title).
  */
 
-#define GAME_NAME              "Independent Study v.0.5 alpha - NOW WITH SOUND!"
+#define GAME_NAME              "Independent Study v.0.6 alpha - NOW WITH more c++"
 
 /**
  * The desired width of the game window.
index 334bfeb101066b0cba07b46a0f3a1535cb2438e2..c10bcd4a489a6da7ce51158b0fd4ebd6db7d8d4d 100644 (file)
@@ -132,6 +132,7 @@ void initEntity();
 
 class Entity{
 public:
+       Entity *followee;
        Inventory *inv;
 
        /*
@@ -186,6 +187,8 @@ public:
        
        virtual void wander(int){}
        virtual void interact(){}
+
+       void follow(Entity *e);
        
        virtual ~Entity(){}
 };
index e96a5557235c53f6d79cc7261638657b65fc7731..a9b172b928a2d20fb4507c02a4730e203c0e4c69 100644 (file)
--- a/main.cpp
+++ b/main.cpp
@@ -164,10 +164,10 @@ Menu pauseMenu;
 
 extern WorldWeather weather;
 
-extern int  fadeIntensity;
-extern bool fadeEnable;
-extern bool fadeWhite;
-extern bool fadeFast;
+extern int  fadeIntensity;     // ui.cpp
+extern bool fadeEnable;                // ui.cpp
+extern bool fadeWhite;         // ui.cpp
+extern bool fadeFast;          // ui.cpp
 
 unsigned int SCREEN_WIDTH;
 unsigned int SCREEN_HEIGHT;
@@ -216,7 +216,7 @@ int main(int argc, char *argv[]){
        
        static SDL_GLContext mainGLContext = NULL;
        
-       gameRunning=false;
+       gameRunning = false;
 
        /**
         * (Attempt to) Initialize SDL libraries so that we can use SDL facilities and eventually
@@ -420,6 +420,8 @@ int main(int argc, char *argv[]){
        ****     GAMELOOP      ****
        **************************/
        
+       //currentWorld->mob.back()->followee = player;
+       
        gameRunning = true;
        while(gameRunning){
                mainLoop();
@@ -482,6 +484,7 @@ void mainLoop(void){
         */
 
        prev = currentWorld;
+       
 
        //pool.Enqueue(ui::handleEvents);
        ui::handleEvents();
@@ -490,13 +493,13 @@ void mainLoop(void){
                currentWorld->bgmPlay(prev);
                ui::dialogBoxExists = false;
        }
-    
+
        if(prevPrevTime + MSEC_PER_TICK <= currentTime){
                //pool.Enqueue(logic);
                logic();
                prevPrevTime = currentTime;
        }
-       
+
        /*
         * Update player and entity coordinates.
         */
@@ -902,36 +905,11 @@ void logic(){
                        }
                }
        }
-       /*for(auto &b : currentWorld->build){
-               switch(b->bsubtype){
-                       case FOUNTAIN:
-                               for(int r = 0; r < (rand()%25)+10;r++){
-                                       currentWorld->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);
-
-                                       currentWorld->particles.back()->fountain = true;
-                               }
-                               break;
-                       case FIRE_PIT:
-                               for(int r = 0; r < (rand()%20)+10;r++){
-                                       currentWorld->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);
-                                       currentWorld->particles.back()->gravity = false;
-                                       currentWorld->particles.back()->behind = true;
-                               }
-                               break;
-                       default: break;
-               }
-       }*/
        
        /*
         *      Switch between day and night (SUNNY and DARK) if necessary.
-       */
+        */
+        
        if(!(tickCount%DAY_CYCLE)||!tickCount){
                if ( weather == WorldWeather::Sunny )
                        weather = WorldWeather::Dark;
index e59d79f76fb630d8351f4d1587df4cf2a53accb9..8f3c33bdea71c00fb59c313c4b37813a809faaca 100644 (file)
@@ -1,5 +1,6 @@
-#include <Quest.h>\r
+#include <algorithm>\r
 \r
+#include <Quest.h>\r
 #include <entities.h>\r
 \r
 extern Player *player;\r
@@ -33,8 +34,6 @@ int QuestHandler::assign(std::string title,std::string desc,std::string req){
        return 0;\r
 }\r
 \r
-#include <algorithm>\r
-\r
 int QuestHandler::drop(std::string title){\r
        current.erase( std::remove_if( current.begin(),\r
                                                                   current.end(),\r
index 731a1d66ae7a1f1dc5e740b85fa4cd0866ef6bfa..ed93af99325f2fb1593c4489bc0391f46f9d2119 100644 (file)
@@ -7,11 +7,11 @@
  * A structure for keeping track of loaded textures.
  */
 
-struct texture_t {
+typedef struct {
        std::string name;       /**< The file path of the texture.              */
        GLuint tex;                     /**< The GLuint for the loaded texture. */
        dim2 dim;                       /**< The dimensions of the texture.             */
-};
+} texture_t;
 
 struct index_t {
        Color color;
@@ -26,7 +26,7 @@ struct index_t {
  * this array and reuse GLuint's to save memory.
  */
 
-static std::vector<struct texture_t> LoadedTexture;
+static std::vector<texture_t> LoadedTexture;
 
 namespace Texture{
        Color pixels[8][4];
@@ -81,7 +81,7 @@ namespace Texture{
                                         );
                
                // add texture to LoadedTexture
-               LoadedTexture.push_back((struct texture_t){fileName,object,{image->w,image->h}});               
+               LoadedTexture.push_back(texture_t{fileName,object,{image->w,image->h}});                
                
                // free the SDL_Surface
                SDL_FreeSurface(image);
index 6dc2c46816fa61b6b2c1c59ddf3e3f3174f7c239..1c9c2b539e0865dc25ef8af9274dae2073a2854f 100644 (file)
@@ -1,15 +1,16 @@
-#include <common.h>
 #include <cstring>
 #include <cstdio>
 #include <chrono>
 
 #ifndef __WIN32__
-#include <sys/types.h>
-#include <dirent.h>
-#include <errno.h>
-#include <vector>
+#      include <sys/types.h>
+#      include <dirent.h>
+#      include <errno.h>
+#      include <vector>
 #endif // __WIN32__
 
+#include <common.h>
+
 #ifndef __WIN32__
 
 unsigned int millis(void){
@@ -79,7 +80,7 @@ const char *readFile(const char *path){
        std::ifstream in (path,std::ios::in);
        unsigned int size;
        GLchar *buf;
-       
+               
        if(!in.is_open()){
                std::cout<<"Error reading file "<<path<<"!"<<std::endl;
                abort();
@@ -101,30 +102,3 @@ UserError( std::string reason )
     std::cout << "User error: " << reason << "!" << std::endl;
     abort();
 }
-
-/*int strCreateFunc(const char *equ){
-       static unsigned int size;
-       static char *filebuf;
-       static FILE *file;
-       
-       size = 57 + strlen(equ) + 3;
-       
-       filebuf = new char[size];
-       memset(filebuf,0,size);
-       
-       strcpy(filebuf,"#include <stdio.h>\n#include <math.h>\nint main(){return ");
-       strcat(filebuf,equ);
-       strcat(filebuf,";}");
-       
-       if(!(file = fopen("gen.tmp","w"))){
-               abort();
-       }
-       
-       fwrite(filebuf,size,sizeof(char),file);
-       delete[] filebuf;
-       fclose(file);
-       
-       system("
-       
-       return 0;
-}*/
index 5c60386b886d34eca713e3ed488149009e5b5b7a..73105f14cafe71a89c18e7895324442b56202d7a 100644 (file)
@@ -1,20 +1,37 @@
-#include <entities.h>
-#include <ui.h>
-
 #include <istream>
 
-#define RAND_DIALOG_COUNT 14
+#include <entities.h>
+#include <ui.h>
 
 extern std::istream *names;
-extern unsigned int loops;
 
-extern World *currentWorld;
+extern Player *player;                 // main.cpp
+extern World *currentWorld;            // main.cpp
+extern unsigned int loops;             // main.cpp
 
-extern Player *player;
+GLuint waterTex;
 
-extern const char *itemName;
+std::vector<int (*)(NPC *)> AIpreload; // A dynamic array of AI functions that are being preloaded
+std::vector<NPC *> AIpreaddr;                  // A dynamic array of pointers to the NPC's that are being assigned the preloads
 
-GLuint waterTex;
+#define RAND_DIALOG_COUNT 14
+
+const char *randomDialog[RAND_DIALOG_COUNT] = {
+       "What a beautiful day it is.",
+       "Have you ever went fast? I have.",
+       "I heard if you complete a quest, you'll get a special reward.",
+       "How much wood could a woodchuck chuck if a woodchuck could chuck wood?",
+       "I don\'t think anyone has ever been able to climb up that hill.",
+       "If you ever see a hole in the ground, watch out; it could mean the end for you.",
+       "Did you know this game has over 5000 lines of code? I didn\'t. I didn't even know I was in a game until now...",
+       "HELP MY CAPS LOCK IS STUCK",
+       "You know, if anyone ever asked me who I wanted to be when I grow up, I would say Abby Ross.",
+       "I want to have the wallpaper in our house changed. It doesn\'t really fit the environment.",
+       "Frig.",
+       "The sine of theta equals the opposite over the hypotenuese.",
+       "Did you know the developers spelt brazier as brazzier.",
+       "My dad once said to me, \"Boy, you are in a game.\" I never knew what he meant by that."
+};
 
 void initEntity(){
        waterTex = Texture::loadTexture("assets/waterTex.png");
@@ -78,6 +95,8 @@ void Entity::spawn(float x, float y){ //spawns the entity you pass to it based o
        
        name = new char[32];
        getRandomName(this);
+       
+       followee = NULL;
 }
 
 Player::Player(){ //sets all of the player specific traits on object creation
@@ -360,43 +379,39 @@ NOPE:
        if(near)ui::putStringCentered(loc.x+width/2,loc.y-ui::fontSize-HLINE/2,name);
 }
 
-/*
- *     NPC::wander, this makes the npcs wander around the near area
- *
- *     timeRun                                 This variable is the amount of gameloop ticks the entity will wander for
-*/
+/**
+ * Handles NPC movement, usually just random walking.
+ */
 
-void NPC::wander(int timeRun){
-       
-       /*
-        *      Direction is the variable that decides what direction the entity will travel in
-        *      the value is either -1, 0, or 1. -1 being left, 0 means that the npc will stay still
-        *      and a value of 1 makes the entity move to the right
-       */
-       
+void NPC::
+wander( int timeRun )
+{
        static int direction;
        
-       /*
-        *      Ticks to use is a variable in the entity class that counts the total ticks that need to be used
-        *
-        *      This loop only runs when ticksToUse is 0, this means that the speed, direction, etc... Will be
-        *      calculated only after the npc has finished his current walking state
-       */
-       
-       if(ticksToUse == 0){
+       if ( followee ) {
+               if ( loc.x < followee->loc.x - 40 )
+                       direction = 1;
+               else if ( loc.x > followee->loc.x + 40 )
+                       direction = -1;
+               else
+                       direction = 0;
+               
+               vel.x = .018 * HLINE * direction;
+       } else if ( ticksToUse == 0 ) {
                ticksToUse = timeRun;
-               vel.x = .008*HLINE;                                     //sets the inital velocity of the entity
-               direction = (getRand() % 3 - 1);        //sets the direction to either -1, 0, 1
-                                                                                       //this lets the entity move left, right, or stay still
-               if(direction==0)ticksToUse*=2;
-               vel.x *= direction;                                     //changes the velocity based off of the direction
+               
+               vel.x = .008 * HLINE;
+               direction = (getRand() % 3 - 1);
+               
+               if ( direction == 0 )
+                       ticksToUse *= 2;
+               
+               vel.x *= direction;
        }
-       ticksToUse--;                                                    //removes one off of the entities timer
+       
+       ticksToUse--;
 }
 
-std::vector<int (*)(NPC *)> AIpreload; // A dynamic array of AI functions that are being preloaded
-std::vector<NPC *> AIpreaddr;                  // A dynamic array of pointers to the NPC's that are being assigned the preloads
-
 void NPC::addAIFunc(int (*func)(NPC *),bool preload){
        if(preload){                                                                            // Preload AI functions so that they're given after 
                                                                                                                // the current dialog box is closed
@@ -410,23 +425,6 @@ void NPC::clearAIFunc(void){
        aiFunc.clear();
 }
 
-const char *randomDialog[RAND_DIALOG_COUNT] = {
-       "What a beautiful day it is.",
-       "Have you ever went fast? I have.",
-       "I heard if you complete a quest, you'll get a special reward.",
-       "How much wood could a woodchuck chuck if a woodchuck could chuck wood?",
-       "I don\'t think anyone has ever been able to climb up that hill.",
-       "If you ever see a hole in the ground, watch out; it could mean the end for you.",
-       "Did you know this game has over 5000 lines of code? I didn\'t. I didn't even know I was in a game until now...",
-       "HELP MY CAPS LOCK IS STUCK",
-       "You know, if anyone ever asked me who I wanted to be when I grow up, I would say Abby Ross.",
-       "I want to have the wallpaper in our house changed. It doesn\'t really fit the environment.",
-       "Frig.",
-       "The sine of theta equals the opposite over the hypotenuese.",
-       "Did you know the developers spelt brazier as brazzier.",
-       "My dad once said to me, \"Boy, you are in a game.\" I never knew what he meant by that."
-};
-
 void NPC::interact(){ //have the npc's interact back to the player
        int (*func)(NPC *);
        loc.y += 5;
@@ -468,6 +466,12 @@ void Object::interact(void){
        }
 }
 
+void Entity::
+follow( Entity *e )
+{
+       followee = e;
+}
+
 /*
  *     This spawns the structures
  *
@@ -530,12 +534,25 @@ void Mob::wander(int timeRun){
        static unsigned int heya=0,hi=0;
        static bool YAYA = false;
        
+       if ( followee ) {
+               if ( loc.x < followee->loc.x - 40 )
+                       direction = 1;
+               else if ( loc.x > followee->loc.x + 40 )
+                       direction = -1;
+               else
+                       direction = 0;
+               
+               vel.x = .018 * HLINE * direction;
+               return;
+       }
+       
        if(aggressive && !YAYA &&
           player->loc.x + (width / 2)  > loc.x && player->loc.x + (width / 2)  < loc.x + width  &&
           player->loc.y + (height / 3) > loc.y && player->loc.y + (height / 3) < loc.y + height ){
                Arena *a = new Arena(currentWorld,player,this);
                a->setBackground( WorldBGType::Forest );
                a->setBGM("assets/music/embark.wav");
+               
                ui::toggleWhiteFast();
                YAYA = true;
                ui::waitForCover();
@@ -646,7 +663,7 @@ void Player::sspawn(float x,float y){
                        std::getline(data,ddata);
                        count = std::stoi(ddata);
                        std::getline(data,ddata);
-                       inv->items.push_back((item_t){count,(uint)std::stoi(ddata)});
+                       inv->items.push_back(item_t{count,(uint)std::stoi(ddata)});
                }
                
                std::getline(data,ddata);
index a286db95a62505ed816046dca11f6d3fe07a12c8..06240679174de1eb10f60f6ffe0b950b90b1f9c3 100644 (file)
@@ -4,30 +4,28 @@
 #include <ui.h>
 
 #include <tinyxml2.h>
-
 using namespace tinyxml2;
 
-extern World   *currentWorld;
-extern Player  *player;
+extern Player  *player;                                                // main.cpp
+extern World   *currentWorld;                                  // main.cpp
 
-extern float shit;
-extern MenucurrentMenu;
-extern Menu pauseMenu;
-extern Menu optionsMenu;
+extern float  shit;
+extern Menu  *currentMenu;
+extern Menu   pauseMenu;
+extern Menu   optionsMenu;
 
-extern void mainLoop(void);
+extern void mainLoop(void);                                            // main.cpp
 
-void segFault(){
-       (*((int *)NULL))++;
-}
+extern std::vector<NPC *> AIpreaddr;                   // entities.cpp
+extern std::vector<int (*)(NPC *)> AIpreload;  // entities.cpp
 
+std::vector<XMLElement *> dopt;
 
-typedef struct {
-       NPC *npc;
-       unsigned int index;
-} NPCDialog;
+void destroyEverything(void);
 
-std::vector<XMLElement *> dopt;
+void segFault(){
+       (*((int *)NULL))++;
+}
 
 int commonAIFunc(NPC *speaker){
        XMLDocument xml;
@@ -252,7 +250,6 @@ void commonTriggerFunc(Mob *callee){
        }
 }
 
-void destroyEverything(void);
 void initEverything(void){
        std::vector<std::string> xmlFiles;
        XMLDocument xml;
@@ -314,9 +311,6 @@ void initEverything(void){
        atexit(destroyEverything);
 }
 
-extern std::vector<int (*)(NPC *)> AIpreload;
-extern std::vector<NPC *> AIpreaddr;
-
 void destroyEverything(void){
        currentWorld->save();
        delete currentWorld;
index 203e7076b5d6a37c702e65645175ccfe3a8fb882..7400f8904e691b18acb83e4b296fbba527d3ff84 100644 (file)
@@ -14,6 +14,8 @@ static vec2 itemLoc;
 Mix_Chunk* swordSwing;
 
 static std::vector<Item *> itemMap;
+static GLuint *itemtex;
+void itemDraw(Player *p,uint id);
 
 void items(void){
        XMLDocument xml;
@@ -44,7 +46,7 @@ int Inventory::addItem(std::string name,uint count){
                                        return 0;
                                }
                        }
-                       items.push_back((item_t){count,i});
+                       items.push_back( item_t { count, i });
                        return 0;
                }
        }
@@ -108,9 +110,6 @@ int Inventory::hasItem(std::string name){
        return 0;
 }
 
-static GLuint *itemtex;
-void itemDraw(Player *p,uint id);
-
 void initInventorySprites(void){
        
        items();
index c755a59d0f1ad9f8cb72a9943db1b6611297a6f5..7333fc48a4acc7fab51554f0b8d7b6b4c2e5d889 100644 (file)
@@ -190,7 +190,7 @@ namespace ui {
        
        void setFontSize(unsigned int size){
                unsigned int i,j;
-               char *buf;
+               unsigned char *buf;
                
                fontSize=size;
                FT_Set_Pixel_Sizes(ftf,0,fontSize);
@@ -230,7 +230,7 @@ namespace ui {
                         *      making it white-on-black.
                        */
                        
-                       buf = new char[ftf->glyph->bitmap.width * ftf->glyph->bitmap.rows * 4];
+                       buf = new unsigned char[ftf->glyph->bitmap.width * ftf->glyph->bitmap.rows * 4];
                
                        for(j=0;j<ftf->glyph->bitmap.width*ftf->glyph->bitmap.rows;j++){
                                buf[j*4  ]=255;//fontColor[0];
@@ -1084,7 +1084,8 @@ namespace ui {
        }
 
        void takeScreenshot(GLubyte* pixels){
-               GLubyte bgr[SCREEN_WIDTH*SCREEN_HEIGHT*3];
+               std::vector<GLubyte> bgr (SCREEN_WIDTH * SCREEN_HEIGHT * 3, 0);
+               
                for(uint x = 0; x < SCREEN_WIDTH*SCREEN_HEIGHT*3; x+=3){
                        bgr[x] = pixels[x+2];
                        bgr[x+1] = pixels[x+1];
index bef6fc0d191932b6e1158cb70bc38e42857c1b16..5dbbe21b5e73b24f3747a04d9033c7705ddabf89 100644 (file)
@@ -1,8 +1,12 @@
 #include <algorithm>
+#include <sstream>
 
 #include <world.h>
 #include <ui.h>
 
+#include <tinyxml2.h>
+using namespace tinyxml2;
+
 /**
  * Defines how many HLINEs tall a blade of grass can be.
  */
 #define INDOOR_FLOOR_HEIGHT     100
 
 
-extern Player *player;
+extern Player *player;                                         // main.cpp?
+extern World  *currentWorld;                           // main.cpp
+extern int     commonAIFunc(NPC *);                    // entities.cpp
+extern void    commonTriggerFunc(Mob *);       // entities.cpp
+extern bool    inBattle;
+
+extern unsigned int tickCount;                         // main.cpp
+
+int worldShade = 0;
+
+std::string currentXML;
+
+std::vector<std::string> inside;               // tracks indoor worlds
 
+std::vector<World *>     battleNest;   // tracks arenas
+std::vector<vec2>        battleNestLoc;        // keeps arena locations
 
 /**
  * Contains the current weather, used in many other places/files.
@@ -230,7 +248,7 @@ generate( unsigned int width )
         UserError("Invalid world dimensions");
 
     // allocate space for world
-    worldData = std::vector<WorldData> (width + GROUND_HILLINESS, (WorldData) { false, {0,0}, 0, 0 });
+    worldData = std::vector<WorldData> (width + GROUND_HILLINESS, WorldData { false, {0,0}, 0, 0 });
     lineCount = worldData.size();
     
     // prepare for generation
@@ -270,7 +288,11 @@ generate( unsigned int width )
     worldStart = (width - GROUND_HILLINESS) * HLINE / 2 * -1;
        
     // create empty star array, should be filled here as well...
-       star = std::vector<vec2> (100, (vec2) { 0, 0 } );
+       star = std::vector<vec2> (100, vec2 { 0, 400 } );
+       for ( auto &s : star ) {
+               s.x = (getRand() % (-worldStart * 2)) + worldStart;
+               s.y = (getRand() % SCREEN_HEIGHT) + 100.0f;
+       }
 }
 
 /**
@@ -363,20 +385,6 @@ bgmPlay( World *prev ) const
        }
 }
 
-/**
- * Variables used by World::draw().
- * @{
- */
-
-extern vec2 offset;
-extern unsigned int tickCount;
-
-int worldShade = 0;
-
-/**
- * @}
- */
-
 /**
  * The world draw function.
  * 
@@ -436,7 +444,7 @@ draw( Player *p )
 
                if (tickCount % DAY_CYCLE) {    // The above if statement doesn't check for exact midnight.
                                
-                       safeSetColorA( 255, 255, 255, shadeBackground + getRand() % 30 - 15 );
+                       safeSetColorA( 255, 255, 255, 255 - (getRand() % 30 - 15) );
                        
                        for ( i = 0; i < 100; i++ ) {
                                glRectf(star[i].x + offset.x * .9,
@@ -446,7 +454,7 @@ draw( Player *p )
                                                );
                        }
                }
-       }
+       } 
        
        // draw remaining background items
        
@@ -464,7 +472,7 @@ draw( Player *p )
                }
        glEnd();
        
-       for ( i = 4; i--; ) {
+       for ( i = 0; i < 4; i++ ) {
                bgTex->bindNext();
                safeSetColorA( bgDraw[i][0] - shadeBackground, bgDraw[i][0] - shadeBackground, bgDraw[i][0] - shadeBackground, bgDraw[i][1] );
        
@@ -515,7 +523,11 @@ draw( Player *p )
        glActiveTexture( GL_TEXTURE0 );
        bgTex->bindNext();
        
-       GLfloat pointArray[ light.size() + (int)p->light ][2];
+       // help me
+       std::unique_ptr<GLfloat[][2]> pointArrayBuf = std::make_unique<GLfloat[][2]> (light.size() + p->light);
+       auto pointArray = pointArrayBuf.get();
+       
+       //GLfloat pointArray[ light.size() + (int)p->light ][2];
        
        for ( i = 0; i < (int)light.size(); i++ ) {
                pointArray[i][0] = light[i].loc.x - offset.x;
@@ -527,7 +539,7 @@ draw( Player *p )
        
        glUseProgram( shaderProgram );
        glUniform1i( glGetUniformLocation( shaderProgram, "sampler"), 0 );
-       glUniform1f( glGetUniformLocation( shaderProgram, "amb"    ), 1 );
+       glUniform1f( glGetUniformLocation( shaderProgram, "amb"    ), 0.5f - worldShade / 50.0f );
        
        if ( p->light ) {
                pointArray[light.size() + 1][0] = (float)( p->loc.x + SCREEN_WIDTH / 2 );
@@ -984,8 +996,6 @@ World *World::goWorldRight(Player *p){
        return this;
 }
 
-std::vector<std::string> inside;
-
 World *World::
 goInsideStructure( Player *p )
 {
@@ -1072,11 +1082,6 @@ void World::save(void){
        out.close();
 }
 
-#include <sstream>
-
-extern int  commonAIFunc(NPC *);
-extern void commonTriggerFunc(Mob *);
-
 void World::load(void){
        std::string save,data,line;
        const char *filedata;
@@ -1143,7 +1148,7 @@ void IndoorWorld::generate(unsigned int width){           // Generates a flat area of wid
        lineCount=width+GROUND_HILLINESS;                       // Sets line count to the desired width plus GEN_INC to remove incorrect line calculations.
        if(lineCount<=0)abort();
        
-       worldData = std::vector<WorldData> (lineCount, (WorldData) { false, {0,0}, INDOOR_FLOOR_HEIGHT, 0 });
+       worldData = std::vector<WorldData> (lineCount, WorldData { false, {0,0}, INDOOR_FLOOR_HEIGHT, 0 });
        
        worldStart = (width - GROUND_HILLINESS) * HLINE / 2 * -1;
 }
@@ -1159,7 +1164,9 @@ void IndoorWorld::draw(Player *p){
        
        glEnable(GL_TEXTURE_2D);
        
-       GLfloat pointArray[light.size()][2];
+       std::unique_ptr<GLfloat[][2]> pointArrayBuf = std::make_unique<GLfloat[][2]> (light.size());
+       auto pointArray = pointArrayBuf.get();
+       
        for(uint w = 0; w < light.size(); w++){
                pointArray[w][0] = light[w].loc.x - offset.x;
                pointArray[w][1] = light[w].loc.y;
@@ -1240,11 +1247,6 @@ void IndoorWorld::draw(Player *p){
        p->draw();
 }
 
-extern bool inBattle;
-
-std::vector<World *> battleNest;
-std::vector<vec2>    battleNestLoc;
-
 Arena::Arena(World *leave,Player *p,Mob *m){
        generate(800);
        addMob(MS_DOOR,100,100);
@@ -1287,13 +1289,6 @@ World *Arena::exitArena(Player *p){
        }
 }
 
-#include <tinyxml2.h>
-using namespace tinyxml2;
-
-std::string currentXML;
-
-extern World *currentWorld;
-
 World *loadWorldFromXML(std::string path){
        if ( !currentXML.empty() )
                currentWorld->save();
index 2cac7430ea1d4921aac80dc745b9a2530f62deef..c770e0f5b294db8b9a9c0f731867319c7e66eec0 100644 (file)
@@ -4,7 +4,7 @@
        <generation type="Random" width="500" />
        <link left="playerSpawnHill2.xml" />
        
-       <mob type="1" aggressive="false" />
+       <mob x="300" type="1" aggressive="true" />
        
        <trigger x="-300" id="Test" />