Skip to content
Snippets Groups Projects
Commit 3d3494c4 authored by belkhiritaha's avatar belkhiritaha
Browse files

Merge branch 'main' into fire

parents cb6cfa97 19e0df97
No related branches found
No related tags found
No related merge requests found
travail_de_groupe/chef_oeuvre/Res/background_sides.png

87.6 KiB | W: | H:

travail_de_groupe/chef_oeuvre/Res/background_sides.png

2.98 KiB | W: | H:

travail_de_groupe/chef_oeuvre/Res/background_sides.png
travail_de_groupe/chef_oeuvre/Res/background_sides.png
travail_de_groupe/chef_oeuvre/Res/background_sides.png
travail_de_groupe/chef_oeuvre/Res/background_sides.png
  • 2-up
  • Swipe
  • Onion skin
travail_de_groupe/chef_oeuvre/Res/empty_bucket.png

287 B

travail_de_groupe/chef_oeuvre/Res/filled_bucket.png

318 B

travail_de_groupe/chef_oeuvre/Res/water.png

193 B

No preview for this file type
......@@ -15,6 +15,6 @@
0 0 0 0 0 1 0 0 0 0 0 0 0 1 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1
\ No newline at end of file
2 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
2 2 2 2 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0
2 2 2 2 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1
\ No newline at end of file
......@@ -123,10 +123,14 @@ void manageGame(){
break;
case SDL_MOUSEMOTION:
mousePosition.x = (event.motion.x - (screenDimension.w - (MAPSIZE * CELLSIZE)) / 2) / CELLSIZE;
mousePosition.y = (event.motion.y - 0) / CELLSIZE;
mousePosition.x = (event.motion.x - (screenDimension.w - (MAPSIZE * CELLSIZE)) / 2) / CELLSIZE;
mousePosition.y = (event.motion.y - 0) / CELLSIZE;
continue;
case SDL_MOUSEBUTTONDOWN:
pourWater(mousePosition.x, mousePosition.y);
break;
default:
continue;
}
......
......@@ -4,11 +4,12 @@ player_t player;
void initPlayer(){
player.x = 18*32;
player.y = 0;
player.x = (MAPSIZE/2)*CELLSIZE;
player.y = (MAPSIZE/2)*CELLSIZE;
player.w = CELLSIZE*0.8;
player.h = CELLSIZE*0.8;
player.waterLevel = 0;
player.waterMax = 3;
player.currentWater = player.waterMax;
player.speed = 1;
player.isMoving = 0;
}
......@@ -134,5 +135,15 @@ int selectStateHover(){
}
void pourWater(int x, int y){
int onFire = searchFire(fireList, x, y);
if(player.currentWater>0){
//downgrade the cliqued fire
if(onFire == 1 && selectStateHover() == 1){
fireList = deleteFire (fireList, x, y);
}
player.currentWater = player.currentWater - 1;
}
}
......@@ -14,7 +14,8 @@ typedef struct player{
int y;
int w;
int h;
int waterLevel;
int currentWater;
int waterMax;
int speed;
int isMoving;
} player_t;
......@@ -24,5 +25,6 @@ extern player_t player;
void initPlayer();
void manageMovement();
int selectStateHover();
void pourWater(int, int);
#endif
\ No newline at end of file
......@@ -38,6 +38,15 @@ SDL_Texture * playButtonHoverTexture;
SDL_Surface * fireSurface;
SDL_Texture * fireTexture;
SDL_Surface * waterSurface;
SDL_Texture * waterTexture;
SDL_Surface * emptyBucketSurface;
SDL_Texture * emptyBucketTexture;
SDL_Surface * filledBucketSurface;
SDL_Texture * filledBucketTexture;
void createWindow(){
if (SDL_Init(SDL_INIT_VIDEO) != 0){
......@@ -111,8 +120,13 @@ void drawMap(){
for(i = 0; i < MAPSIZE; i++){
for(j = 0; j < MAPSIZE; j++){
SDL_RenderCopy(renderer, grassTexture, NULL, &rect);
if(map[i][j] == 1){
SDL_RenderCopy(renderer, treeTexture, NULL, &rect);
switch (map[i][j]){
case 1:
SDL_RenderCopy(renderer, treeTexture, NULL, &rect);
break;
case 2:
SDL_RenderCopy(renderer, waterTexture, NULL, &rect);
break;
}
if (mousePosition.x == j && mousePosition.y == i){
if (selectStateHover()){
......@@ -162,12 +176,32 @@ void drawFire(){
}
}
void drawPlayerWaterLevel(){
int borderWidth = (screenDimension.w - (MAPSIZE * CELLSIZE)) / 2;
SDL_Rect rect;
rect.h = borderWidth/player.waterMax;
rect.w = borderWidth/player.waterMax;
int count = player.currentWater;
for (int i=0; i<player.waterMax; i++){
rect.x = (i*rect.h);
rect.y = screenDimension.h/3;
if (count){
count--;
SDL_RenderCopy(renderer, filledBucketTexture, NULL, &rect);
}
else {
SDL_RenderCopy(renderer, emptyBucketTexture, NULL, &rect);
}
}
}
void drawGame(){
SDL_RenderClear(renderer);
drawBackgroundSides();
drawMap();
drawPlayer();
drawFire();
drawPlayerWaterLevel();
SDL_RenderPresent(renderer);
}
......@@ -205,6 +239,15 @@ void mainLoop(){
fireSurface = IMG_Load("Res/fire.png");
fireTexture = SDL_CreateTextureFromSurface(renderer, fireSurface);
waterSurface = IMG_Load("Res/water.png");
waterTexture = SDL_CreateTextureFromSurface(renderer, waterSurface);
emptyBucketSurface = IMG_Load("Res/empty_bucket.png");
emptyBucketTexture = SDL_CreateTextureFromSurface(renderer, emptyBucketSurface);
filledBucketSurface = IMG_Load("Res/filled_bucket.png");
filledBucketTexture = SDL_CreateTextureFromSurface(renderer, filledBucketSurface);
SDL_FreeSurface(grassSurface);
SDL_FreeSurface(treeSurface);
SDL_FreeSurface(hoverSurface);
......@@ -215,6 +258,7 @@ void mainLoop(){
SDL_FreeSurface(backgroundSidesSurface);
SDL_FreeSurface(noHoverSurface);
SDL_FreeSurface(fireSurface);
SDL_FreeSurface(waterSurface);
unsigned int a = SDL_GetTicks();
unsigned int b = SDL_GetTicks();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment