diff --git a/travail_de_groupe/chef_oeuvre/Res/Roboto-Black.ttf b/travail_de_groupe/chef_oeuvre/Res/Roboto-Black.ttf new file mode 100644 index 0000000000000000000000000000000000000000..86ec2b29ba56a3d6c45f1a8584ff3780fa70c60e Binary files /dev/null and b/travail_de_groupe/chef_oeuvre/Res/Roboto-Black.ttf differ diff --git a/travail_de_groupe/chef_oeuvre/Res/character_idle_spritesheet.png b/travail_de_groupe/chef_oeuvre/Res/character_idle_spritesheet.png new file mode 100755 index 0000000000000000000000000000000000000000..47a5c276d8aedab5461ae2e37331f545ecf61fbe Binary files /dev/null and b/travail_de_groupe/chef_oeuvre/Res/character_idle_spritesheet.png differ diff --git a/travail_de_groupe/chef_oeuvre/Res/character_tileset.png b/travail_de_groupe/chef_oeuvre/Res/character_tileset.png new file mode 100755 index 0000000000000000000000000000000000000000..10a2a7345a6109a55c646a6dddca2ddbb6ee1cf5 Binary files /dev/null and b/travail_de_groupe/chef_oeuvre/Res/character_tileset.png differ diff --git a/travail_de_groupe/chef_oeuvre/Res/fire_spritesheet.png b/travail_de_groupe/chef_oeuvre/Res/fire_spritesheet.png new file mode 100755 index 0000000000000000000000000000000000000000..5d4c8fb76341e7f72f61bbc2eb20c55db3415567 Binary files /dev/null and b/travail_de_groupe/chef_oeuvre/Res/fire_spritesheet.png differ diff --git a/travail_de_groupe/chef_oeuvre/Res/score.png b/travail_de_groupe/chef_oeuvre/Res/score.png new file mode 100755 index 0000000000000000000000000000000000000000..0a61c7e238b8eea05cae0d000a7bfccf29aa2194 Binary files /dev/null and b/travail_de_groupe/chef_oeuvre/Res/score.png differ diff --git a/travail_de_groupe/chef_oeuvre/markov.txt b/travail_de_groupe/chef_oeuvre/markov.txt index dd3380684e771c77605b4c1344704b94bb324981..5a5f989e4d61b12dad907467cb58fc1dd38f067b 100644 --- a/travail_de_groupe/chef_oeuvre/markov.txt +++ b/travail_de_groupe/chef_oeuvre/markov.txt @@ -1,4 +1,5 @@ -1 0 0 0 -0 1 0 0 -0 0 1 0 -0 0 0 1 \ No newline at end of file +90 10 0 0 0 +0 80 20 0 0 +0 10 80 10 0 +0 0 10 50 40 +0 0 0 50 50 \ No newline at end of file diff --git a/travail_de_groupe/chef_oeuvre/src/fire.c b/travail_de_groupe/chef_oeuvre/src/fire.c index 4a798d47939bb9b4c608dc1164ac32d6a115d34c..3082b7967a37f1ed86b225e74e7184c5b4f25789 100644 --- a/travail_de_groupe/chef_oeuvre/src/fire.c +++ b/travail_de_groupe/chef_oeuvre/src/fire.c @@ -161,7 +161,6 @@ void nextFire(listchainfire_t listFire){ int pSparkle; int pMedium; int pStrong; - int pSpread; listchainfire_t listTemporary; listTemporary= listFire; @@ -171,23 +170,71 @@ void nextFire(listchainfire_t listFire){ state=(listTemporary->fire).state; probability= rand()%101; - pDead=markov[state][DEAD]*100; - pSparkle=(markov[state][SPARKLE]+markov[state][DEAD])*100; + pDead=markov[state][DEAD]; + pSparkle=(markov[state][SPARKLE]+markov[state][DEAD]); - pMedium=(markov[state][SPARKLE]+markov[state][DEAD]+markov[state][MEDIUM])*100; + pMedium=(markov[state][SPARKLE]+markov[state][DEAD]+markov[state][MEDIUM]); pStrong=(markov[state][SPARKLE]+markov[state][DEAD]+ - markov[state][MEDIUM]+markov[state][STRONG])*100; + markov[state][MEDIUM]+markov[state][STRONG]); - pSpread=(markov[state][SPARKLE]+markov[state][DEAD]+ - markov[state][MEDIUM]+markov[state][STRONG]+markov[state][SPREAD])*100; - if (0<=probability<pDead){(listTemporary->fire).state=DEAD;} - else if (pDead<=probability<pSparkle){(listTemporary->fire).state=SPARKLE;} - else if (pSparkle<=probability<pMedium){(listTemporary->fire).state=MEDIUM;} - else if (pMedium<=probability<pStrong){(listTemporary->fire).state=STRONG;} + if ((0<=probability)&&(probability<pDead)){(listTemporary->fire).state=DEAD;} + else if ((pDead<=probability)&&(probability<pSparkle)){(listTemporary->fire).state=SPARKLE;} + else if ((pSparkle<=probability)&&(probability<pMedium)){(listTemporary->fire).state=MEDIUM;} + else if ((pMedium<=probability)&&(probability<pStrong)){(listTemporary->fire).state=STRONG;} else {(listTemporary->fire).state=SPREAD;} + printf("%d %d\n", probability, state); + printf("%d %d %d %d\n", pDead, pSparkle, pMedium, pStrong); + listTemporary=listTemporary->next; } -} \ No newline at end of file +} + +listchainfire_t probabilitySpreadFire( listchainfire_t listFire, listchainfire_t listTemporary){ + int probability; + fire_t fire; + + probability= rand()%4; + printf("proba:%d\n", probability); + printf("listfire1: x%d,y%d\n",(listFire->fire).x,(listFire->fire).y); + + if((probability==0)&&((listTemporary->fire).x+1<MAPSIZE)){fire.state=1; + fire.x=(listTemporary->fire).x+1; + fire.y=(listTemporary->fire).y; + listFire=insertAheadFire(fire,listFire); + } + if ((probability==1)&&((listTemporary->fire).y+1<MAPSIZE)){fire.state=1; + fire.x=(listTemporary->fire).x; + fire.y=(listTemporary->fire).y+1; + listFire=insertAheadFire(fire,listFire); + } + if ((probability==2)&&((listTemporary->fire).y-1>=0)){fire.state=1; + fire.x=(listTemporary->fire).x; + fire.y=(listTemporary->fire).y-1; + listFire=insertAheadFire(fire,listFire); + } + if ((probability==3)&&((listTemporary->fire).x-1>=0)){fire.state=1; + fire.x=(listTemporary->fire).x-1; + fire.y=(listTemporary->fire).y; + listFire=insertAheadFire(fire,listFire); + } + printf("listtemp1: x%d,y%d\n",(listTemporary->fire).x,(listTemporary->fire).y); + printf("listfire2: x%d,y%d\n",(listFire->fire).x,(listFire->fire).y); + return listFire; +} + +listchainfire_t spreadFire (listchainfire_t listFire){ + listchainfire_t listTemporary=fireList; + srand(time(NULL)); + while (!emptyListFire(listTemporary)){ + if ((listTemporary->fire).state==4){ + + listFire=probabilitySpreadFire(listFire, listTemporary); + printf("listfire ajout: x%d,y%d\n",(listFire->fire).x,(listFire->fire).y); + } + listTemporary=listTemporary->next; + } + return listFire; +} \ No newline at end of file diff --git a/travail_de_groupe/chef_oeuvre/src/fire.h b/travail_de_groupe/chef_oeuvre/src/fire.h index 510c4b291093d5e8b9e79df74c5442dda06fb8ff..ea537e23abfc605dd840f3d6685e4ba7a06581da 100644 --- a/travail_de_groupe/chef_oeuvre/src/fire.h +++ b/travail_de_groupe/chef_oeuvre/src/fire.h @@ -6,7 +6,7 @@ #include <time.h> #include <stdio.h> -#define SIZEMARKOV 4 +#define SIZEMARKOV 5 #define DEAD 0 #define SPARKLE 1 #define MEDIUM 2 @@ -44,9 +44,13 @@ listchainfire_t deleteAheadFire(listchainfire_t); listchainfire_t deleteFire (listchainfire_t, int ,int ); listchainfire_t freeListFire (listchainfire_t ); listchainfire_t offFire (listchainfire_t, int,int ); -void travelFire(listchainfire_t listFire); +void travelFire(listchainfire_t ); void readFapFromFile(char * filename); void nextFire(listchainfire_t ); +listchainfire_t probabilitySpreadFire( listchainfire_t, listchainfire_t); +listchainfire_t spreadFire (listchainfire_t ); + + #endif \ No newline at end of file diff --git a/travail_de_groupe/chef_oeuvre/src/gest_event.c b/travail_de_groupe/chef_oeuvre/src/gest_event.c index caad8317dca7bb341842856eba8c5e14dff9a70a..92749b566d57083cf004fb92a5d554e70ce79845 100644 --- a/travail_de_groupe/chef_oeuvre/src/gest_event.c +++ b/travail_de_groupe/chef_oeuvre/src/gest_event.c @@ -128,7 +128,12 @@ void manageGame(){ continue; case SDL_MOUSEBUTTONDOWN: - pourWater(mousePosition.x, mousePosition.y); + //clic on water + if(2 == map[mousePosition.y][mousePosition.x]){ + fillWater(mousePosition.x, mousePosition.y); + }else{ + pourWater(mousePosition.x, mousePosition.y); + } break; default: diff --git a/travail_de_groupe/chef_oeuvre/src/main.c b/travail_de_groupe/chef_oeuvre/src/main.c index b6868c9fa9b7b35e119c484f7e75d7fbe5a582fb..2ce91a51061e2f16521276e0e43cc90a0bfd3a93 100644 --- a/travail_de_groupe/chef_oeuvre/src/main.c +++ b/travail_de_groupe/chef_oeuvre/src/main.c @@ -8,7 +8,11 @@ int main(){ running = 1; gameState = MENU; readMapFromFile("map.txt"); + readFapFromFile("markov.txt"); fireList = startFire(fireList,10,MAPSIZE); travelFire(fireList); + nextFire(fireList); + nextFire(fireList); + nextFire(fireList); mainLoop(); } \ No newline at end of file diff --git a/travail_de_groupe/chef_oeuvre/src/player.c b/travail_de_groupe/chef_oeuvre/src/player.c index cc5135b7b723da9287fb87cca4890714b0933639..865f3a155734ad29523334da798fcb11935dac56 100644 --- a/travail_de_groupe/chef_oeuvre/src/player.c +++ b/travail_de_groupe/chef_oeuvre/src/player.c @@ -32,7 +32,10 @@ int collisionsLeftPlayer(){ if(dotTopLeft==1 || dotDownLeft==1){ collision = 1; } - + //collision water + if(dotTopLeft==2 || dotDownLeft==2){ + collision = 1; + } return collision; } @@ -48,6 +51,10 @@ int collisionsRightPlayer(){ if(dotTopRight==1 || dotDownRight==1){ collision = 1; } + //collision water + if(dotTopRight==2 || dotDownRight==2){ + collision = 1; + } return collision; } @@ -63,6 +70,10 @@ int collisionsUpPlayer(){ if(dotTopRight==1 || dotTopLeft==1){ collision = 1; } + //collision water + if(dotTopRight==2 || dotTopLeft==2){ + collision = 1; + } return collision; } @@ -78,6 +89,10 @@ int collisionsDownPlayer(){ if(dotDownRight==1 || dotDownLeft==1){ collision = 1; } + //collision water + if(dotDownRight==2 || dotDownLeft==2){ + collision = 1; + } return collision; } @@ -109,20 +124,24 @@ void manageMovement(){ if(keys[PLAYER_UP]){ moveUpPlayer(); player.isMoving = 1; + player.direction = PLAYER_UP; } - if(keys[PLAYER_DOWN]){ + else if(keys[PLAYER_DOWN]){ moveDownPlayer(); player.isMoving = 1; + player.direction = PLAYER_DOWN; } - if(keys[PLAYER_LEFT]){ + else if(keys[PLAYER_LEFT]){ moveLeftPlayer(); player.isMoving = 1; + player.direction = PLAYER_LEFT; } - if(keys[PLAYER_RIGHT]){ + else if(keys[PLAYER_RIGHT]){ moveRightPlayer(); player.isMoving = 1; + player.direction = PLAYER_RIGHT; } - player.isMoving = 0; + else player.isMoving = 0; } int selectStateHover(){ @@ -146,4 +165,10 @@ void pourWater(int x, int y){ } } +void fillWater(int x, int y){ + if(player.currentWater<player.waterMax && selectStateHover() == 1){ + player.currentWater = player.currentWater + 1; + } +} + diff --git a/travail_de_groupe/chef_oeuvre/src/player.h b/travail_de_groupe/chef_oeuvre/src/player.h index a8bcffb7d67bb15d6dfa6feaa4b19ef23b0a90f1..387cf001c1dcde003a376e123739a23e158ebbbe 100644 --- a/travail_de_groupe/chef_oeuvre/src/player.h +++ b/travail_de_groupe/chef_oeuvre/src/player.h @@ -18,6 +18,7 @@ typedef struct player{ int waterMax; int speed; int isMoving; + int direction; } player_t; extern player_t player; @@ -26,5 +27,7 @@ void initPlayer(); void manageMovement(); int selectStateHover(); void pourWater(int, int); +void fillWater(int, int); +int giveCaseBelowPosition(int, int); #endif \ No newline at end of file diff --git a/travail_de_groupe/chef_oeuvre/src/render.c b/travail_de_groupe/chef_oeuvre/src/render.c index 6963c387011b4ab9569146a1369da5f84f35faf8..38d69edff20b7fb066c87a8b111058b799d5d507 100644 --- a/travail_de_groupe/chef_oeuvre/src/render.c +++ b/travail_de_groupe/chef_oeuvre/src/render.c @@ -1,5 +1,8 @@ #include "render.h" +int score = 100; +float timer = 0; + SDL_Window *window; SDL_Renderer *renderer; @@ -23,6 +26,9 @@ SDL_Texture * noHoverTexture; SDL_Surface * playerSurface; SDL_Texture * playerTexture; +SDL_Surface * playerIdleSurface; +SDL_Texture * playerIdleTexture; + SDL_Surface * backgroundSurface; SDL_Texture * backgroundTexture; @@ -47,6 +53,9 @@ SDL_Texture * emptyBucketTexture; SDL_Surface * filledBucketSurface; SDL_Texture * filledBucketTexture; +SDL_Surface * scoreSurface; +SDL_Texture * scoreTexture; + void createWindow(){ if (SDL_Init(SDL_INIT_VIDEO) != 0){ @@ -149,8 +158,14 @@ void drawPlayer(){ rect.w = CELLSIZE; rect.x = player.x + (screenDimension.w - (MAPSIZE * CELLSIZE)) / 2; rect.y = player.y ; - SDL_Rect destRect = {32 * (SDL_GetTicks()/200%4), 0, 32, 32}; - SDL_RenderCopyEx(renderer, playerTexture, &destRect, &rect, 0, NULL, SDL_FLIP_NONE); + SDL_Rect destRect = {32 * (SDL_GetTicks()/200%6), 0, 32, 32}; + int flip = (player.direction == PLAYER_LEFT) ? (SDL_FLIP_HORIZONTAL) : (SDL_FLIP_NONE); + if (player.isMoving){ + SDL_RenderCopyEx(renderer, playerTexture, &destRect, &rect, 0, NULL, flip); + } + else { + SDL_RenderCopyEx(renderer, playerIdleTexture, &destRect, &rect, 0, NULL, flip); + } } void drawBackgroundSides(){ @@ -159,18 +174,49 @@ void drawBackgroundSides(){ } void drawFire(){ + int loop; + int step; listchainfire_t cour = fireList; SDL_Rect rect; + rect.h = CELLSIZE; + rect.w = CELLSIZE; SDL_Rect srcRect; - srcRect.w = 24; - srcRect.h =32; - srcRect.x = srcRect.w * (SDL_GetTicks()/200 % 8); - srcRect.y= 0; while (cour != NULL){ - rect.h = CELLSIZE; - rect.w = CELLSIZE; rect.x = (cour->fire).x * CELLSIZE + (screenDimension.w - (MAPSIZE * CELLSIZE)) / 2; - rect.y = (cour->fire).y * CELLSIZE; + rect.y = (cour->fire).y * CELLSIZE - rect.h/2; + + switch ((cour->fire).state) + { + case SPARKLE: + step = 0; + loop = 2; + break; + + case MEDIUM: + step = 2 * srcRect.w; + loop = 4; + break; + + case STRONG: + step = 6 * srcRect.w; + loop = 6; + break; + + case SPREAD: + step = 6 * srcRect.w; + loop = 6; + break; + + default: + break; + } + + srcRect.w = 15; + srcRect.h = 24; + srcRect.x = step + srcRect.w * (SDL_GetTicks()/200 % loop); + srcRect.y= 0; + + SDL_RenderCopy(renderer, fireTexture, &srcRect, &rect); cour = cour->next; } @@ -184,7 +230,7 @@ void drawPlayerWaterLevel(){ int count = player.currentWater; for (int i=0; i<player.waterMax; i++){ rect.x = (i*rect.h); - rect.y = screenDimension.h/3; + rect.y = screenDimension.h - 1.5 * rect.h; if (count){ count--; SDL_RenderCopy(renderer, filledBucketTexture, NULL, &rect); @@ -195,6 +241,22 @@ void drawPlayerWaterLevel(){ } } +void drawScore(){ + SDL_Rect rect; + rect.h = screenDimension.h/6; + rect.w = (screenDimension.w - (MAPSIZE * CELLSIZE)) / 2; + rect.x = 0; + rect.y = 0; + SDL_RenderCopy(renderer, scoreTexture, NULL, &rect); + rect.y += rect.h; + char str[10]; + sprintf(str, "%d", score); + SDL_Color textColor = {237,222,17}; + SDL_Surface * surface = TTF_RenderText_Solid(robotoFont, str, textColor); + SDL_Texture * texture = SDL_CreateTextureFromSurface(renderer, surface); + SDL_RenderCopy(renderer, texture, NULL, &rect); +} + void drawGame(){ SDL_RenderClear(renderer); drawBackgroundSides(); @@ -202,6 +264,7 @@ void drawGame(){ drawPlayer(); drawFire(); drawPlayerWaterLevel(); + drawScore(); SDL_RenderPresent(renderer); } @@ -221,9 +284,12 @@ void mainLoop(){ noHoverSurface = IMG_Load("Res/noHover.png"); noHoverTexture = SDL_CreateTextureFromSurface(renderer, noHoverSurface); - playerSurface = IMG_Load("Res/character_spritesheet.png"); + playerSurface = IMG_Load("Res/character_tileset.png"); playerTexture = SDL_CreateTextureFromSurface(renderer, playerSurface); + playerIdleSurface = IMG_Load("Res/character_idle_spritesheet.png"); + playerIdleTexture = SDL_CreateTextureFromSurface(renderer, playerIdleSurface); + backgroundSurface = IMG_Load("Res/background_mat.png"); backgroundTexture = SDL_CreateTextureFromSurface(renderer, backgroundSurface); @@ -236,7 +302,7 @@ void mainLoop(){ playButtonHoverSurface = IMG_Load("Res/play_button_hover.png"); playButtonHoverTexture = SDL_CreateTextureFromSurface(renderer, playButtonHoverSurface); - fireSurface = IMG_Load("Res/fire.png"); + fireSurface = IMG_Load("Res/fire_spritesheet.png"); fireTexture = SDL_CreateTextureFromSurface(renderer, fireSurface); waterSurface = IMG_Load("Res/water.png"); @@ -247,6 +313,9 @@ void mainLoop(){ filledBucketSurface = IMG_Load("Res/filled_bucket.png"); filledBucketTexture = SDL_CreateTextureFromSurface(renderer, filledBucketSurface); + + scoreSurface = IMG_Load("Res/score.png"); + scoreTexture = SDL_CreateTextureFromSurface(renderer, scoreSurface); SDL_FreeSurface(grassSurface); SDL_FreeSurface(treeSurface); @@ -259,6 +328,10 @@ void mainLoop(){ SDL_FreeSurface(noHoverSurface); SDL_FreeSurface(fireSurface); SDL_FreeSurface(waterSurface); + SDL_FreeSurface(emptyBucketSurface); + SDL_FreeSurface(filledBucketSurface); + SDL_FreeSurface(scoreSurface); + unsigned int a = SDL_GetTicks(); unsigned int b = SDL_GetTicks(); @@ -272,21 +345,29 @@ void mainLoop(){ while (running){ a = SDL_GetTicks(); - delta = (a - b) / 1000.0; - if (delta > 1/FPS_TO_GET){ + delta = (a - b); + if (delta > 1000/FPS_TO_GET){ + timer += delta; + printf("timer : %f\n", timer/1000); b = a; + printf("fps : %f", 1000/delta); switch (gameState){ case MENU: drawMenu(); break; case GAME: + if ((int)timer % 20 == 0){ + nextFire(fireList); + fireList=spreadFire(fireList); + printf("after spread fire : x%d,y%d\n",(fireList->fire).x,(fireList->fire).y); + } drawGame(); break; } } else { // fait dormir le thread pour garder des ressources - usleep(1000 * (1/FPS_TO_GET - delta)); + usleep(1000 * (1000/FPS_TO_GET - delta)); } } diff --git a/travail_individuel/Beret/sprites/Makefile b/travail_individuel/Beret/sprites/Makefile new file mode 100644 index 0000000000000000000000000000000000000000..0826868a1a4e3c39362aac62d470f3b85032fab8 --- /dev/null +++ b/travail_individuel/Beret/sprites/Makefile @@ -0,0 +1,23 @@ +CC=gcc + +LDFLAG=$(shell sdl2-config --cflags --libs) -lm -lSDL2_ttf -D_REENTRANT -lSDL2_image -pthread +CFLAG=-Wall $(shell sdl2-config --cflags --libs) + +EXEC=run +SRC=$(wildcard src/*.c) +OBJ=$(SRC:.c=.o) + +all:$(EXEC) + +$(EXEC):$(OBJ) + $(CC) -o $@ $^ $(LDFLAG) + mv $^ bin/ + +%.o:%.c + $(CC) -o $@ -c $< $(CFLAG) + +.PHONY:clean + +clean: + rm -rf bin/*.o + rm -rf $(EXEC) \ No newline at end of file diff --git a/travail_individuel/Beret/sprites/assets/DarkForest_Background.png b/travail_individuel/Beret/sprites/assets/DarkForest_Background.png new file mode 100644 index 0000000000000000000000000000000000000000..1dd152fdf364c090c3e24f6441c41477db2402c5 Binary files /dev/null and b/travail_individuel/Beret/sprites/assets/DarkForest_Background.png differ diff --git a/travail_individuel/Beret/sprites/assets/DarkForest_Foreground.png b/travail_individuel/Beret/sprites/assets/DarkForest_Foreground.png new file mode 100644 index 0000000000000000000000000000000000000000..d686226d15399f30a298e8bbbe25440162b06c9b Binary files /dev/null and b/travail_individuel/Beret/sprites/assets/DarkForest_Foreground.png differ diff --git a/travail_individuel/Beret/sprites/assets/DarkForest_Middleground.png b/travail_individuel/Beret/sprites/assets/DarkForest_Middleground.png new file mode 100644 index 0000000000000000000000000000000000000000..204c16d94ac5be4d8b582c19c08a0afa618835a5 Binary files /dev/null and b/travail_individuel/Beret/sprites/assets/DarkForest_Middleground.png differ diff --git a/travail_individuel/Beret/sprites/assets/Sprite-0001.png b/travail_individuel/Beret/sprites/assets/Sprite-0001.png new file mode 100644 index 0000000000000000000000000000000000000000..9a2233715f5db5820961f78e14f70aaca5b29514 Binary files /dev/null and b/travail_individuel/Beret/sprites/assets/Sprite-0001.png differ diff --git a/travail_individuel/Beret/sprites/src/main.c b/travail_individuel/Beret/sprites/src/main.c new file mode 100644 index 0000000000000000000000000000000000000000..9b1cc7c030b8214d74c9e488e6b1d2c56b2fc111 --- /dev/null +++ b/travail_individuel/Beret/sprites/src/main.c @@ -0,0 +1,7 @@ +#include "render.h" + +int main (){ + + affichage(); + return 0; +} \ No newline at end of file diff --git a/travail_individuel/Beret/sprites/src/render.c b/travail_individuel/Beret/sprites/src/render.c new file mode 100644 index 0000000000000000000000000000000000000000..ebb04f6e2762ea36ac4bfe00c19e70edcd9f3020 --- /dev/null +++ b/travail_individuel/Beret/sprites/src/render.c @@ -0,0 +1,119 @@ +#include "render.h" + +SDL_Window *window; +SDL_Renderer *renderer; + +SDL_Surface *oursSurface=NULL; +SDL_Texture *oursTexture=NULL; + +SDL_Surface * fondSurface1=NULL; +SDL_Texture * fondTexture1=NULL; + +SDL_Surface * fondSurface2=NULL; +SDL_Texture * fondTexture2=NULL; + +SDL_Surface * fondSurface3=NULL; +SDL_Texture * fondTexture3=NULL; + +void creation_fen(){ + + if (SDL_Init(SDL_INIT_VIDEO) != 0) { + SDL_Log("Error : SDL initialisation - %s\n", + SDL_GetError()); // l'initialisation de la SDL a échoué + exit(EXIT_FAILURE);} + + window = SDL_CreateWindow("Running Bear", + SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 640, 180,SDL_WINDOW_OPENGL); + + + if (window == NULL) { + SDL_Log("Error : SDL window 1 creation - %s\n", + SDL_GetError()); // échec de la création de la fenêtre + SDL_Quit(); // On referme la SDL + exit(EXIT_FAILURE); + } + + renderer = SDL_CreateRenderer(window, -1, + SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC); + if (renderer == NULL) {SDL_DestroyRenderer(renderer); // Attention : on suppose que les NULL sont maintenus !! + renderer = NULL; + + SDL_DestroyWindow(window); + window = NULL;}; + +} + +void dessin_fond(int temps,int w , int h){ + SDL_Rect rect2 = {0, 0, w,h}; + SDL_Rect destRect2 = {temps%320, 0,w, h}; + SDL_RenderCopyEx(renderer,fondTexture1, &destRect2, &rect2, 0, NULL, SDL_FLIP_NONE); + SDL_Rect rect3 = {0, 0, w,h}; + SDL_Rect destRect3 = {temps%320, 0,w, h}; + SDL_RenderCopyEx(renderer,fondTexture2, &destRect3, &rect3, 0, NULL, SDL_FLIP_NONE); + SDL_Rect rect4 = {0, 0, w,h}; + SDL_Rect destRect4 = {temps%320, 0,w, h}; + SDL_RenderCopyEx(renderer,fondTexture3, &destRect4, &rect4, 0, NULL, SDL_FLIP_NONE); +} + +void dessin_ours(int temps){ + SDL_Rect rect = {(-64+10*temps)%(640-64), 52, 128,128}; + SDL_Rect destRect = {128 * (SDL_GetTicks()/200%8), 0,128, 128}; + SDL_RenderCopyEx(renderer,oursTexture, &destRect, &rect, 0, NULL, SDL_FLIP_NONE); +} + + +void dessin (int temps,int w,int h) { + SDL_RenderClear(renderer); + dessin_fond(temps,w,h); + dessin_ours(temps); + SDL_RenderPresent(renderer); + SDL_Delay(100); +} + +void affichage () { + int i=0; + int w=320; + int h=180; + int running =1; + creation_fen(); + + oursSurface= IMG_Load("assets/Sprite-0001.png"); + oursTexture = SDL_CreateTextureFromSurface(renderer, oursSurface); + + fondSurface1=IMG_Load("assets/DarkForest_Background.png"); + fondTexture1 = SDL_CreateTextureFromSurface(renderer, fondSurface1); + + fondSurface2=IMG_Load("assets/DarkForest_Middleground.png"); + fondTexture2 = SDL_CreateTextureFromSurface(renderer, fondSurface2); + + fondSurface3=IMG_Load("assets/DarkForest_Foreground.png"); + fondTexture3 = SDL_CreateTextureFromSurface(renderer, fondSurface3); + + SDL_QueryTexture(fondTexture1,NULL,NULL,&w,&h); + printf("w:%d,h:%d\n",w,h); + + SDL_FreeSurface(oursSurface); + + while (running) { + SDL_Event event; + while (SDL_PollEvent(&event)){ + switch(event.type) + { + case SDL_QUIT: + running = 0; + break; + default: + continue; + } + } + dessin(i,w,h); + i++; + + } + SDL_DestroyRenderer(renderer); // Attention : on suppose que les NULL sont maintenus !! + renderer = NULL; + SDL_DestroyWindow(window); + window=NULL; + SDL_Quit(); + +} diff --git a/travail_individuel/Beret/sprites/src/render.h b/travail_individuel/Beret/sprites/src/render.h new file mode 100644 index 0000000000000000000000000000000000000000..400e21152027fb08d7f52efddd0ee48e73af4456 --- /dev/null +++ b/travail_individuel/Beret/sprites/src/render.h @@ -0,0 +1,16 @@ +#ifndef _RENDER_H_ +#define _RENDER_H_ + +#include <stdio.h> +#include <stdlib.h> + +#include <SDL2/SDL.h> +#include <SDL2/SDL_image.h> +#include <SDL2/SDL_ttf.h> + +void creation_fen(); +void dessin_fond(); +void dessin_ours(); +void dessin (); +void affichage (); +#endif \ No newline at end of file