Commit 3edca7d9 authored by Yassine BAHOU's avatar Yassine BAHOU
Browse files

Upload New File

parent b50dbf12
#include <math.h>
#include <stdio.h>
#include <SDL2/SDL.h>
#include <SDL2/SDL_ttf.h>
#include <string.h>
#include <SDL2/SDL_image.h>
#include <stdbool.h>
#include "image.h"
#include "matrice.h"
#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)
{
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "[DEBUG] > %s", SDL_GetError());
return EXIT_FAILURE;
}
SDL_Texture * texture1 = NULL;
SDL_Texture * texture3 = NULL;
SDL_Texture * texture2 = NULL;
SDL_Texture * texture4 = NULL;
SDL_Texture * texture5 = NULL;
SDL_Texture * texture6 = NULL;
SDL_Texture * texture7 = NULL;
SDL_Texture * texture8 = NULL;
SDL_Window * pWindow;
SDL_Renderer * pRenderer;
pWindow = SDL_CreateWindow("rendu",SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 20*48, 20*48, SDL_WINDOW_SHOWN);
if (pWindow == NULL)
{
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "[DEBUG] > %s", SDL_GetError());
SDL_Quit();
return EXIT_FAILURE;
}
pRenderer = SDL_CreateRenderer(pWindow, -1, SDL_RENDERER_ACCELERATED);
if (pRenderer == NULL)
{
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "[DEBUG] > %s", SDL_GetError());
SDL_Quit();
return EXIT_FAILURE;
}
texture3=load_texture_from_image("Punk_climb.png",pWindow,pRenderer);
texture1=load_texture_from_image("Punk_run.png",pWindow, pRenderer); /* creation de la texture qui contient l'image */
texture2=load_texture_from_image("Punk_attack3.png",pWindow, pRenderer);
texture4=load_texture_from_image("Punk_run_back.png",pWindow, pRenderer);
texture5=load_texture_from_image("Punk_attack3_back.png",pWindow, pRenderer);
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);
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** matrice =cree(20,20);
fill_matrix(matrice,20,20);
int k = 0;
for(k=1;k<=20;k++){
insert(matrice,k,k);
insert(matrice,k,1);
insert(matrice,1,k);
insert(matrice,k,20);
insert(matrice,20,k);
insert(matrice,21-k,k);
}
int code = 1;
afficher_perso(texture2,texture6,texture7,pWindow,pRenderer,i,j,matrice);
while(lancer_prog)
{
SDL_Event event;
while(SDL_PollEvent(&event) && lancer_prog)
{
switch(event.type)
{
case SDL_QUIT :
lancer_prog = SDL_FALSE;
break;
case SDL_KEYDOWN :
code = 1;
switch (event.key.keysym.sym)
{
case SDLK_LEFT:
if (matrice[i-1][j]==0){
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){
animation_run(texture1,texture6,texture7,pWindow,pRenderer,i,j,matrice);
i++;
}
// basculement pause/unpause
break;
case SDLK_UP:
if (matrice[i][j-1]==0){
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){
animation_climb(texture3,texture6,texture7,pWindow,pRenderer,i,j,matrice,BAS);
j++;
} // 'p' // 'SPC'
// basculement pause/unpause
break;
case SDLK_f:
animation_attack(texture2,texture6,texture7,pWindow,pRenderer,i,j,matrice);
if (matrice[i+1][j]==1){
matrice[i+1][j]=0;
}
break;
case SDLK_s:
animation_attack_gauche(texture5,texture6,texture7,pWindow,pRenderer,i,j,matrice);
if (matrice[i-1][j]==1){
matrice[i-1][j]=0;
}
break;
case SDLK_e:
animation_attack(texture8,texture6,texture7,pWindow,pRenderer,i,j,matrice);
if (matrice[i][j-1]==1){
matrice[i][j-1]=0;
}
break;
case SDLK_d:
animation_attack(texture8,texture6,texture7,pWindow,pRenderer,i,j,matrice);
if (matrice[i][j+1]==1){
matrice[i][j+1]=0;
}
break;
case SDLK_ESCAPE:
case SDLK_q :
lancer_prog = SDL_FALSE;
break;
default :
break;
}
break;
default :
code =0;
break;
}
if (code==1){
afficher_perso(texture2,texture6,texture7,pWindow,pRenderer,i,j,matrice);
}
}
}
SDL_DestroyRenderer(pRenderer);
SDL_DestroyWindow(pWindow);
SDL_Quit();
return EXIT_SUCCESS;
}
\ No newline at end of file
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