Commit 3ff37cee authored by Wadie EL AMRANI's avatar Wadie EL AMRANI
Browse files

mise a jour

parent 62799ec4
......@@ -125,7 +125,8 @@ void animation_run(SDL_Texture* my_texture,SDL_Texture* mure,SDL_Texture* fond,
SDL_RenderCopy(renderer, my_texture, // Préparation de l'affichage
&source_image,
&destination);
SDL_RenderPresent(renderer);
SDL_RenderPresent(renderer);
SDL_Delay(100);
k++;
......@@ -164,13 +165,15 @@ void animation_run_back(SDL_Texture* my_texture,SDL_Texture* mure,SDL_Texture* f
//(window_dimensions.w - destination.w) /2 -300 +3*j; // La destination est au milieu de la largeur de la fenêtre
// (window_dimensions.h - destination.h) / 2+63; // La destination est au milieu de la hauteur de la fenêtre
// play_with_texture_1_1(texture_fond, window,renderer) ;
SDL_RenderCopy(renderer, my_texture, // Préparation de l'affichage
&source_image,
&destination);
SDL_SetRenderDrawColor(renderer,247,246,255,255);
SDL_RenderPresent(renderer);
play_with_texture_2(mure,fond, window,
renderer,matrice);
SDL_RenderPresent(renderer);
SDL_RenderCopy(renderer, my_texture, // Préparation de l'affichage
&source_image,
&destination);
SDL_RenderPresent(renderer);
SDL_Delay(100);
k=k+1;
}
......@@ -211,13 +214,16 @@ void animation_climb(SDL_Texture* my_texture,SDL_Texture* mure,SDL_Texture* fond
//(window_dimensions.w - destination.w) /2 -300 +3*j; // La destination est au milieu de la largeur de la fenêtre
// (window_dimensions.h - destination.h) / 2+63; // La destination est au milieu de la hauteur de la fenêtre
// play_with_texture_1_1(texture_fond, window,renderer) ;
play_with_texture_2(mure,fond, window,
renderer,matrice);
SDL_RenderPresent(renderer);
SDL_RenderCopy(renderer, my_texture, // Préparation de l'affichage
&source_image,
&destination);
SDL_SetRenderDrawColor(renderer,247,246,255,255);
SDL_RenderPresent(renderer);
play_with_texture_2(mure,fond, window,
renderer,matrice);
SDL_RenderPresent(renderer);
SDL_Delay(100);
k++;
}
......@@ -234,13 +240,15 @@ void animation_climb(SDL_Texture* my_texture,SDL_Texture* mure,SDL_Texture* fond
//(window_dimensions.w - destination.w) /2 -300 +3*j; // La destination est au milieu de la largeur de la fenêtre
// (window_dimensions.h - destination.h) / 2+63; // La destination est au milieu de la hauteur de la fenêtre
// play_with_texture_1_1(texture_fond, window,renderer) ;
play_with_texture_2(mure,fond, window,
renderer,matrice);
SDL_RenderPresent(renderer);
SDL_RenderCopy(renderer, my_texture, // Préparation de l'affichage
&source_image,
&destination);
SDL_SetRenderDrawColor(renderer,247,246,255,255);
SDL_RenderPresent(renderer);
play_with_texture_2(mure,fond, window,
renderer,matrice);
SDL_RenderPresent(renderer);
SDL_Delay(100);
k++;
}
......@@ -273,14 +281,17 @@ void animation_attack(SDL_Texture* my_texture,SDL_Texture* mure,SDL_Texture* fon
// la boucle par condition d'arret : la distance a parcourir
while(k<6)
{
source_image.x=k*source_image.w;;
source_image.x=k*source_image.w;
play_with_texture_2(mure,fond, window,
renderer,matrice);
SDL_RenderPresent(renderer);
SDL_RenderCopy(renderer, my_texture, // Préparation de l'affichage
&source_image,
&destination);
SDL_SetRenderDrawColor(renderer,247,246,255,255);
SDL_RenderPresent(renderer);
play_with_texture_2(mure,fond, window,
renderer,matrice);
SDL_RenderPresent(renderer);
SDL_Delay(100);
k++;
}
......@@ -310,14 +321,16 @@ void animation_attack_gauche(SDL_Texture* my_texture,SDL_Texture* mure,SDL_Textu
// la boucle par condition d'arret : la distance a parcourir
while(k<6)
{
source_image.x=(6-k)*source_image.w;;
source_image.x=(6-k)*source_image.w;
play_with_texture_2(mure,fond, window,
renderer,matrice);
SDL_RenderPresent(renderer);
SDL_RenderCopy(renderer, my_texture, // Préparation de l'affichage
&source_image,
&destination);
SDL_SetRenderDrawColor(renderer,247,246,255,255);
SDL_RenderPresent(renderer);
play_with_texture_2(mure,fond, window,
renderer,matrice);
SDL_RenderPresent(renderer);
SDL_Delay(100);
k++;
}
......
......@@ -13,7 +13,9 @@
#define BAS 1
#define HAUT 2
SDL_Texture* load_texture_from_image(char * file_image_name, SDL_Window *window, SDL_Renderer *renderer);
// void play_with_texture_1(SDL_Texture *my_texture, SDL_Window*window,SDL_Renderer *renderer);
void play_with_texture_1_1(SDL_Texture *my_texture, SDL_Window *window,
SDL_Renderer *renderer);
void animation_run(SDL_Texture* my_texture,SDL_Texture* mure,SDL_Texture* fond,
SDL_Window* window,
SDL_Renderer* renderer,int i,int j,int ** matrice);
......
......@@ -91,7 +91,7 @@ void play_with_texture_2(SDL_Texture *my_texture,SDL_Texture *texture_back, SDL_
destination.w = 48;
play_with_texture_1(texture_back,window,
play_with_texture_1_1(texture_back,window,
renderer);
SDL_RenderPresent(renderer);
int i,j;
......
#ifndef IMAGE
#define IMAGE
#include <math.h>
#include <stdio.h>
#include <SDL2/SDL.h>
#include <string.h>
#include <SDL2/SDL_image.h>
#include <stdbool.h>
#include "image.h"
#include "matrice.h"
#include "animationperso.h"
void end_sdl(char ok,char const* msg,SDL_Window* window,SDL_Renderer* renderer);
void play_with_texture_1(SDL_Texture *texture_back, SDL_Window *window,
SDL_Renderer *renderer);
void play_with_texture_2(SDL_Texture *my_texture,SDL_Texture *texture_back, SDL_Window*window,SDL_Renderer *renderer,int** );
#endif
......@@ -10,37 +10,7 @@
#include "animationperso.h"
//mure = 48*48
// void draw(SDL_Renderer* renderer) { // Je pense que vous allez faire moins laid :)
// SDL_Rect rectangle;
// SDL_SetRenderDrawColor(renderer,
// 50, 0, 0, // mode Red, Green, Blue (tous dans 0..255)
// 255); // 0 = transparent ; 255 = opaque
// rectangle.x = 0; // x haut gauche du rectangle
// rectangle.y = 0; // y haut gauche du rectangle
// rectangle.w = 400; // sa largeur (w = width)
// rectangle.h = 400; // sa hauteur (h = height)
// SDL_RenderFillRect(renderer, &rectangle);
// SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255);
// SDL_RenderDrawLine(renderer,
// 0, 0, // x,y du point de la première extrémité
// 400, 400); // x,y seconde extrémité
// /* tracer un cercle n'est en fait pas trivial, voilà le résultat sans algo intelligent ... */
// for (float angle = 0; angle < 2 * M_PI; angle += M_PI / 4000) {
// SDL_SetRenderDrawColor(renderer,
// (cos(angle * 2) + 1) * 255 / 2, // quantité de Rouge
// (cos(angle * 5) + 1) * 255 / 2, // de vert
// (cos(angle) + 1) * 255 / 2, // de bleu
// 255); // opaque
// SDL_RenderDrawPoint(renderer,
// 200 + 100 * cos(angle), // coordonnée en x
// 200 + 150 * sin(angle)); // en y
// }
// }
int main(int argc, char* argv[])
{
if(SDL_Init(SDL_INIT_VIDEO) < 0)
......@@ -55,7 +25,9 @@ int main(int argc, char* argv[])
SDL_Texture * texture5 = NULL;
SDL_Texture * texture6 = NULL;
SDL_Texture * texture7 = NULL;
SDL_Texture * texture8 = NULL;
SDL_Texture * texture8 = NULL;
SDL_Texture * texture9 = NULL;
SDL_Texture * texture10 = NULL;
SDL_Window * pWindow;
SDL_Renderer * pRenderer;
pWindow = SDL_CreateWindow("rendu",SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 20*48, 20*48, SDL_WINDOW_SHOWN);
......@@ -80,15 +52,16 @@ int main(int argc, char* argv[])
texture6=load_texture_from_image("mur.png",pWindow, pRenderer);
texture7=load_texture_from_image("Back.png",pWindow, pRenderer);
texture8=load_texture_from_image("atack_haut_bas.png",pWindow, pRenderer);
texture9=load_texture_from_image("game_over.jpg",pWindow, pRenderer);
texture10=load_texture_from_image("win.jpg",pWindow, pRenderer);
SDL_SetRenderDrawColor(pRenderer,247,246,255,255);
SDL_RenderClear(pRenderer);
SDL_bool lancer_prog = SDL_TRUE;
SDL_bool paused = SDL_FALSE;
int i =4,j=4;
int i =1,j=17;
int** matrice =cree(20,20);
fill_matrix(matrice,20,20);
int k = 0;
for(k=1;k<=20;k++){
for(int k=1;k<=20;k++){
insert(matrice,k,k);
insert(matrice,k,1);
insert(matrice,1,k);
......@@ -97,9 +70,12 @@ int main(int argc, char* argv[])
insert(matrice,21-k,k);
}
matrice[19][10]=0;
int marteau = 5;
int code = 1;
int fin = 0;
afficher_perso(texture2,texture6,texture7,pWindow,pRenderer,i,j,matrice);
while(lancer_prog)
{
......@@ -116,27 +92,36 @@ int main(int argc, char* argv[])
switch (event.key.keysym.sym)
{
case SDLK_LEFT:
if (matrice[i-1][j]==0){
if (!matrice[i-1][j]){
animation_run_back(texture4,texture6,texture7,pWindow,pRenderer,i,j,matrice);
i--;
} // 'p' // 'SPC' // basculement pause/unpause
break;
case SDLK_RIGHT: // 'p' // 'SPC'
if (matrice[i+1][j]==0){
if (!matrice[i+1][j]){
if(i==18 && j == 10){
animation_run(texture1,texture6,texture7,pWindow,pRenderer,i,j,matrice);
play_with_texture_1_1(texture10,pWindow,pRenderer);
SDL_Delay(2000);
lancer_prog = SDL_FALSE;
}
else{
animation_run(texture1,texture6,texture7,pWindow,pRenderer,i,j,matrice);
i++;
}
}
// basculement pause/unpause
break;
case SDLK_UP:
if (matrice[i][j-1]==0){
if (!matrice[i][j-1]){
animation_climb(texture3,texture6,texture7,pWindow,pRenderer,i,j,matrice,HAUT);
j--;
} // 'p' // 'SPC'
// basculement pause/unpause
break;
case SDLK_DOWN:
if (matrice[i][j+1]==0){
if (!matrice[i][j+1]){
animation_climb(texture3,texture6,texture7,pWindow,pRenderer,i,j,matrice,BAS);
j++;
} // 'p' // 'SPC'
......@@ -144,28 +129,32 @@ int main(int argc, char* argv[])
break;
case SDLK_f:
animation_attack(texture2,texture6,texture7,pWindow,pRenderer,i,j,matrice);
if (matrice[i+1][j]==1){
if (matrice[i+1][j] && (i+1)!=19){
matrice[i+1][j]=0;
marteau--;
}
break;
case SDLK_s:
animation_attack_gauche(texture5,texture6,texture7,pWindow,pRenderer,i,j,matrice);
if (matrice[i-1][j]==1){
if (matrice[i-1][j] && (i-1)!=0 ){
matrice[i-1][j]=0;
marteau--;
}
break;
case SDLK_e:
animation_attack(texture8,texture6,texture7,pWindow,pRenderer,i,j,matrice);
if (matrice[i][j-1]==1){
if (matrice[i][j-1] && (j-1)!=0){
matrice[i][j-1]=0;
marteau--;
}
break;
case SDLK_d:
animation_attack(texture8,texture6,texture7,pWindow,pRenderer,i,j,matrice);
if (matrice[i][j+1]==1){
if (matrice[i][j+1] && (j+1)!=19){
matrice[i][j+1]=0;
marteau--;
}
break;
......@@ -182,9 +171,14 @@ int main(int argc, char* argv[])
code =0;
break;
}
if (code==1){
afficher_perso(texture2,texture6,texture7,pWindow,pRenderer,i,j,matrice);
}
if (code){
afficher_perso(texture2,texture6,texture7,pWindow,pRenderer,i,j,matrice);
if(!marteau){
play_with_texture_1_1(texture9,pWindow,pRenderer);
SDL_Delay(2000);
lancer_prog = SDL_FALSE;
}
}
}
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment