From 11b1b0c29b3911c04a7d784ac9c0c352851be2c9 Mon Sep 17 00:00:00 2001 From: Clyne Sullivan Date: Wed, 21 Oct 2015 08:49:20 -0400 Subject: documentation part 3 --- src/Quest.cpp | 2 +- src/common.cpp | 4 +- src/entities.cpp | 4 ++ src/inventory.cpp | 6 +-- src/ui.cpp | 5 +-- src/world.cpp | 127 +++++++++++++++++++++++++++++++++++++++++------------- 6 files changed, 110 insertions(+), 38 deletions(-) (limited to 'src') diff --git a/src/Quest.cpp b/src/Quest.cpp index 2eed1ae..a361418 100644 --- a/src/Quest.cpp +++ b/src/Quest.cpp @@ -1,4 +1,4 @@ -#include +#include #define TITLE Quest( #define DESC , diff --git a/src/common.cpp b/src/common.cpp index 8dcbd11..660ed9d 100644 --- a/src/common.cpp +++ b/src/common.cpp @@ -1,11 +1,13 @@ #include +#define DEBUG + GLuint loadTexture(const char *fileName){ SDL_Surface *image = IMG_Load(fileName); if(!image)return 0; #ifdef DEBUG - DEBUG_printf("Loaded image file: %s\n", fileName); + DEBUG_printf("Loaded image file: %s\n", fileName); #endif // DEBUG unsigned object = 0; //creates a new unsigned variable for the texture diff --git a/src/entities.cpp b/src/entities.cpp index 2bc5a61..9b87150 100644 --- a/src/entities.cpp +++ b/src/entities.cpp @@ -5,6 +5,9 @@ extern std::vectorentity; extern std::vectornpc; extern std::vectorbuild; +extern FILE* names; +extern unsigned int loops; + void Entity::spawn(float x, float y){ //spawns the entity you pass to it based off of coords and global entity settings loc.x = x; loc.y = y; @@ -245,6 +248,7 @@ unsigned int Structures::spawn(_TYPE t, float x, float y){ //spawns a structure loc.y = y; type = t; alive = true; + health = maxHealth = 1; /*VILLAGE*/ //spawns a village diff --git a/src/inventory.cpp b/src/inventory.cpp index 3690de5..b9b4859 100644 --- a/src/inventory.cpp +++ b/src/inventory.cpp @@ -1,8 +1,11 @@ #include +#include #include #define ITEM_COUNT 2 // Total number of items that actually exist +extern Player *player; + const char *itemName[]={ "\0", "Dank Maymay", @@ -80,9 +83,6 @@ int Inventory::takeItem(ITEM_ID id,unsigned char count){ return -1; } -#include -extern Player *player; - void Inventory::draw(void){ unsigned int i=0; float y=SCREEN_HEIGHT/2,xoff; diff --git a/src/ui.cpp b/src/ui.cpp index a62086e..256f5d7 100644 --- a/src/ui.cpp +++ b/src/ui.cpp @@ -1,7 +1,4 @@ #include -#include // World-switching stuff -#include // FreeType stuff -#include FT_FREETYPE_H #define SDL_KEY e.key.keysym.sym // Keeps the code neater :) @@ -11,6 +8,8 @@ extern World *currentWorld; // should/must also be defined in main.cpp extern std::vector AIpreload; // see entities.cpp extern std::vector AIpreaddr; // +extern bool gameRunning; + static FT_Library ftl; // Variables for the FreeType library and stuff static FT_Face ftf; static GLuint ftex; diff --git a/src/world.cpp b/src/world.cpp index 3b1fd87..bd58573 100644 --- a/src/world.cpp +++ b/src/world.cpp @@ -1,5 +1,4 @@ #include -#include #define getWidth(w) ((w->lineCount-GEN_INC)*HLINE) // Calculates the width of world 'w' @@ -33,38 +32,110 @@ World::World(void){ void World::generate(unsigned int width){ // Generates the world and sets all variables contained in the World class. unsigned int i; // Used for 'for' loops float inc; // See line 40 - lineCount=width+GEN_INC; // Sets line count to the desired width plus GEN_INC to remove incorrect line calculations. - if(lineCount<=0)abort(); - line=(struct line_t *)calloc(lineCount,sizeof(struct line_t)); // Allocate memory for the array 'line' + /* + * Calculate the world's real width. The current form of generation fails to generate + * the last GEN_INC lines, so we offset those making the real real width what was passed + * to this function. + * + * Abort if the width is invalid. + * + */ + + if((lineCount = width + GEN_INC) <= 0) + abort(); + + /* + * Allocate enough memory for the world to be stored. + */ + + line=(struct line_t *)calloc(lineCount,sizeof(struct line_t)); - line[0].y=80; // Sets a starting value for the world generation to be based off of - for(i=GEN_INC;i110)line[i].y=110; // y value maximum + /* + * Set an initial y to base generation off of, as generation references previous lines. + */ + + line[0].y=80; + + /* + * Populate every GEN_INCth line structure. The remaining lines will be based off of these. + */ + + for(i=GEN_INC;i 110)line[i].y = 110; // Maximum bound + } - for(i=0;idraw(), + * by setting an RGB value of color (red), color - 50 (green), color - 100 (blue). + */ + + line[i].color=rand() % 20 + 100; // 100 to 120 + + /* + * Each line has two 'blades' of grass, here we generate random heights for them. + */ + + line[i].gh[0]=(getRand() % 16) / 3.5 + 2; // Not sure what the range resolves to here... + line[i].gh[1]=(getRand() % 16) / 3.5 + 2; // + + line[i].gs=true; // Show the blades of grass (modified by the player) + } - x_start=0-getWidth(this)/2+GEN_INC/2*HLINE; // Calculate x_start (explained in world.h) - behind=infront=NULL; // Set pointers to other worlds to NULL - toLeft=toRight=NULL; // to avoid accidental calls to goWorld... functions + + /* + * Calculate the x coordinate to start drawing this world from so that it is centered at (0,0). + */ + + x_start=0 - getWidth(this) / 2 + GEN_INC / 2 * HLINE; + + /* + * Nullify pointers to other worlds. + */ + + behind = + infront = + toLeft = + toRight = NULL; } World::~World(void){ - free(line); // Free (de-allocate) the array 'line' + free(line); } void World::draw(Player *p){ @@ -161,14 +232,10 @@ void World::singleDetect(Entity *e){ e->alive=false; }else if(e->alive){ i=(e->loc.x+e->width/2-x_start)/HLINE; // Calculate what line the player is currently on - if(e->type==STRUCTURET||e->loc.yloc.yvel.y=0; e->ground=true; e->loc.y=line[i].y-.001*deltaTime; - if(e->type==STRUCTURET){ - //std::cout<loc.x<<" "<loc.y<loc.y>line[i].y-.002*deltaTime){ for(i=0;iloc.x+e->width>platform[i].p1.x)&(e->loc.x+e->width