Minor fixes
This commit is contained in:
		
							parent
							
								
									f6619d1289
								
							
						
					
					
						commit
						7acb37824e
					
				| @ -1,5 +1,6 @@ | |||||||
| #pragma once | #pragma once | ||||||
| #include <stdbool.h> | #include <stdbool.h> | ||||||
|  | #include <string.h> | ||||||
| 
 | 
 | ||||||
| #include "snake.h" | #include "snake.h" | ||||||
| #include "config.h" | #include "config.h" | ||||||
| @ -31,10 +32,20 @@ typedef struct gameData_t | |||||||
|   gameState_t gameState;  // state the game is in
 |   gameState_t gameState;  // state the game is in
 | ||||||
| } gameData_t; | } gameData_t; | ||||||
| 
 | 
 | ||||||
|  | 
 | ||||||
|  | // struct that store player score at the end of the game
 | ||||||
|  | typedef struct playerScore_t | ||||||
|  | { | ||||||
|  |     int score; | ||||||
|  |     char playerName[30]; | ||||||
|  |     int difficulty; | ||||||
|  |     char map[30]; | ||||||
|  | } playerScore_t; | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
| // global struct for storing all game data (defined in game.c)
 | // global struct for storing all game data (defined in game.c)
 | ||||||
| extern gameData_t game; | extern gameData_t game; | ||||||
| 
 | 
 | ||||||
| 
 |  | ||||||
| // run once at game start and does the following:
 | // run once at game start and does the following:
 | ||||||
| // - init snake
 | // - init snake
 | ||||||
| // - load map
 | // - load map
 | ||||||
| @ -50,4 +61,7 @@ void handlePortals(); //(ran in gameCycle) | |||||||
| // - moves snake to next position
 | // - moves snake to next position
 | ||||||
| // - handles collision, portals, food
 | // - handles collision, portals, food
 | ||||||
| // - triggers frame update (render.c)
 | // - triggers frame update (render.c)
 | ||||||
| void runGameCycle(); | void runGameCycle(); | ||||||
|  | 
 | ||||||
|  | // function which saves score in a .csv file
 | ||||||
|  |   // void savePlayerScore()
 | ||||||
| @ -56,12 +56,13 @@ extern ttlData_t ttlStorage; | |||||||
| 
 | 
 | ||||||
| extern menus_t activeMenu; | extern menus_t activeMenu; | ||||||
| 
 | 
 | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
| // edit various menus
 | // edit various menus
 | ||||||
| // is called up in main.cpp
 | // is called up in main.cpp
 | ||||||
| void manageMenu(); | void manageMenu(); | ||||||
| 
 | 
 | ||||||
| 
 |  | ||||||
| 
 |  | ||||||
| void showStartScreen(); | void showStartScreen(); | ||||||
| //zum Starten Enter drücken
 | //zum Starten Enter drücken
 | ||||||
| //optional: "E" eingeben für Settings
 | //optional: "E" eingeben für Settings
 | ||||||
|  | |||||||
							
								
								
									
										37
									
								
								src/game.c
									
									
									
									
									
								
							
							
						
						
									
										37
									
								
								src/game.c
									
									
									
									
									
								
							| @ -111,6 +111,7 @@ void runGameCycle() | |||||||
|         // TODO consider game.lifesRemaining and reset if still good?
 |         // TODO consider game.lifesRemaining and reset if still good?
 | ||||||
|         LOGI("game: collided with wall or self! => show leaderboard\n"); |         LOGI("game: collided with wall or self! => show leaderboard\n"); | ||||||
|         //game.gameState = MENU; //TODO add config.collisionEnabled option?
 |         //game.gameState = MENU; //TODO add config.collisionEnabled option?
 | ||||||
|  |         //savePlayerScore(/*(game.snake.length - config.snakeDefaultLength), ttlStorage.userName, config.difficulty, *storedMaps[ttlStorage.userSelectedMap - 1]*/);
 | ||||||
|         showLeaderboard(); |         showLeaderboard(); | ||||||
|         return; |         return; | ||||||
|     } |     } | ||||||
| @ -134,4 +135,38 @@ void runGameCycle() | |||||||
|     printMap(game.map); //render game to console
 |     printMap(game.map); //render game to console
 | ||||||
| #endif | #endif | ||||||
|     return; |     return; | ||||||
| } | } | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | //==========================
 | ||||||
|  | //==== savePlayerScores ====
 | ||||||
|  | //==========================
 | ||||||
|  | // void savePlayerScore(/*int score, int difficulty, const char *playerName,  const char *map*/) 
 | ||||||
|  | // {   
 | ||||||
|  | //     // playerScore_t playerScore;
 | ||||||
|  | 
 | ||||||
|  | //     // // copy data into struct
 | ||||||
|  | //     // playerScore.score = game.snake.length - config.snakeDefaultLength;
 | ||||||
|  | //     // playerScore.difficulty = config.difficulty;
 | ||||||
|  | //     // strcpy(playerScore.playerName, ttlStorage.userName);
 | ||||||
|  | //     // strcpy(playerScore.map, "testmap");
 | ||||||
|  |      | ||||||
|  | 
 | ||||||
|  | //     // FILE *file;
 | ||||||
|  | //     // // open file
 | ||||||
|  | //     // file = fopen("../player_scores.bin", "ab");
 | ||||||
|  | 
 | ||||||
|  | //     // // write data in file
 | ||||||
|  | //     // if (file != NULL) 
 | ||||||
|  | //     // {
 | ||||||
|  | //     //     fwrite(&playerScore, sizeof(playerScore_t), 1, file);
 | ||||||
|  | //     //     fclose(file);
 | ||||||
|  | 
 | ||||||
|  | //     //     LOGI("Spielergebnis wurde erfolgreich in die Binärdatei gespeichert.\n");
 | ||||||
|  | //     // } 
 | ||||||
|  | //     // else 
 | ||||||
|  | //     // {
 | ||||||
|  | //     //     LOGI("Fehler beim Öffnen der Datei!\n");
 | ||||||
|  | //     // }
 | ||||||
|  | // }
 | ||||||
|  | 
 | ||||||
|  | |||||||
| @ -1,5 +1,5 @@ | |||||||
| #include <math.h> | #include <math.h> | ||||||
| 
 | #include "render.h" | ||||||
| #include "input.h" | #include "input.h" | ||||||
| #include "common.h" | #include "common.h" | ||||||
| #include "SDL.h" | #include "SDL.h" | ||||||
|  | |||||||
| @ -3,6 +3,7 @@ | |||||||
| #include "sound.h" | #include "sound.h" | ||||||
| #include "common.h" | #include "common.h" | ||||||
| #include <stdio.h> | #include <stdio.h> | ||||||
|  | #include <math.h> | ||||||
| //#include <Windows.h>
 | //#include <Windows.h>
 | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| @ -56,6 +57,7 @@ void manageMenu() | |||||||
| 
 | 
 | ||||||
| // shows start screen with blinking ENTER
 | // shows start screen with blinking ENTER
 | ||||||
| void showStartScreen() | void showStartScreen() | ||||||
|  | 
 | ||||||
| { | { | ||||||
|     LOGD("menu: showing start-screen\n"); |     LOGD("menu: showing start-screen\n"); | ||||||
| 
 | 
 | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user