From 1c0767766506407babdfefea9efe2b5627569244 Mon Sep 17 00:00:00 2001 From: Clyne Sullivan Date: Tue, 6 Oct 2015 08:50:52 -0400 Subject: improvements ;) --- Changelog | 7 +++++++ Makefile | 18 ++++-------------- include/world.h | 2 +- main.cpp | 19 ++++++++----------- src/Makefile | 11 +++++++++++ src/entities.cpp | 6 +++--- src/world.cpp | 23 ++++++++++++++--------- 7 files changed, 48 insertions(+), 38 deletions(-) create mode 100644 src/Makefile diff --git a/Changelog b/Changelog index 540d8fe..fecb56d 100644 --- a/Changelog +++ b/Changelog @@ -79,3 +79,10 @@ - textures flip with direction - made a beautiful Makefile - moved main game loop into separate function + +10/6/2015: +========== + + - Makefile only builds edited files now + - improved sprites + - improved world drawing diff --git a/Makefile b/Makefile index d04582b..983f636 100644 --- a/Makefile +++ b/Makefile @@ -1,21 +1,11 @@ -LIBS_LINUX = -lGL -lSDL2_image -lSDL2_mixer -LIBS_WIN32 = -lopengl32 -lmingw32 -lSDL2_Image +LIBS = -lGL -lSDL2_image -lSDL2_mixer FLAGS = -m32 -std=c++11 -Iinclude -Iinclude/freetype2 -lSDL2main -lSDL2 -lfreetype -SRCS = $(wildcard src/*.cpp) - -OUT = $(SRCS:.cpp=.o) - -.cpp.o: - @echo " CXX " $^ - @g++ -o $@ -c $^ $(LIBS_LINUX) $(FLAGS) - -all: $(OUT) - @echo "Relocating object files..." - @mv ./src/*.o ./out +all: + @cd src; $(MAKE) $(MFLAGS) @echo " CXX main.cpp" - @g++ -o main main.cpp out/*.o $(LIBS_LINUX) $(FLAGS) + @g++ $(FLAGS) -o main main.cpp out/*.o $(LIBS) clean: @echo " RM main" diff --git a/include/world.h b/include/world.h index cf0b7b8..7095c3b 100644 --- a/include/world.h +++ b/include/world.h @@ -24,7 +24,7 @@ protected: * */ struct line_t { - float y; + float y,gh; unsigned char color; } __attribute__ ((packed)) *line; unsigned int lineCount; // Size of the array 'line' (aka the width of the world) diff --git a/main.cpp b/main.cpp index fdb7d32..b9512cd 100644 --- a/main.cpp +++ b/main.cpp @@ -58,16 +58,6 @@ int main(int argc, char *argv[]){ } atexit(Mix_Quit); - //Load music - music = Mix_LoadMUS("assets/BennyHillTheme.wav"); - horn = Mix_LoadWAV("assets/air-horn-club-sample_1.wav"); - if( music == NULL ){ - printf( "Failed to load beat music! SDL_mixer Error: %s\n", Mix_GetError() ); - } - Mix_PlayMusic( music, -1 ); - - - // Turn on double buffering SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); // Create the window @@ -93,7 +83,6 @@ int main(int argc, char *argv[]){ initRand(millis()); // Initialize the random number generator with millis() glViewport(0,0,SCREEN_WIDTH, SCREEN_HEIGHT); // Switch to pixel-based rendering, not coordinates (the -1 to 1 stuff) - glClearColor(.3,.5,.8,0); // Sky blue glEnable(GL_BLEND); // Allow transparency glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA); SDL_ShowCursor(SDL_DISABLE); // Hide mouse cursor so we can draw our own @@ -110,6 +99,14 @@ int main(int argc, char *argv[]){ **** GAMELOOP **** **************************/ + //Load music + music = Mix_LoadMUS("assets/BennyHillTheme.wav"); + horn = Mix_LoadWAV("assets/air-horn-club-sample_1.wav"); + if( music == NULL ){ + printf( "Failed to load beat music! SDL_mixer Error: %s\n", Mix_GetError() ); + } + Mix_PlayMusic( music, -1 ); + while(gameRunning){ mainLoop(); } diff --git a/src/Makefile b/src/Makefile new file mode 100644 index 0000000..f75bee9 --- /dev/null +++ b/src/Makefile @@ -0,0 +1,11 @@ +LIBS = -lGL -lSDL2_image -lSDL2_mixer + +FLAGS = -m32 -std=c++11 -I../include -I../include/freetype2 -lSDL2main -lSDL2 -lfreetype + +OUT = `echo "" $$(ls -c $(wildcard *.cpp)) | sed s/.cpp/.o/g | sed 's/ / ..\/out\//g'` + +../out/%.o: + @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)) diff --git a/src/entities.cpp b/src/entities.cpp index 42f93c8..5dc743c 100644 --- a/src/entities.cpp +++ b/src/entities.cpp @@ -85,17 +85,17 @@ void Entity::getName(){ switch(fgetc(names)){ case 'm': gender = MALE; - std::puts("Male"); + //std::puts("Male"); break; case 'f': gender = FEMALE; - std::puts("Female"); + //std::puts("Female"); break; default: break; } if((fgets(bufs,16,(FILE*)names)) != NULL){ - std::puts(bufs); + //std::puts(bufs); bufs[strlen(bufs)-1] = '\0'; strcpy(name,bufs); } diff --git a/src/world.cpp b/src/world.cpp index d2cd380..ef11002 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 40 // Defines a shade increment for draw() +#define DRAW_SHADE 10 // Defines a shade increment for draw() #define INDOOR_FLOOR_HEIGHT 100 // Defines how high the base floor of an IndoorWorld should be @@ -50,8 +50,9 @@ 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+130; // 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].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 } 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 @@ -69,6 +70,7 @@ void World::draw(vec2 *vec){ int i,ie,v_offset,cx_start; struct line_t *cline; current=this; // yeah + glClearColor(.1,.3,.6,0); LOOP1: // Check for worlds behind the current one and set 'current' to them if they exist if(current->behind){ // so that once LOOP1 is exited 'current' contains the furthest back world. yoff+=DRAW_Y_OFFSET; @@ -85,22 +87,24 @@ LOOP2: // Draw each world 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; glBegin(GL_QUADS); for(i=i;iplatform.size();i++){ glRectf(current->platform[i].p1.x,current->platform[i].p1.y+yoff-DRAW_Y_OFFSET, @@ -273,6 +277,7 @@ void IndoorWorld::draw(vec2 *vec){ // 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); glBegin(GL_QUADS); for(i=i;i