From f28fda996331de5dac8fc2f20ea0898527239fe5 Mon Sep 17 00:00:00 2001 From: Clyne Sullivan Date: Wed, 7 Oct 2015 08:39:53 -0400 Subject: world improvement --- src/Makefile | 2 +- src/common.cpp | 17 +----------- src/entities.cpp | 2 +- src/world.cpp | 81 ++++++++++++++++++++++++++++++++++++++------------------ 4 files changed, 58 insertions(+), 44 deletions(-) (limited to 'src') diff --git a/src/Makefile b/src/Makefile index f75bee9..b88dc53 100644 --- a/src/Makefile +++ b/src/Makefile @@ -8,4 +8,4 @@ OUT = `echo "" $$(ls -c $(wildcard *.cpp)) | sed s/.cpp/.o/g | sed 's/ / ..\/out @echo " CXX " $(shell echo $@ | sed 's/..\/out\///g' | sed 's/\.o/\.cpp/') @g++ $(FLAGS) -o $@ -c $(shell echo $@ | sed 's/..\/out\///g' | sed 's/\.o/\.cpp/') $(LIBS) -all: $(shell echo $(OUT)) +all: $(shell echo $(OUT)) diff --git a/src/common.cpp b/src/common.cpp index 124d999..373c08c 100644 --- a/src/common.cpp +++ b/src/common.cpp @@ -1,20 +1,5 @@ #include -/*SDL_Surface* loadTexture(char* filename){ - SDL_Surface *optimizedSurface = NULL; - SDL_Surface *texture = IMG_Load(filename); - if(texture == NULL){ - std::cout << "Unable to load an image properly from " << filename << "; Error: " << IMG_GetError() << std::endl; - }else{ - optimizedSurface = SDL_ConvertSurface(texture, renderSurface->format, NULL); - if(optimizedSurface == NULL){ - std::cout << "Unable to optimize image properly from " << filename << "; Error: " << IMG_GetError() << std::endl; - } - SDL_FreeSurface(texture); - } - return optimizedSurface; -}*/ - GLuint loadTexture(const char *fileName){ SDL_Surface *image = IMG_Load(fileName); @@ -38,4 +23,4 @@ GLuint loadTexture(const char *fileName){ SDL_FreeSurface(image); return object; -} \ No newline at end of file +} diff --git a/src/entities.cpp b/src/entities.cpp index 46d445b..49fce0f 100644 --- a/src/entities.cpp +++ b/src/entities.cpp @@ -32,7 +32,7 @@ void Entity::draw(void){ //draws the entities glColor3ub(255,255,0); glRectf(loc.x+width/3,loc.y+height,loc.x+width*2/3,loc.y+height+width/3); } - }if(type==STRUCTURET){ + }else{ glColor3ub(255,255,255); } if(left){ diff --git a/src/world.cpp b/src/world.cpp index ef11002..18a0725 100644 --- a/src/world.cpp +++ b/src/world.cpp @@ -11,7 +11,7 @@ #define DRAW_Y_OFFSET 50 // Defines how many pixels each layer should be offset from each other on the y axis when drawn. -#define DRAW_SHADE 10 // Defines a shade increment for draw() +#define DRAW_SHADE 30 // Defines a shade increment for draw() #define INDOOR_FLOOR_HEIGHT 100 // Defines how high the base floor of an IndoorWorld should be @@ -50,9 +50,12 @@ void World::generate(unsigned int width){ // Generates the world and sets all va }else{ // If this line's y hasn't been set yet line[i].y=line[i-1].y+inc; // Set it by incrementing the previous line's y by 'inc'. } - line[i].color=rand()%20+90; // Generate a color for the dirt area of this line. This value will be used - // in the form (where n represents the color) glColor3ub(n,n-50,n-100) - line[i].gh=(getRand()%20)/3; // Create a random grass height so it looks cool + line[i].color=rand()%20+100; // Generate a color for the dirt area of this line. This value will be used + // in the form (where n represents the color) glColor3ub(n,n-50,n-100) + + line[i].gh[0]=(getRand()%16)/3.5+2; // Create a random grass height so it looks cool + line[i].gh[1]=(getRand()%16)/3.5+2; + line[i].gs=true; } 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 @@ -63,11 +66,11 @@ World::~World(void){ free(line); // Free (de-allocate) the array 'line' } -void World::draw(vec2 *vec){ +void World::draw(Player *p){ static float yoff=DRAW_Y_OFFSET; // Initialize stuff static int shade=0; static World *current; - int i,ie,v_offset,cx_start; + int i,is,ie,v_offset,cx_start; struct line_t *cline; current=this; // yeah glClearColor(.1,.3,.6,0); @@ -79,32 +82,62 @@ LOOP1: // Check for worlds behind the current one and set 'current' to th goto LOOP1; } LOOP2: // Draw each world - v_offset=(vec->x-current->x_start)/HLINE; // Calculate the player's offset in the array 'line' using the player's location 'vec' - i=v_offset-SCREEN_WIDTH/(yoff/(DRAW_Y_OFFSET/2)); // Set 'i' to that somehow - if(i<0)i=0; // If the player is past the start of that world 'i' should start at the beginning + v_offset=(p->loc.x-current->x_start)/HLINE; // Calculate the player's offset in the array 'line' using the player's location 'vec' + is=v_offset-SCREEN_WIDTH/(yoff/(DRAW_Y_OFFSET/2)); // Set 'i' to that somehow + if(is<0)is=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/(yoff/(DRAW_Y_OFFSET/2)); // Set how many lines should be drawn (the drawing for loop loops from 'i' to 'ie') if(ie>current->lineCount)ie=current->lineCount; // If the player is past the end of that world 'ie' should contain the end of that world cline=current->line; // 'cline' and 'cx_start' only exist to make the for loop clear (and maybe make it faster) cx_start=current->x_start; - shade*=-1; + //shade*=-1; glBegin(GL_QUADS); - for(i=i;iloc.x+p->width/2-x_start)/HLINE; // Calculate what line the player is currently on + for(i=0;iground==1&&iph-6)cline[i].gs=false; + else cline[i].gs=true; + } + for(i=0;iinWorld==this){ + entity[i]->draw(); + } + } + p->draw(); + } + float cgh[2]; + glBegin(GL_QUADS); + for(i=is;iplatform.size();i++){ glRectf(current->platform[i].p1.x,current->platform[i].p1.y+yoff-DRAW_Y_OFFSET, @@ -118,11 +151,6 @@ LOOP2: // Draw each world }else{ // Otherwise reset static values and return yoff=DRAW_Y_OFFSET; shade=0; - for(i=0;iinWorld==this){ - entity[i]->draw(); - } - } } } @@ -269,9 +297,9 @@ void IndoorWorld::generate(unsigned int width){ // Generates a flat area of wid x_start=0-getWidth(this)/2+GEN_INC/2*HLINE; // Calculate x_start (explained in world.h) } -void IndoorWorld::draw(vec2 *vec){ +void IndoorWorld::draw(Player *p){ int i,ie,v_offset; - v_offset=(vec->x-x_start)/HLINE; // Calculate the player's offset in the array 'line' using the player's location 'vec' + 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 @@ -291,4 +319,5 @@ void IndoorWorld::draw(vec2 *vec){ if(entity[i]->inWorld==this) entity[i]->draw(); } + p->draw(); } -- cgit v1.2.3