diff --git a/auto.c b/auto.c index 68b2fb1ef6a0f47c6a460b8ae3238bd448732bdc..61e9f9582b17ac0bf7c11958c83aa9a94c10182c 100644 --- a/auto.c +++ b/auto.c @@ -1,4 +1,4 @@ -#include "auto.h" +#include "hDateien/auto.h" // Vorbedinung: diff --git a/charac.c b/charac.c index 680acb8a4b872091e6b61719964eb7930b91bc30..7fe9c874f5fb6436d2bf3b77dfb376e1a8148e46 100644 --- a/charac.c +++ b/charac.c @@ -1,5 +1,5 @@ -#include "charac.h" +#include "hDateien/charac.h" /* Vorbedingung: Es wurde eine Taste gedrückt diff --git a/file_own.c b/file_own.c index 3ef3ac91a2bb73333388ee7f9d106c53424cfed6..5b7657027466c221dfca39097045ddf4d24ab2a1 100644 --- a/file_own.c +++ b/file_own.c @@ -1,4 +1,4 @@ -#include "file_own.h" +#include "hDateien/file_own.h" //V: playerhighscore exists and score.txt exists //N if playerhighscore > current score; playerhighscore is written into corresponding space in score.txt. The rest is rewritten into score.txt (including the theme if playerhighscore < score) diff --git a/gameLoop.c b/gameLoop.c index a9d7ca0735766edb9be0f46f354e8f6884ddd993..8a678527740ceefb8e347dbc74764bef2c6616ee 100644 --- a/gameLoop.c +++ b/gameLoop.c @@ -1,4 +1,4 @@ -#include "gameLoop.h" +#include "hDateien/gameLoop.h" SDL_Rect *player; diff --git a/auto.h b/hDateien/auto.h similarity index 86% rename from auto.h rename to hDateien/auto.h index 64ea4da8f24aac5372afb2e1de26b7b83b02050b..8327cbfc3efe82798cab1d9f2b1f3a0ad6955ea3 100644 --- a/auto.h +++ b/hDateien/auto.h @@ -6,9 +6,6 @@ #include <stdlib.h> #include <stdbool.h> #include "output.h" -//#include "map.h" -//#include "rows.h" -//#include "gameLoop.h" #include "header.h" //Declarations of functions diff --git a/charac.h b/hDateien/charac.h similarity index 100% rename from charac.h rename to hDateien/charac.h diff --git a/file_own.h b/hDateien/file_own.h similarity index 100% rename from file_own.h rename to hDateien/file_own.h diff --git a/gameLoop.h b/hDateien/gameLoop.h similarity index 100% rename from gameLoop.h rename to hDateien/gameLoop.h diff --git a/header.h b/hDateien/header.h similarity index 100% rename from header.h rename to hDateien/header.h diff --git a/init.h b/hDateien/init.h similarity index 90% rename from init.h rename to hDateien/init.h index 56e6784acb8890842857354b765654e9b61ab83f..42290cad922fe0904b302defa2b96f34f70cf90b 100644 --- a/init.h +++ b/hDateien/init.h @@ -8,7 +8,9 @@ //Declaration of functions -int init(SDL_Renderer*); +SDL_Window* init_window(void); +SDL_Renderer* init_renderer(SDL_Window*); +int init_images(SDL_Renderer*); int exitGame(SDL_Renderer*,SDL_Window* window); diff --git a/main.h b/hDateien/main.h similarity index 100% rename from main.h rename to hDateien/main.h diff --git a/map.h b/hDateien/map.h similarity index 100% rename from map.h rename to hDateien/map.h diff --git a/menu2.h b/hDateien/menu2.h similarity index 100% rename from menu2.h rename to hDateien/menu2.h diff --git a/output.h b/hDateien/output.h similarity index 100% rename from output.h rename to hDateien/output.h diff --git a/rows.h b/hDateien/rows.h similarity index 100% rename from rows.h rename to hDateien/rows.h diff --git a/title_screen.h b/hDateien/title_screen.h similarity index 100% rename from title_screen.h rename to hDateien/title_screen.h diff --git a/init.c b/init.c index 89b674a4758dae83f344e87107c640e3286ab58d..f3be29e7d1f1bf3e13e12c8bb1cc4cd40da171cd 100644 --- a/init.c +++ b/init.c @@ -1,4 +1,4 @@ -#include "init.h" +#include "hDateien/init.h" //Lädt Texturen rein SDL_Texture *img_grassDark; @@ -23,9 +23,44 @@ SDL_Texture *img_duck; SDL_Texture *img_3D_Duck; TTF_Font* font; +SDL_Window* init_window(){ + SDL_Window *window = SDL_CreateWindow("Smashy Roads", SDL_WINDOWPOS_UNDEFINED, + SDL_WINDOWPOS_UNDEFINED, SCREEN_WIDTH, + SCREEN_HEIGHT, SDL_WINDOW_SHOWN); + + if (window == NULL){ + SDL_Log("Es gab einen Fehler beim Erstellen des Fensters! SDL_Error: %s\n",SDL_GetError()); + exit(-1); + } + + return(window); +} + +SDL_Renderer* init_renderer(SDL_Window *window){ + SDL_Renderer *renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_PRESENTVSYNC); + + if (renderer == NULL) { + SDL_Log("Renderer konnte nicht erstellt werden! SDL_Error: %s\n",SDL_GetError()); + exit(-1); + } + + if (SDL_RenderClear(renderer) != 0) { + SDL_Log("Renderer konnte nicht bereinigt werden! SDL_Error: %s\n",SDL_GetError()); + exit(-1); + } + + if (SDL_SetRenderDrawBlendMode(renderer, SDL_BLENDMODE_BLEND) != 0) { + SDL_Log("Blendmode konnte nicht aktualisiert werden (main.c)! SDL_Error: %s\n",SDL_GetError()); + exit(-1); + } + return(renderer); + +} + + //V: all images and fonts to load are in file images //N: images and fonts have been loaded into renderer -int init(SDL_Renderer* renderer) { +int init_images(SDL_Renderer* renderer) { //Initiiere Text TTF_Init(); diff --git a/main.c b/main.c index f0cacc84876ebac90ffd76068d561fc23eda3089..c6552cd89e29ced90cdc6191cae185b04741a029 100644 --- a/main.c +++ b/main.c @@ -1,11 +1,13 @@ // v1.0 -#include "main.h" +#include "hDateien/main.h" //V: SDL2 is installed //N: Game is closed //E: You played the game + + int main(void) { // Initialiserung des Zufallgenerators @@ -17,34 +19,12 @@ int main(void) { return(-1); } - SDL_Window *window = SDL_CreateWindow("Smashy Roads", SDL_WINDOWPOS_UNDEFINED, - SDL_WINDOWPOS_UNDEFINED, SCREEN_WIDTH, - SCREEN_HEIGHT, SDL_WINDOW_SHOWN); + SDL_Window *window = init_window(); - if (window == NULL){ - SDL_Log("Es gab einen Fehler beim Erstellen des Fensters! SDL_Error: %s\n",SDL_GetError()); - return(-1); - } - - SDL_Renderer *renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_PRESENTVSYNC); - - if (renderer == NULL) { - SDL_Log("Renderer konnte nicht erstellt werden! SDL_Error: %s\n",SDL_GetError()); - return(-1); - } - - if (SDL_RenderClear(renderer) != 0) { - SDL_Log("Renderer konnte nicht bereinigt werden! SDL_Error: %s\n",SDL_GetError()); - return(-1); - } - - if (SDL_SetRenderDrawBlendMode(renderer, SDL_BLENDMODE_BLEND) != 0) { - SDL_Log("Blendmode konnte nicht aktualisiert werden (main.c)! SDL_Error: %s\n",SDL_GetError()); - return(-1); - }; + SDL_Renderer *renderer = init_renderer(window); //Initialisierung der Bilder und Fonts - if (init(renderer)){ + if (init_images(renderer)){ printf("Fehler beim laden der Bilder"); return(-1); } diff --git a/map.c b/map.c index ba624c8519a7c3a7f91266b01ea95d127877e93d..61df72abf58449352d35dd0baafdd7dcaf0223c8 100644 --- a/map.c +++ b/map.c @@ -1,4 +1,4 @@ -#include "map.h" +#include "hDateien/map.h" // Vorbedingung: 0 <= player->y <= 1000, 0 <= player->x <= 900 diff --git a/menu2.c b/menu2.c index 616f5c59dda9016f4f6c8a690903aa6fa1d8588f..e71cc0a56da61f09f441f7f2d624ba395d5a8f8a 100644 --- a/menu2.c +++ b/menu2.c @@ -1,4 +1,4 @@ -#include "menu2.h" +#include "hDateien/menu2.h" // Vorb.: Die Funktion zeigt die möglichen Reihen des Spiels // Nachb.: Wenn man auf eine Reihe klickt, dann wir das Spiel mit einer bestimmten diff --git a/output.c b/output.c index 754b652260c9a56eda84ee603e1b74327d99ea14..976e0d7aa6e9b89d4c9b5b1ae21bd3c946fee0df 100644 --- a/output.c +++ b/output.c @@ -1,4 +1,4 @@ -#include "output.h" +#include "hDateien/output.h" //V: renderer exists, enum row_type is correct and not renamed, correct y coordinates are transferred //N: img corresponding to row_type is set to coordinates: x: 0 to 900 y: y to y+100 and displayed via renderer diff --git a/rows.c b/rows.c index b2bf23970695c53876e746f317f89aff2f6a04e7..b9674eed2da2b7efbd7c69e9043a9ee691cb9907 100644 --- a/rows.c +++ b/rows.c @@ -1,5 +1,4 @@ -#include "rows.h" - +#include "hDateien/rows.h" //Vorbedingung: -200<=y_pos<=1000 @@ -116,13 +115,13 @@ struct Row* init_row(struct Row *m){ int p; // Ziellinie erscheint alle 100 Punkte - if(playerhighscore + (player->y/ROW_SIZE) % 100 == 98){ + if((playerhighscore + (player->y/ROW_SIZE)) % 100 == 98){ if (m->row_type != grassDark && m->row_type != waterDarkSingle && m->row_type != waterDarkMultiple){ n = grass(true,true,m->y_pos - ROW_SIZE); }else{ - n = grass(false,true,m->y_pos - 100); + n = grass(false,true,m->y_pos - ROW_SIZE); } // Nach einer Ziellinie kommt immer Gras diff --git a/title_screen.c b/title_screen.c index bf1964964c2de926f27189a8cc10961b55dbb913..a2d12ddc2eacb55ee74fa51d8234387e7dac2d8d 100644 --- a/title_screen.c +++ b/title_screen.c @@ -1,4 +1,4 @@ -#include "title_screen.h" +#include "hDateien/title_screen.h" /* Vorbindung: Es existiert ein SDL_Renderer Nachbedingung: /