diff options
-rw-r--r-- | Makefile | 2 | ||||
-rw-r--r-- | include/entities.h | 2 | ||||
-rw-r--r-- | include/inventory.h | 1 | ||||
-rw-r--r-- | include/world.h | 4 | ||||
-rw-r--r-- | main.cpp | 4 | ||||
-rw-r--r-- | src/Makefile | 2 | ||||
-rw-r--r-- | src/Quest.cpp | 1 | ||||
-rw-r--r-- | src/Texture.cpp | 6 | ||||
-rw-r--r-- | src/entities.cpp | 39 | ||||
-rw-r--r-- | src/gameplay.cpp | 31 | ||||
-rw-r--r-- | src/inventory.cpp | 26 | ||||
-rw-r--r-- | src/ui.cpp | 7 | ||||
-rw-r--r-- | src/world.cpp | 239 |
13 files changed, 214 insertions, 150 deletions
@@ -2,7 +2,7 @@ LIBS = -lpthread -lGL -lGLEW -lSDL2 -lfreetype -lSDL2_image -lSDL2_mixer WIN_LIBS = -lopengl32 -lglew32 -lmingw32 -lSDL2main -lSDL2 -lSDL2_image -lSDL2_mixer -lfreetype
-FLAGS = -std=c++11 -Iinclude -Iinclude/freetype2
+FLAGS = -std=c++11 -Iinclude -Iinclude/freetype2 -Wall -Wextra -Werror
MFLAGS64 = 64
all:
diff --git a/include/entities.h b/include/entities.h index 19dd492..77ca347 100644 --- a/include/entities.h +++ b/include/entities.h @@ -87,6 +87,8 @@ public: virtual void wander(int){} virtual void interact(){} + + virtual ~Entity(){} }; class Player : public Entity { diff --git a/include/inventory.h b/include/inventory.h index 2c667a7..33a113c 100644 --- a/include/inventory.h +++ b/include/inventory.h @@ -48,7 +48,6 @@ public: char* textureLoc; Texturec *tex; GLuint text; - int count; Item(ITEM_ID i, const char *n, ITEM_TYPE t, float w, float h, int m, const char *tl); GLuint rtex(){ diff --git a/include/world.h b/include/world.h index 57ea091..952c2e5 100644 --- a/include/world.h +++ b/include/world.h @@ -118,7 +118,7 @@ public: */ World(void); - ~World(void); // Frees the 'line' array. + virtual ~World(void); // Frees the 'line' array. /* * Generate a world of width `width`. This function is virtual so that other world @@ -183,6 +183,8 @@ public: int getTheWidth(void); + void save(FILE *); + void load(FILE *); }; /* @@ -220,7 +220,7 @@ static unsigned int fadeIntensity = 0; * MAIN ************************************************************************ *******************************************************************************/ -int main(int argc, char *argv[]){ +int main(/*int argc, char *argv[]*/){ gameRunning=false; /*! @@ -708,7 +708,7 @@ void render(){ glUniform3f(glGetUniformLocation(shaderProgram, "lightColor"), 1,1,1); glUniform1f(glGetUniformLocation(shaderProgram, "lightStrength"), 5); glColor4f(1.0f, 1.0f, 1.0f, .5f); - for(auto r = 0; r < fray.size(); r++){ + for(unsigned int r = 0; r < fray.size(); r++){ glBegin(GL_TRIANGLES); glVertex2f(fray[r].start.x, fray[r].start.y); glVertex2f(fray[r].end.x, fray[r].end.y); diff --git a/src/Makefile b/src/Makefile index 03652fc..91743ef 100644 --- a/src/Makefile +++ b/src/Makefile @@ -1,6 +1,6 @@ LIBS = -lpthread -lGL -lSDL2 -lSDL2_image -lSDL2_mixer -lfreetype -FLAGS = -std=c++11 -I../include -I../include/freetype2 +FLAGS = -std=c++11 -I../include -I../include/freetype2 -Wall -Wextra -Werror OUT = `echo "" $$(ls -c $(wildcard *.cpp)) | sed s/.cpp/.o/g | sed 's/ / ..\/out\//g'` OUT64 = `echo "" $$(ls -c $(wildcard *.cpp)) | sed s/.cpp/.o/g | sed 's/ / ..\/out64\//g'` diff --git a/src/Quest.cpp b/src/Quest.cpp index 4e8522d..0905a87 100644 --- a/src/Quest.cpp +++ b/src/Quest.cpp @@ -67,7 +67,6 @@ int QuestHandler::drop(const char *t){ int QuestHandler::finish(const char *t,void *completer){
unsigned char i;
- unsigned int r;
for(i=0;i<current.size();i++){
if(!strcmp(current[i]->title,t)){
#ifdef DEBUG
diff --git a/src/Texture.cpp b/src/Texture.cpp index a44f1a7..5e5651d 100644 --- a/src/Texture.cpp +++ b/src/Texture.cpp @@ -66,11 +66,11 @@ namespace Texture{ } Texturec::Texturec(uint amt, ...){ + va_list fNames; texState = 0; image = new GLuint[amt]; - va_list fNames; va_start(fNames, amt); - for(int i = 0; i < amt; i++){ + for(unsigned int i = 0; i < amt; i++){ image[i] = Texture::loadTexture(va_arg(fNames, char *)); } va_end(fNames); @@ -79,7 +79,7 @@ Texturec::Texturec(uint amt, ...){ Texturec::Texturec(uint amt,const char **paths){ texState = 0; image = new GLuint[amt]; - for(int i = 0; i < amt; i++){ + for(unsigned int i = 0; i < amt; i++){ image[i] = Texture::loadTexture(paths[i]); } } diff --git a/src/entities.cpp b/src/entities.cpp index 7f78637..a2bff3c 100644 --- a/src/entities.cpp +++ b/src/entities.cpp @@ -12,7 +12,7 @@ extern const char *itemName; void getRandomName(Entity *e){ int tempNum,max=0; - char buf,*bufs; + char *bufs; rewind(names); @@ -358,38 +358,35 @@ void Object::interact(void){ * void spawn points for large amounts of entities. This would allow for the spawn * point to have non-normal traits so it could be invisible or invincible... */ -unsigned int Structures::spawn(_TYPE t, float x, float y){ //spawns a structure based off of type and coords + +unsigned int Structures::spawn(_TYPE t, float x, float y){ loc.x = x; loc.y = y; type = t; alive = true; - /*VILLAGE*/ - switch(type){ - case STRUCTURET: - width = 50 * HLINE; - height = 40 * HLINE; + width = 50 * HLINE; + height = 40 * HLINE; + /* + * tempN is the amount of entities that will be spawned in the village. Currently the village + * will spawn bewteen 2 and 7 villagers for the starting hut. + */ + + unsigned int tempN = (getRand() % 5 + 2); + + while(--tempN){ + /* - * tempN is the amount of entities that will be spawned in the village. Currently the village - * will spawn bewteen 2 and 7 villagers for the starting hut. + * This is where the entities actually spawn. A new entity is created + * with type NPC. */ - unsigned int tempN = (getRand() % 5 + 2); + currentWorld->addNPC(loc.x + (tempN - 5),100); - for(int i=0;i<tempN;i++){ - - /* - * This is where the entities actually spawn. A new entity is created - * with type NPC by using polymorphism. - */ - - currentWorld->addNPC(loc.x+(i-5),100); - - } - break; } + return 0; } diff --git a/src/gameplay.cpp b/src/gameplay.cpp index fa030c3..958356e 100644 --- a/src/gameplay.cpp +++ b/src/gameplay.cpp @@ -13,10 +13,7 @@ int compTestQuest(NPC *speaker){ } int giveTestQuest(NPC *speaker){ - unsigned char i; - ui::dialogBox(speaker->name,":Yes:No","Here, have a quest!"); - ui::waitForDialog(); if(ui::dialogOptChosen == 1){ @@ -32,20 +29,17 @@ int giveTestQuest(NPC *speaker){ return 0; } -static Arena *a; - void CUTSCENEEE(Mob *callee){ player->vel.x = 0; ui::dialogBox(player->name,":K.","No way I\'m gettin\' up this hill."); ui::waitForDialog(); - a = new Arena(currentWorld,player); - currentWorld = a; - - /*player->right = true; + player->right = true; player->left = false; - player->loc.x += HLINE * 5;*/ + player->loc.x += HLINE * 5; + + callee->alive = false; } void CUTSCENEEE2(Mob *callee){ @@ -67,7 +61,7 @@ static IndoorWorld *iw; void destroyEverything(void); void initEverything(void){ - unsigned int i; + //FILE *load; /* * World creation: @@ -82,9 +76,14 @@ void initEverything(void){ test->addLayer(400); playerSpawnHill=new World(); - playerSpawnHill->setBackground(BG_FOREST); - playerSpawnHill->generateFunc(1280,playerSpawnHillFunc); + + /*if((load=fopen("world.dat","rb"))){ + playerSpawnHill->load(load); + fclose(load); + }else{*/ + playerSpawnHill->generateFunc(1280,playerSpawnHillFunc); + //} /* * Setup the current world, making the player initially spawn in `test`. @@ -143,6 +142,12 @@ extern std::vector<int (*)(NPC *)> AIpreload; extern std::vector<NPC *> AIpreaddr; void destroyEverything(void){ + //FILE *save; + + /*save = fopen("world.dat","wb"); + playerSpawnHill->save(save); + fclose(save);*/ + delete test; delete playerSpawnHill; diff --git a/src/inventory.cpp b/src/inventory.cpp index 40f2153..7761c8c 100644 --- a/src/inventory.cpp +++ b/src/inventory.cpp @@ -16,8 +16,9 @@ static GLuint itemtex[ITEM_COUNT]; void itemDraw(Player *p,ITEM_ID id); void initInventorySprites(void){ - for(int i = 0;i<ITEM_COUNT;i++){ - itemtex[i]=Texture::loadTexture(getItemTexturePath((ITEM_ID)i)); + unsigned int i; + for(i = 0;i < ITEM_COUNT;i++){ + itemtex[i] = Texture::loadTexture(getItemTexturePath((ITEM_ID)i)); } } @@ -31,7 +32,6 @@ Item::Item(ITEM_ID i, const char *n, ITEM_TYPE t, float w, float h, int m, const width = w; height = h; maxStackSize = m; - count = 0; name = new char[strlen(n)+1]; textureLoc = new char[strlen(tl)+1]; @@ -58,34 +58,34 @@ void Inventory::setSelection(unsigned int s){ } int Inventory::addItem(ITEM_ID id,unsigned char count){ - std::cout << id << "," << inv[os].id << std::endl; - for(int i = 0; i < size; i++){ + //std::cout << id << "," << inv[os].id << std::endl; + + for(unsigned int i = 0; i < size; i++){ if(id == inv[i].id){ inv[i].count += count; break; - }else if(id ){ + }else if(id){ inv[os].id = id; inv[os].count = count; os++; break; } } + #ifdef DEBUG DEBUG_printf("Gave player %u more %s(s)(ID: %d).\n",count,item[id].name,item[id].id); #endif // DEBUG + return 0; } int Inventory::takeItem(ITEM_ID id,unsigned char count){ - unsigned int i; - for(i=0;i<size;i++){ - if(inv[i].id==id){ + for(unsigned int i = 0;i < size;i++){ + if(inv[i].id == id){ #ifdef DEBUG DEBUG_printf("Took %u of player's %s(s).\n",count,item[i].name); #endif // DEBUG inv[i].count-=count; - if(item[i].count<0) - return item[i].count*-1; return 0; } } @@ -93,10 +93,8 @@ int Inventory::takeItem(ITEM_ID id,unsigned char count){ } void Inventory::draw(void){ - unsigned int i=0; static unsigned int lop = 0; - float y,xoff; - static int numSlot = 7; + static unsigned int numSlot = 7; static std::vector<int>dfp(numSlot); static std::vector<Ray>iray(numSlot); static std::vector<vec2>curCoord(numSlot); @@ -243,7 +243,7 @@ namespace ui { */ float putString(const float x,const float y,const char *s){ - unsigned int i=0,j; + unsigned int i=0; float xo=x,yo=y; vec2 add; @@ -271,7 +271,7 @@ namespace ui { float putStringCentered(const float x,const float y,const char *s){ unsigned int i = 0; - float width = 0, prev = 0; + float width = 0; do{ if(s[i]=='\n'){ // Handle newlines @@ -299,7 +299,6 @@ namespace ui { linc=0, // Contains the number of letters that should be drawn. size=0; // Contains the full size of the current string. static char *ret = NULL; - unsigned int i; /* * Create a well-sized buffer if we haven't yet. @@ -623,7 +622,7 @@ DONE: } if(SDL_KEY==SDLK_p)toggleBlack(); if(SDL_KEY==SDLK_F3)debug^=true; - if(SDL_KEY==SDLK_b & SDL_KEY==SDLK_F3)posFlag^=true; + if(((SDL_KEY==SDLK_b) & (SDL_KEY==SDLK_F3)))posFlag^=true; if(SDL_KEY==SDLK_e){ if(heyOhLetsGo == 0){ heyOhLetsGo = loops; diff --git a/src/world.cpp b/src/world.cpp index 3557121..e5203df 100644 --- a/src/world.cpp +++ b/src/world.cpp @@ -40,13 +40,7 @@ const float bgDraw[3][3]={ }; float worldGetYBase(World *w){ - /*float base = 0; - World *ptr = w; - while(ptr->infront){ - base+=DRAW_Y_OFFSET; - ptr=ptr->infront; - }*/ - return /*base*/ GEN_MIN; + return w?GEN_MIN:0; } void World::setBackground(WORLD_BG_TYPE bgt){ @@ -60,7 +54,16 @@ void World::setBackground(WORLD_BG_TYPE bgt){ } } +void World::save(FILE *s){ + fclose(s); +} + +void World::load(FILE *s){ + fclose(s); +} + World::World(void){ + /* * Nullify pointers to other worlds. */ @@ -70,8 +73,12 @@ World::World(void){ toLeft = toRight = NULL; - star = new vec2[100]; //(vec2 *)calloc(100,sizeof(vec2)); - memset(star,0,100*sizeof(vec2)); + /* + * Allocate and clear an array for star coordinates. + */ + + star = new vec2[100]; + memset(star,0,100 * sizeof(vec2)); } void World::deleteEntities(void){ @@ -118,35 +125,38 @@ void World::generate(unsigned int width){ // Generates the world and sets all va * */ - if((lineCount = width + GEN_INC) <= 0) + if(width <= 0) abort(); + + lineCount = width + GEN_INC; /* * Allocate enough memory for the world to be stored. */ - line = new struct line_t[lineCount]; //(struct line_t *)calloc(lineCount,sizeof(struct line_t)); - memset(line,0,lineCount*sizeof(struct line_t)); + line = new struct line_t[lineCount]; + memset(line,0,lineCount * sizeof(struct line_t)); /* * Set an initial y to base generation off of, as generation references previous lines. */ - line[0].y=GEN_INIT; + line[0].y = GEN_INIT; /* * Populate every GEN_INCth line structure. The remaining lines will be based off of these. */ - for(i=GEN_INC;i<lineCount;i+=GEN_INC){ + for(i = GEN_INC;i < lineCount;i += GEN_INC){ /* * Generate a y value, ensuring it stays within a reasonable range. */ - line[i].y=rand() % 8 - 4 + line[i-GEN_INC].y; // Add +/- 4 to the previous line - if(line[i].y < GEN_MIN)line[i].y = GEN_MIN; // Minimum bound - else if(line[i].y > GEN_MAX)line[i].y = GEN_MAX; // Maximum bound + line[i].y = rand() % 8 - 4 + line[i - GEN_INC].y; // Add +/- 4 to the previous line + + if(line[i].y < GEN_MIN)line[i].y = GEN_MIN; // Minimum bound + else if(line[i].y > GEN_MAX)line[i].y = GEN_MAX; // Maximum bound } @@ -154,7 +164,7 @@ void World::generate(unsigned int width){ // Generates the world and sets all va * Generate values for the remaining lines here. */ - for(i=0;i<lineCount-GEN_INC;i++){ + for(i = 0;i < lineCount - GEN_INC;i++){ /* * Every GEN_INCth line calculate the slope between the current line and the one @@ -163,35 +173,31 @@ void World::generate(unsigned int width){ // Generates the world and sets all va * */ - if(!(i%GEN_INC)){ + if(!(i % GEN_INC)) - inc=(line[i + GEN_INC].y - line[i].y) / (float)GEN_INC; + inc = (line[i + GEN_INC].y - line[i].y) / (float)GEN_INC; - }else{ - - /* - * Add the increment to create the smooth slope. - */ - - line[i].y=line[i - 1].y + inc; + /* + * Add the increment to create the smooth slope. + */ - } + else line[i].y = line[i - 1].y + inc; /* * Generate a color value for the line. This will be referenced in World->draw(), * by setting an RGB value of color (red), color - 50 (green), color - 100 (blue). */ - line[i].color=rand() % 20 + 100; // 100 to 120 + 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].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) + line[i].gs = true; // Show the blades of grass (modified by the player) } @@ -199,47 +205,80 @@ void World::generate(unsigned int width){ // Generates the world and sets all va * Calculate the x coordinate to start drawing this world from so that it is centered at (0,0). */ - x_start=0 - getWidth(this) / 2; + x_start = 0 - getWidth(this) / 2; - for(int i=0;i<100;i++){ - star[i].x=getRand()%getTheWidth()-getTheWidth()/2; - star[i].y=getRand()%SCREEN_HEIGHT+100; + /* + * Assign coordinates for the stars, seen at nighttime. + */ + + for(i = 0;i < 100;i++){ + star[i].x = getRand() % getTheWidth() - getTheWidth() / 2; + star[i].y = getRand() % SCREEN_HEIGHT + 100; } } void World::generateFunc(unsigned int width,float(*func)(float)){ unsigned int i; + + /* + * Check for a valid width. + */ + if((lineCount = width) <= 0) abort(); - line = new struct line_t[lineCount]; //(struct line_t *)calloc(lineCount,sizeof(struct line_t)); + + /* + * Allocate memory for the line array. + */ + + line = new struct line_t[lineCount]; memset(line,0,lineCount*sizeof(struct line_t)); - for(i=0;i<lineCount;i++){ - line[i].y=func(i); - if(line[i].y<0)line[i].y=0; - if(line[i].y>2000)line[i].y=2000; - line[i].color=rand() % 20 + 100; - line[i].gh[0]=(getRand() % 16) / 3.5 + 2; - line[i].gh[1]=(getRand() % 16) / 3.5 + 2; - line[i].gs=true; + + /* + * Populate entries in the line array, using `func` to get y values. + */ + + for(i = 0;i < lineCount;i++){ + line[i].y = func(i); + + if(line[i].y < 0)line[i].y = 0; // Minimum bound + if(line[i].y > 2000)line[i].y = 2000; // Maximum bound + + line[i].color = rand() % 20 + 100; + + line[i].gh[0] = (getRand() % 16) / 3.5 + 2; + line[i].gh[1] = (getRand() % 16) / 3.5 + 2; + + line[i].gs = true; } - x_start=0 - getWidth(this) / 2; - for(int i=0;i<100;i++){ - star[i].x=getRand()%getTheWidth()-getTheWidth()/2; - star[i].y=getRand()%SCREEN_HEIGHT+100; + x_start = 0 - getWidth(this) / 2; + + for(i = 0;i < 100;i++){ + star[i].x = getRand() % getTheWidth() - getTheWidth() / 2; + star[i].y = getRand() % SCREEN_HEIGHT + 100; } } void World::update(Player *p,unsigned int delta){ - p->loc.y+= p->vel.y *delta; - p->loc.x+=(p->vel.x*p->speed)*delta; + + /* + * Update the player's coordinates. + */ + + p->loc.y += p->vel.y * delta; + p->loc.x +=(p->vel.x * p->speed) * delta; + + /* + * Update coordinates of all entities except for structures. + */ for(auto &e : entity){ if(e->type != STRUCTURET) e->loc.x += e->vel.x * delta; e->loc.y += e->vel.y * delta; if(e->vel.x < 0)e->left = true; - else if(e->vel.x > 0)e->left = false; + else if(e->vel.x > 0)e->left = false; } } @@ -252,7 +291,8 @@ void World::draw(Player *p){ static float yoff=DRAW_Y_OFFSET; // Initialize stuff static int shade,bgshade; static World *current; - int i,is,ie,v_offset,cx_start,width; + unsigned int i,ie; + int is,v_offset,cx_start,width; struct line_t *cline; bgshade = worldShade << 1; // *2 @@ -290,8 +330,8 @@ void World::draw(Player *p){ * Draws stars if it is an appropriate time of day for them. */ - if(((weather==DARK )&(tickCount%DAY_CYCLE)<DAY_CYCLE/2) || - ((weather==SUNNY)&(tickCount%DAY_CYCLE)>DAY_CYCLE*.75) ){ + if((((weather==DARK )&(tickCount%DAY_CYCLE))<DAY_CYCLE/2) || + (((weather==SUNNY)&(tickCount%DAY_CYCLE))>DAY_CYCLE*.75) ){ if(tickCount % DAY_CYCLE){ // The above if statement doesn't check for exact midnight. @@ -530,7 +570,7 @@ LOOP2: * Calculate the line that the player is on */ - int ph = (p->loc.x + p->width / 2 - x_start) / HLINE; + unsigned int ph = (p->loc.x + p->width / 2 - x_start) / HLINE; /* * If the player is on the ground, flatten the grass where the player is standing @@ -587,8 +627,8 @@ LOOP2: } void World::singleDetect(Entity *e){ - int i; - unsigned int j; + unsigned int i,j; + int l; /* * Kill any dead entities. @@ -635,17 +675,16 @@ void World::singleDetect(Entity *e){ } } break; + case PLAYERT: + std::cout<<"RIP "<<e->name<<"."<<std::endl; + exit(0); + break; } std::cout<<"Killed an entity..."<<std::endl; entity.erase(entity.begin()+i); return; } } - - std::cout<<"RIP "<<e->name<<"."<<std::endl; - exit(0); - - return; } /* @@ -660,8 +699,9 @@ void World::singleDetect(Entity *e){ * Calculate the line that this entity is currently standing on. */ - i=(e->loc.x + e->width / 2 - x_start) / HLINE; - if(i < 0) i=0; + l=(e->loc.x + e->width / 2 - x_start) / HLINE; + if(l < 0) l=0; + i = l; if(i > lineCount-1) i=lineCount-1; /* @@ -690,8 +730,9 @@ void World::singleDetect(Entity *e){ do{ e->loc.x+=.001 * e->vel.x>0?-1:1; - i=(e->loc.x - e->width / 2 - x_start) / HLINE; - if(i < 0){ e->alive = false; return; } + l=(e->loc.x - e->width / 2 - x_start) / HLINE; + if(l < 0){ e->alive = false; return; } + i = l; if(i > lineCount-1){ e->alive = false; return; } }while(line[i].y>e->loc.y+ e->height); @@ -909,40 +950,62 @@ void IndoorWorld::generate(unsigned int width){ // Generates a flat area of wid } void IndoorWorld::draw(Player *p){ - int i,ie,v_offset; + unsigned int i,ie; + int j,x,v_offset; + + /* + * Draw the background. + */ glEnable(GL_TEXTURE_2D); + bgTex->bind(0); glColor4ub(255,255,255,255); - glBegin(GL_QUADS); - for(i = x_start - SCREEN_WIDTH / 2;i < -x_start + SCREEN_WIDTH / 2; i += 1024){ - glTexCoord2i(1,1);glVertex2i(i ,0); - glTexCoord2i(0,1);glVertex2i(i+1024,0); - glTexCoord2i(0,0);glVertex2i(i+1024,1024); - glTexCoord2i(1,0);glVertex2i(i ,1024); + + glBegin(GL_QUADS); + for(j = x_start - SCREEN_WIDTH / 2;j < -x_start + SCREEN_WIDTH / 2; j += 512){ + glTexCoord2i(1,1);glVertex2i(j ,0); + glTexCoord2i(0,1);glVertex2i(j+512,0); + glTexCoord2i(0,0);glVertex2i(j+512,512); + glTexCoord2i(1,0);glVertex2i(j ,512); } glEnd(); + glDisable(GL_TEXTURE_2D); - v_offset=(p->loc.x-x_start)/HLINE; // Calculate the player's offset in the array 'line' using the player's location 'vec' - i=v_offset-SCREEN_WIDTH/2; // um - if(i<0)i=0; // If the player is past the start of that world 'i' should start at the beginning - // of the world - ie=v_offset+SCREEN_WIDTH/2; // Set how many lines should be drawn (the drawing for loop loops from 'i' to 'ie') - if(ie>lineCount)ie=lineCount; // If the player is past the end of that world 'ie' should contain the end of that world - //glClearColor(.3,.1,0,0); + /* + * Calculate the starting and ending points to draw the ground from. + */ + + v_offset = (p->loc.x - x_start) / HLINE; + j = v_offset - (SCREEN_WIDTH / 2 / HLINE) - GEN_INC; + if(j < 0)j = 0; + i = j; + + ie = v_offset + (SCREEN_WIDTH / 2 / HLINE) - GEN_INC; + if(ie > lineCount)ie = lineCount; + + /* + * Draw the ground. + */ glBegin(GL_QUADS); - for(i=i;i<ie-GEN_INC;i++){ // For lines in array 'line' from 'i' to 'ie' + for(;i < ie - GEN_INC;i++){ safeSetColor(150,100,50); - glVertex2i(x_start+i*HLINE ,line[i].y); // Draw the base floor - glVertex2i(x_start+i*HLINE+HLINE,line[i].y); - glVertex2i(x_start+i*HLINE+HLINE,line[i].y-50); - glVertex2i(x_start+i*HLINE ,line[i].y-50); + + x = x_start + i * HLINE; + glVertex2i(x ,line[i].y); + glVertex2i(x + HLINE,line[i].y); + glVertex2i(x + HLINE,line[i].y - 50); + glVertex2i(x ,line[i].y - 50); } glEnd(); - for(i=0;i<entity.size();i++) - entity[i]->draw(); + + /* + * Draw all entities. + */ + + for(auto &e : entity) e->draw(); p->draw(); } |