]> code.bitgloo.com Git - clyne/gamedev.git/commitdiff
improvements ;)
authorClyne Sullivan <tullivan99@gmail.com>
Tue, 6 Oct 2015 12:50:52 +0000 (08:50 -0400)
committerClyne Sullivan <tullivan99@gmail.com>
Tue, 6 Oct 2015 12:50:52 +0000 (08:50 -0400)
Changelog
Makefile
include/world.h
main.cpp
src/Makefile [new file with mode: 0644]
src/entities.cpp
src/world.cpp

index 540d8fefe5c6bb8f09a9f14ec64ec9ca0e4e42ad..fecb56d83ca1c7fa926085eaa340940f558b696d 100644 (file)
--- a/Changelog
+++ b/Changelog
        - 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
index d04582b3de9151ffdf2e0513d296776d01d6eb69..983f6365455310c3443f3ece46850d122525013e 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -1,21 +1,11 @@
-LIBS_LINUX = -lGL -lSDL2_image -lSDL2_mixer\r
-LIBS_WIN32 = -lopengl32 -lmingw32 -lSDL2_Image\r
+LIBS = -lGL -lSDL2_image -lSDL2_mixer\r
 \r
 FLAGS = -m32 -std=c++11 -Iinclude -Iinclude/freetype2 -lSDL2main -lSDL2 -lfreetype\r
 \r
-SRCS = $(wildcard src/*.cpp)\r
-\r
-OUT = $(SRCS:.cpp=.o)\r
-\r
-.cpp.o:\r
-       @echo "  CXX " $^\r
-       @g++ -o $@ -c $^ $(LIBS_LINUX) $(FLAGS)\r
-\r
-all: $(OUT)\r
-       @echo "Relocating object files..."\r
-       @mv ./src/*.o ./out\r
+all:\r
+       @cd src; $(MAKE) $(MFLAGS)\r
        @echo "  CXX main.cpp"\r
-       @g++ -o main main.cpp out/*.o $(LIBS_LINUX) $(FLAGS)\r
+       @g++ $(FLAGS) -o main main.cpp out/*.o $(LIBS)\r
 \r
 clean:\r
        @echo "  RM main"\r
index cf0b7b8fc1010056e862f3e8ff6016e40eddf2b5..7095c3bb1f8feb6867249e53f43f5ef0266ce9dc 100644 (file)
@@ -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)
index fdb7d32d601f7cb97368b1e315fc04b63ffd6dce..b9512cdc8ca072f8543fd9418626285dc27978c6 100644 (file)
--- 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 (file)
index 0000000..f75bee9
--- /dev/null
@@ -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))
index 42f93c8b6969195bb0db7dad6c5aa6c638700e61..5dc743c9ceba300e1c84409f2e637ce0155f80a6 100644 (file)
@@ -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);
        }
index d2cd3801cdc2ef91a96da67e3d5b3c928e0734e6..ef11002029e19be5343c007877f6239fcc9d7d5c 100644 (file)
@@ -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;i<ie-GEN_INC;i++){                                                              // For lines in array 'line' from 'i' to 'ie'
-                       cline[i].y+=(yoff-DRAW_Y_OFFSET);                       // 'yoff' is always one incrementation ahead of what it should be
-                       safeSetColor(shade,200+shade,shade);            // Safely set the grass color
+                       cline[i].y+=(yoff-DRAW_Y_OFFSET);                                       // 'yoff' is always one incrementation ahead of what it should be
+                       safeSetColor(shade,150+shade,shade);                            // Safely set the grass color
                        glVertex2i(cx_start+i*HLINE      ,cline[i].y);                                                                                  // Draw the grass area of the line
                        glVertex2i(cx_start+i*HLINE+HLINE,cline[i].y);
-                       glVertex2i(cx_start+i*HLINE+HLINE,cline[i].y-GRASS_HEIGHT);
-                       glVertex2i(cx_start+i*HLINE             ,cline[i].y-GRASS_HEIGHT);
+                       glVertex2i(cx_start+i*HLINE+HLINE,cline[i].y-GRASS_HEIGHT-cline[i].gh);
+                       glVertex2i(cx_start+i*HLINE             ,cline[i].y-GRASS_HEIGHT-cline[i].gh);
                        safeSetColor(cline[i].color+shade,cline[i].color-50+shade,cline[i].color-100+shade);    // Set the shaded dirt color (safely)
-                       glVertex2i(cx_start+i*HLINE      ,cline[i].y-GRASS_HEIGHT);                                                             // Draw the dirt area of the line
-                       glVertex2i(cx_start+i*HLINE+HLINE,cline[i].y-GRASS_HEIGHT);
+                       glVertex2i(cx_start+i*HLINE      ,cline[i].y-GRASS_HEIGHT-cline[i].gh);                                 // Draw the dirt area of the line
+                       glVertex2i(cx_start+i*HLINE+HLINE,cline[i].y-GRASS_HEIGHT-cline[i].gh);
                        glVertex2i(cx_start+i*HLINE+HLINE,0);
                        glVertex2i(cx_start+i*HLINE              ,0);
                        cline[i].y-=(yoff-DRAW_Y_OFFSET); // Reset 'cline[i]'`s y to what it was
                }
        glEnd();
+       shade*=-1;
        safeSetColor(255+shade*2,0+shade,0+shade);
        for(i=0;i<current->platform.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<ie-GEN_INC;i++){                                              // For lines in array 'line' from 'i' to 'ie'
                        safeSetColor(150,100,50);