Skip to content
Snippets Groups Projects
Commit 907625cc authored by LAHLOU Ghalia's avatar LAHLOU Ghalia
Browse files

Last Commit

parents 6fb64e51 f89ee0ec
No related branches found
No related tags found
No related merge requests found
......@@ -2,6 +2,7 @@
#include <stdlib.h>
#include <stdbool.h>
#include "fonctions_fichiers.h"
#include "joueur.h"
#include <SDL2/SDL.h>
......@@ -202,5 +203,4 @@ void affichage ( SDL_Renderer* ecran ,SDL_Texture* sprite,SDL_Texture* etoile, S
}
}
}
......@@ -6,7 +6,7 @@
#include <stdio.h>
#include <stdlib.h>
#include "joueur.h"
#include "joueur.h"
char ** allouer_tab_2D(int n , int m);
......@@ -25,4 +25,5 @@ void affichage_etoile(SDL_Renderer* ecran ,SDL_Texture* etoile, int l, int h, in
void affichage ( SDL_Renderer* ecran ,SDL_Texture* sprite,SDL_Texture* etoile, SDL_Texture* personnage , game_t * game , int lpers , int hpers ,int largeur , int hauteur , int l , int h);
void affichage_pers(SDL_Renderer* ecran ,SDL_Texture* sprite, game_t * game,int largeur , int hauteur, int x , int y );
#endif
......@@ -3,6 +3,7 @@
#include <stdbool.h>
#include <SDL2/SDL.h>
#include "sdl2-ttf-light.h"
#include "joueur.h"
......@@ -16,6 +17,8 @@ int score(game_t * game){
}
void handle_event(SDL_Event * evenements, game_t *game , char ** tab ){
void handle_event(SDL_Event * evenements, game_t *game , char ** tab,SDL_Renderer* ecran ,SDL_Texture* personnage,int lpers , int hpers ){
>>>>>>> aad6ed212a0b181b6369881ce3891b5bb843e44f
game->gameover = false;
SDL_PollEvent( evenements );
......@@ -45,6 +48,22 @@ game->gameover = true;
break;
case SDLK_RIGHT:
//collision_brick_dt(game,tab);
game->joueur->x += 1;
break;
case SDLK_UP:
//collision_brick_haut(game,tab);
game->joueur->y-=1;
break;
case SDLK_RIGHT:
//collision_brick_dt(game,tab);
game->joueur->x += 1;
......@@ -55,6 +74,7 @@ game->gameover = true;
//collision_brick_gch(game,tab);
game->joueur->x -= 1;
break;
case SDLK_q:
game->gameover = true;
......@@ -74,17 +94,62 @@ game->gameover = true;
void collision_fenetre(joueur_t * joueur){
if(joueur->x <= 0){
joueur->x +=1;
}else if(joueur->x >= 659){
}else if(joueur->x >= 659 ){
joueur->x -= 1;
}
if(joueur->y <= 0){
joueur->y +=1;
}else if(joueur->y >= 359){
}else if(joueur->y >= 359 ){
joueur->y -= 1;
}
}
void collision_sprite(joueur_t * joueur){
if(joueur->x <= 0){
joueur->x +=1;
}else if(joueur->x >= 64 ){
joueur->x -= 1;
}
if(joueur->y <= 0){
joueur->y +=1;
}else if(joueur->y >= 32 ){
joueur->y -= 1;
}
}
void collision_brick_haut(game_t* game,char** map){
//if(game->joueur->y > 0){
printf("x = %d\n",game->joueur->x );
printf("y = %d\n",game->joueur->y);
if(map[4][5]=='5'){
game->joueur->y+=0;
if(map[game->joueur->x][game->joueur->y-1]=='5'){
game->joueur->y +=0;
}
}
}
void collision_brick_bas(game_t* game,char** map){
if(map[game->joueur->x][game->joueur->y+1]=='5'){
game->joueur->y +=0;
}
}
void collision_brick_gch(game_t* game,char** map){
// if(game->joueur->x >0){
if(map[game->joueur->x-1][game->joueur->y]=='5'){
game->joueur->x +=0;
}
}
<<<<<<< HEAD
/*
pos de joueur est en pixel 32 pour largeur et 32 pou Hauteur
pour cela on arrive pas a detecter la pos exact sur la map
......@@ -128,4 +193,5 @@ void print_temps(SDL_Renderer *ecran, game_t *game,textures_t* textures){
sprintf(game->tmp,"TEMPS : %d S", (game->temps - game->temps_init));
apply_text(ecran,0,0,100,50,game->tmp,textures->font);//on applique le temps en haut à gauche
}
......@@ -40,6 +40,7 @@ void jump( joueur_t * joueur);
void handle_event(SDL_Event* evenements, game_t* game , char ** tab);
void joueur_print(SDL_Event* evenements, game_t* game);
void collision_fenetre(joueur_t * joueur);
void collision_sprite(joueur_t * joueur);
void collision_sprites();
void collision_brick_haut(game_t* game,char** map);
void collision_brick_dt(game_t* game,char** map);
......
......@@ -3,15 +3,20 @@
#include <stdbool.h>
#include "SDL2/SDL.h"
#include "sdl2-ttf-light.h"
#include "fonctions_fichiers.h"
#include "joueur.h"
#include "Fonction_SDL.h"
#include "sdl2-ttf-light.h"
int main ( int argc , char* args[] ){
#define SCREEN_WIDTH 700
#define SCREEN_HEIGHT 400
int main ( int argc , char* args[] ){
textures_t* textures= malloc(sizeof(textures_t));
int nbCol=0,nbLing=0;
char** map=lire_fichier("mape.txt");
taille_fichier( "mape.txt" , &nbLing , &nbCol);
......@@ -38,7 +43,7 @@ int main ( int argc , char* args[] ){
// Mettre en place un contexte de rendu de l’écran
SDL_Renderer* ecran;
textures_t *textures =malloc(sizeof(textures_t));
// textures_t *textures =malloc(sizeof(textures_t));
ecran = SDL_CreateRenderer(fenetre, -1, SDL_RENDERER_ACCELERATED);
// Charger l’image
SDL_Texture* fond = charger_image( "layer.bmp", ecran );
......@@ -62,14 +67,18 @@ int main ( int argc , char* args[] ){
SDL_QueryTexture(etoile, &f, &a , &l ,&h);//recuperation d info sur l image
//joueur_t * player;
game_t* game= malloc(sizeof(game_t));
game->joueur=malloc(sizeof(joueur_t));
game->joueur->x=0;
game->joueur->y=hpers*8;
TTF_Init();
// Boucle principale
while( ! is_game_over(game)){
......@@ -86,6 +95,7 @@ int main ( int argc , char* args[] ){
}
TTF_Quit();
// Libérer de la mémoire
SDL_DestroyTexture(fond);
SDL_DestroyRenderer(ecran);
......
personnage1.bmp

80.1 KiB

0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment