Change folder structure (Add folders: src, include)
Add src folder for all .c and include folder .h files => clearer structure, no documents mixed into code files
This commit is contained in:
18
include/config.h
Normal file
18
include/config.h
Normal file
@@ -0,0 +1,18 @@
|
||||
#pragma once
|
||||
|
||||
// global configuration macros
|
||||
#define MAX_MAP_SIZE 10
|
||||
|
||||
// struct for storing game configuration
|
||||
typedef struct config_t
|
||||
{
|
||||
int mapWidth; // =10 //Kartenbreite
|
||||
int mapHeight; // =10 //Kartenhöhe
|
||||
int cycleDurationMs; // ms between each game loop iterartion (game speed)
|
||||
int difficulty; // 0-3 //Schwierigkeitsgrad
|
||||
int snakeDefaultLength; // = 2 //Länge der Schlange
|
||||
const char *leaderboardFilename; // Dateiname des Leaderboards
|
||||
} config_t;
|
||||
|
||||
// global config struct defined in config.c
|
||||
extern config_t config;
|
||||
5
include/food.h
Normal file
5
include/food.h
Normal file
@@ -0,0 +1,5 @@
|
||||
void placeFood(int cnt);
|
||||
// platziert zufällig (mit bestimmtem Algorithmus) Fressen auf dem Spielfeld
|
||||
|
||||
void ckeckEaten();
|
||||
// Überprüft, ob Snake gefressen hat
|
||||
46
include/game.h
Normal file
46
include/game.h
Normal file
@@ -0,0 +1,46 @@
|
||||
#include <stdbool.h>
|
||||
|
||||
#include "snake.h"
|
||||
#include "config.h"
|
||||
|
||||
typedef enum gameState_t
|
||||
{
|
||||
PAUSED = 0,
|
||||
MENU,
|
||||
RUNNING
|
||||
} gameState_t;
|
||||
|
||||
typedef struct gameData_t
|
||||
{
|
||||
snake_t snake;
|
||||
int mapCollisions[MAX_MAP_SIZE][MAX_MAP_SIZE]; // Position der Wände
|
||||
int mapPortals[MAX_MAP_SIZE][MAX_MAP_SIZE]; // Position der Portale
|
||||
|
||||
int foodX, foodY; // Positon des Futters (es gibt immer nur 1 Futter)
|
||||
int lifesRemaining; // implementieren wir nicht!!
|
||||
int timestampLastRun;
|
||||
bool isPaused;
|
||||
gameState_t gameState;
|
||||
} gameData_t;
|
||||
|
||||
// global struct for storing all game data (defined in game.c)
|
||||
extern gameData_t game;
|
||||
|
||||
void gameInit();
|
||||
// ruft snakeInit auf
|
||||
// ruft place Food auf
|
||||
|
||||
void handleCollision();
|
||||
// Überprüft, ob Snake mit Gegenstand/Wand kollidiert ist
|
||||
|
||||
void handlePortals(); // optional
|
||||
// Prüft, ob Snake sich auf einem Portal befindet
|
||||
|
||||
void runGameCycle();
|
||||
// macht immer: handleKeyboardEvents();
|
||||
// if TickDue: Snakemove(), TickTimerReset
|
||||
// optional: ruft checkCollision auf
|
||||
// ruft place food auf
|
||||
// ruft checkEaten auf
|
||||
// if checkEaten then snakeGrow
|
||||
// ruft snakeMove auf
|
||||
6
include/input.h
Normal file
6
include/input.h
Normal file
@@ -0,0 +1,6 @@
|
||||
void processInputEvent();
|
||||
//wird von SDL aufgerufen, wenn Taste gedrückt wurde
|
||||
//bekommt Info darüber, welche Taste gedrückt wurde
|
||||
//ruft zugehörige Aktion über switch caseauf
|
||||
// z.B. bei Pfeiltaste -> rufe snakeSetDir auf
|
||||
// im Menü bei Settings -> rufe menuNavigate auf
|
||||
14
include/menu.h
Normal file
14
include/menu.h
Normal file
@@ -0,0 +1,14 @@
|
||||
void showStartScreen();
|
||||
//zum Starten Enter drücken
|
||||
//optional: "E" eingeen für Settings
|
||||
|
||||
void showLeaderboard();
|
||||
//zeigt die besten Spieldurchläufe inkl. Punktestand an
|
||||
|
||||
void menuNavigate();
|
||||
//über Tastaturbefehle im Menü navigieren
|
||||
|
||||
void showSettings(); //optional
|
||||
//Menü zum Auswählen über Tastaturbefehle
|
||||
|
||||
void menuHandleInput();
|
||||
4
include/render.h
Normal file
4
include/render.h
Normal file
@@ -0,0 +1,4 @@
|
||||
#include "game.h"
|
||||
#include "snake.h"
|
||||
void renderGame(gameData_t game, snake_t snake);
|
||||
//erstellt aus Spielfeldstruktur die graphische Anzeige mit SDL-Framework
|
||||
43
include/snake.h
Normal file
43
include/snake.h
Normal file
@@ -0,0 +1,43 @@
|
||||
|
||||
#pragma once
|
||||
#include <stdbool.h>
|
||||
|
||||
typedef enum snakeDirection_t
|
||||
{
|
||||
DOWN = 0,
|
||||
UP,
|
||||
LEFT,
|
||||
RIGHT
|
||||
} snakeDirection_t; // Bewegungsrichtung
|
||||
|
||||
typedef struct snake_t
|
||||
{
|
||||
int length; // aktuelle Länge der Schlange
|
||||
int headX;
|
||||
int headY; // aktuelle Position der Schlange
|
||||
snakeDirection_t direction;
|
||||
int tail[512][2];
|
||||
bool isAlive; // lebt die Schlange noch oder ist sie mit sich selbst kollidiert?
|
||||
} snake_t;
|
||||
|
||||
void snakeInit();
|
||||
// Snake mit bestimmter Startlänge an Startposition erstellen
|
||||
// Speicherbereich reservieren
|
||||
|
||||
void snakeGrow();
|
||||
// Snake wird um 1 Glied länger (nach Fressen)
|
||||
|
||||
void snakeMove();
|
||||
// bewegt die Schlang einen Schritt in die aktuelle Richtung
|
||||
// ruft lokale Variable dir von snakeSetDir auf
|
||||
|
||||
void snakeSetDir(snakeDirection_t dir); // Richtung als Übergabeparameter
|
||||
// definiert aktuelle Bewegungsrichtung der Schlange
|
||||
|
||||
bool snakeIsAlive();
|
||||
// Überprüfen, ob Schlange noch lebt
|
||||
// Prüft Kollision mit sich selbst
|
||||
|
||||
void snakeSetHeadPos(); // optional
|
||||
// für handlePortals
|
||||
// generiert zufällige Zielsposition, wohin sich die Schlange nach Betreten eines Portals bewegt
|
||||
Reference in New Issue
Block a user