Skip to content
Snippets Groups Projects
Commit b5858e07 authored by antoinemeyer5's avatar antoinemeyer5
Browse files

coherence noms des variables, fonctions, etc

parent 0be3e93a
No related branches found
No related tags found
No related merge requests found
No preview for this file type
...@@ -4,9 +4,9 @@ int hover[2]; ...@@ -4,9 +4,9 @@ int hover[2];
int x; int x;
int y; int y;
int Keys[10]; int keys[10];
void gestMenu(){ void manageMenu(){
SDL_Event event; SDL_Event event;
while (SDL_PollEvent(&event)){ while (SDL_PollEvent(&event)){
switch(event.type) switch(event.type)
...@@ -23,19 +23,19 @@ void gestMenu(){ ...@@ -23,19 +23,19 @@ void gestMenu(){
continue; continue;
case SDLK_UP: case SDLK_UP:
Keys[0] = 0; keys[0] = 0;
break; break;
case SDLK_DOWN: case SDLK_DOWN:
Keys[1] = 0; keys[1] = 0;
break; break;
case SDLK_LEFT: case SDLK_LEFT:
Keys[2] = 0; keys[2] = 0;
break; break;
case SDLK_RIGHT: case SDLK_RIGHT:
Keys[3] = 0; keys[3] = 0;
break; break;
default: default:
...@@ -51,19 +51,19 @@ void gestMenu(){ ...@@ -51,19 +51,19 @@ void gestMenu(){
continue; continue;
case SDLK_UP: case SDLK_UP:
Keys[0] = 1; keys[0] = 1;
break; break;
case SDLK_DOWN: case SDLK_DOWN:
Keys[1] = 1; keys[1] = 1;
break; break;
case SDLK_LEFT: case SDLK_LEFT:
Keys[2] = 1; keys[2] = 1;
break; break;
case SDLK_RIGHT: case SDLK_RIGHT:
Keys[3] = 1; keys[3] = 1;
break; break;
default: default:
...@@ -72,7 +72,7 @@ void gestMenu(){ ...@@ -72,7 +72,7 @@ void gestMenu(){
break; break;
case SDL_MOUSEMOTION: case SDL_MOUSEMOTION:
x = (event.motion.x - (ScreenDimension.w - (MAPSIZE * CELLSIZE)) / 2) / CELLSIZE; x = (event.motion.x - (screenDimension.w - (MAPSIZE * CELLSIZE)) / 2) / CELLSIZE;
y = (event.motion.y - 0) / CELLSIZE; y = (event.motion.y - 0) / CELLSIZE;
hover[0] = x; hover[0] = x;
hover[1] = y; hover[1] = y;
...@@ -82,16 +82,16 @@ void gestMenu(){ ...@@ -82,16 +82,16 @@ void gestMenu(){
continue; continue;
} }
} }
GestMovement(); manageMovement();
SDL_Delay(5); SDL_Delay(5);
} }
void *EventLoop(void *arg){ void *eventLoop(void *arg){
while(running){ while(running){
switch(game_state){ switch(gameState){
case MENU : gestMenu();break; case MENU : manageMenu();break;
case GAME : gestMenu();break; case GAME : manageMenu();break;
default:printf("game state fault");break; default:printf("game state fault");break;
} }
} }
......
...@@ -6,8 +6,8 @@ ...@@ -6,8 +6,8 @@
#include "render.h" #include "render.h"
extern int hover[2]; extern int hover[2];
extern int Keys[10]; extern int keys[10];
void *EventLoop(void *arg); void *eventLoop(void *arg);
#endif #endif
\ No newline at end of file
#include "main.h" #include "main.h"
int running; int running;
int game_state; int gameState;
int main(){ int main(){
running = 1; running = 1;
game_state = GAME; gameState = GAME;
readMapFromFile("map.txt"); readMapFromFile("map.txt");
initPlayer(); initPlayer();
MainLoop(); mainLoop();
} }
\ No newline at end of file
...@@ -24,7 +24,7 @@ ...@@ -24,7 +24,7 @@
#define GAME 1 #define GAME 1
extern int running; extern int running;
extern int game_state; extern int gameState;
#endif #endif
\ No newline at end of file
...@@ -5,8 +5,6 @@ ...@@ -5,8 +5,6 @@
#define MAPSIZE 20 #define MAPSIZE 20
extern int map[MAPSIZE][MAPSIZE]; extern int map[MAPSIZE][MAPSIZE];
void readMapFromFile(char * filename); void readMapFromFile(char * filename);
......
#include "player.h" #include "player.h"
Player_t player; player_t player;
void initPlayer(){ void initPlayer(){
player.x = 0; player.x = 0;
player.y = 0; player.y = 0;
player.water_level = 0; player.waterLevel = 0;
} }
void GestMovement(){ void manageMovement(){
if(Keys[0] == 1){ if(keys[0] == 1){
player.y--; player.y--;
} }
if(Keys[1] == 1){ if(keys[1] == 1){
player.y++; player.y++;
} }
if(Keys[2] == 1){ if(keys[2] == 1){
player.x--; player.x--;
} }
if(Keys[3] == 1){ if(keys[3] == 1){
player.x++; player.x++;
} }
} }
...@@ -4,15 +4,15 @@ ...@@ -4,15 +4,15 @@
#include "main.h" #include "main.h"
#include "gest_event.h" #include "gest_event.h"
typedef struct Player{ typedef struct player{
int x; int x;
int y; int y;
int water_level; int waterLevel;
} Player_t; } player_t;
extern Player_t player; extern player_t player;
void initPlayer(); void initPlayer();
void GestMovement(); void manageMovement();
#endif #endif
\ No newline at end of file
...@@ -3,8 +3,8 @@ ...@@ -3,8 +3,8 @@
SDL_Window *window; SDL_Window *window;
SDL_Renderer *renderer; SDL_Renderer *renderer;
TTF_Font *RobotoFont; TTF_Font *robotoFont;
SDL_DisplayMode ScreenDimension; SDL_DisplayMode screenDimension;
SDL_Surface * grassSurface; SDL_Surface * grassSurface;
SDL_Texture * grassTexture; SDL_Texture * grassTexture;
...@@ -18,16 +18,16 @@ SDL_Texture * hoverTexture; ...@@ -18,16 +18,16 @@ SDL_Texture * hoverTexture;
SDL_Surface * playerSurface; SDL_Surface * playerSurface;
SDL_Texture * playerTexture; SDL_Texture * playerTexture;
void CreateWindow(){ void createWindow(){
if (SDL_Init(SDL_INIT_VIDEO) != 0){ if (SDL_Init(SDL_INIT_VIDEO) != 0){
printf("Couldn't create window."); printf("Couldn't create window.");
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
SDL_GetCurrentDisplayMode(0, &ScreenDimension); SDL_GetCurrentDisplayMode(0, &screenDimension);
window = SDL_CreateWindow("Game Of Life", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, ScreenDimension.w, ScreenDimension.h, SDL_WINDOW_INPUT_GRABBED | SDL_WINDOW_SHOWN | SDL_WINDOW_FULLSCREEN_DESKTOP); window = SDL_CreateWindow("Game Of Life", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, screenDimension.w, screenDimension.h, SDL_WINDOW_INPUT_GRABBED | SDL_WINDOW_SHOWN | SDL_WINDOW_FULLSCREEN_DESKTOP);
if (window == NULL){ if (window == NULL){
printf("Couldn't create window"); printf("Couldn't create window");
...@@ -46,7 +46,7 @@ void CreateWindow(){ ...@@ -46,7 +46,7 @@ void CreateWindow(){
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
RobotoFont = TTF_OpenFont("Res/Roboto-Black.ttf", 50); robotoFont = TTF_OpenFont("Res/Roboto-Black.ttf", 50);
} }
...@@ -55,7 +55,7 @@ void drawMap(){ ...@@ -55,7 +55,7 @@ void drawMap(){
SDL_Rect rect; SDL_Rect rect;
rect.h = CELLSIZE; rect.h = CELLSIZE;
rect.w = CELLSIZE; rect.w = CELLSIZE;
rect.x = (ScreenDimension.w - (MAPSIZE * CELLSIZE)) / 2; // centers the drawing rect.x = (screenDimension.w - (MAPSIZE * CELLSIZE)) / 2; // centers the drawing
rect.y = 0; rect.y = 0;
for(i = 0; i < MAPSIZE; i++){ for(i = 0; i < MAPSIZE; i++){
for(j = 0; j < MAPSIZE; j++){ for(j = 0; j < MAPSIZE; j++){
...@@ -68,7 +68,7 @@ void drawMap(){ ...@@ -68,7 +68,7 @@ void drawMap(){
} }
rect.x += CELLSIZE; rect.x += CELLSIZE;
} }
rect.x = (ScreenDimension.w - (MAPSIZE * CELLSIZE)) / 2; rect.x = (screenDimension.w - (MAPSIZE * CELLSIZE)) / 2;
rect.y += CELLSIZE; rect.y += CELLSIZE;
} }
} }
...@@ -77,7 +77,7 @@ void drawPlayer(){ ...@@ -77,7 +77,7 @@ void drawPlayer(){
SDL_Rect rect; SDL_Rect rect;
rect.h = CELLSIZE; rect.h = CELLSIZE;
rect.w = CELLSIZE; rect.w = CELLSIZE;
rect.x = player.x + (ScreenDimension.w - (MAPSIZE * CELLSIZE)) / 2; rect.x = player.x + (screenDimension.w - (MAPSIZE * CELLSIZE)) / 2;
rect.y = player.y ; rect.y = player.y ;
SDL_Rect destRect = {32 * (SDL_GetTicks()/200%4), 0, 32, 32}; SDL_Rect destRect = {32 * (SDL_GetTicks()/200%4), 0, 32, 32};
SDL_RenderCopyEx(renderer, playerTexture, &destRect, &rect, 0, NULL, SDL_FLIP_NONE); SDL_RenderCopyEx(renderer, playerTexture, &destRect, &rect, 0, NULL, SDL_FLIP_NONE);
...@@ -90,8 +90,8 @@ void drawGame(){ ...@@ -90,8 +90,8 @@ void drawGame(){
SDL_RenderPresent(renderer); SDL_RenderPresent(renderer);
} }
void MainLoop(){ void mainLoop(){
CreateWindow(); createWindow();
grassSurface = IMG_Load("Res/grass.png"); grassSurface = IMG_Load("Res/grass.png");
grassTexture = SDL_CreateTextureFromSurface(renderer, grassSurface); grassTexture = SDL_CreateTextureFromSurface(renderer, grassSurface);
...@@ -115,7 +115,7 @@ void MainLoop(){ ...@@ -115,7 +115,7 @@ void MainLoop(){
double delta = 0; double delta = 0;
pthread_t eventThread; pthread_t eventThread;
if (pthread_create(&eventThread, NULL, EventLoop, NULL) != 0){ if (pthread_create(&eventThread, NULL, eventLoop, NULL) != 0){
printf("Couldn't create thread."); printf("Couldn't create thread.");
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
...@@ -125,7 +125,7 @@ void MainLoop(){ ...@@ -125,7 +125,7 @@ void MainLoop(){
delta = (a - b) / 1000.0; delta = (a - b) / 1000.0;
if (delta > 1/FPS_TO_GET){ if (delta > 1/FPS_TO_GET){
b = a; b = a;
switch (game_state){ switch (gameState){
case MENU: case MENU:
//Menu(); //Menu();
break; break;
......
...@@ -6,13 +6,13 @@ ...@@ -6,13 +6,13 @@
#include "player.h" #include "player.h"
#define FPS_TO_GET 60 #define FPS_TO_GET 60
#define CELLSIZE (ScreenDimension.h / MAPSIZE) #define CELLSIZE (screenDimension.h / MAPSIZE)
extern SDL_Window *window; extern SDL_Window *window;
extern SDL_Renderer *renderer; extern SDL_Renderer *renderer;
extern SDL_DisplayMode ScreenDimension; extern SDL_DisplayMode screenDimension;
void drawHover(int x, int y); void drawHover(int x, int y);
void MainLoop(); void mainLoop();
#endif #endif
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment