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