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

Merge branch 'render' of github.com:maberet/ProjetZZ1 into player

parents a5d1724d e6390d32
No related branches found
No related tags found
No related merge requests found
......@@ -13,6 +13,7 @@
#define STRONG 3
#define SPREAD 4
#define UPDATETIME 5
typedef struct fire{
......
......@@ -241,6 +241,25 @@ void drawPlayerWaterLevel(){
}
}
void drawPlayerHP(){
int borderWidth = (screenDimension.w - (MAPSIZE * CELLSIZE))/2;
SDL_Rect rect;
rect.h = borderWidth/player.HPMax;
rect.w = rect.h;
int count = player.currentHP;
for (int i=0; i<player.HPMax; i++){
rect.x = (i*rect.h);
rect.y = screenDimension.h - 3 * rect.h;
if (count){
count--;
SDL_RenderCopy(renderer, filledBucketTexture, NULL, &rect);
}
else {
SDL_RenderCopy(renderer, emptyBucketTexture, NULL, &rect);
}
}
}
void drawScore(){
SDL_Rect rect;
rect.h = screenDimension.h/6;
......@@ -257,6 +276,22 @@ void drawScore(){
SDL_RenderCopy(renderer, texture, NULL, &rect);
}
void drawTime(){
SDL_Rect rect;
rect.h = screenDimension.h/6;
rect.w = (screenDimension.w - (MAPSIZE * CELLSIZE)) / 2;
rect.x = rect.w + (MAPSIZE * CELLSIZE);
rect.y = 0;
SDL_RenderCopy(renderer, scoreTexture, NULL, &rect);
rect.y += rect.h;
char str[10];
sprintf(str, "%d", UPDATETIME - (int)timer/1000 % UPDATETIME);
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();
......@@ -264,7 +299,9 @@ void drawGame(){
drawPlayer();
drawFire();
drawPlayerWaterLevel();
drawPlayerHP();
drawScore();
drawTime();
SDL_RenderPresent(renderer);
}
......@@ -356,7 +393,7 @@ void mainLoop(){
drawMenu();
break;
case GAME:
if ((int)timer % 20 == 0){
if ((int)timer/1000 % UPDATETIME == 0){
nextFire(fireList);
}
drawGame();
......
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
travail_individuel/Beret/sprites/assets/DarkForest_Background.png

3.71 KiB

travail_individuel/Beret/sprites/assets/DarkForest_Foreground.png

7.44 KiB

travail_individuel/Beret/sprites/assets/DarkForest_Middleground.png

5.01 KiB

travail_individuel/Beret/sprites/assets/Sprite-0001.png

2.48 KiB

#include "render.h"
int main (){
affichage();
return 0;
}
\ No newline at end of file
#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();
}
#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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment