Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file not shown.
Binary file added animebg/1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added animebg/10.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added animebg/11.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added animebg/12.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added animebg/13.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added animebg/14.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added animebg/15.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added animebg/16.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added animebg/17.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added animebg/18.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added animebg/19.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added animebg/2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added animebg/20.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added animebg/21.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added animebg/22.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added animebg/23.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added animebg/24.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added animebg/3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added animebg/4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added animebg/5.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added animebg/6.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added animebg/7.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added animebg/8.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added animebg/9.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
281 changes: 281 additions & 0 deletions bg.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,281 @@
#include </usr/include/SDL/SDL.h>
#include "bg.h"
#include "text.h"
#include </usr/include/SDL/SDL_image.h>
#include </usr/include/SDL/SDL_ttf.h>
#include <string.h>

Mix_Music* initsound (char ch[])
{
return Mix_LoadMUS (ch);
}

void initialiser_imageBIRDS(image *imge)
{
imge->img=IMG_Load("music.png");
if (imge->img == NULL) {
printf("unable to load background image %s\n", Mix_GetError());
return;}
imge->pos_img_ecran.x=10;
imge->pos_img_ecran.y=100;
imge->pos_img_affiche.x=0;
imge->pos_img_affiche.y=0;
imge->pos_img_affiche.h=164;
imge->pos_img_affiche.w=161;
}
void afficher_imageBIRDS(SDL_Surface *screen, image imge)
{
SDL_BlitSurface(imge.img,NULL,screen, &imge.pos_img_ecran);
}
void initBack(background *b,char ch[])
{
b->img = IMG_Load(ch);
if ( b->img == NULL)
{
return;
}
b->pos1.x=0;
b->pos1.y=0;
b->pos2.x=0;
b->pos2.y=0;
b->pos2.w=(1920);
b->pos2.h=(1080);

}
void initobs1(background *obs1,char ch[])
{
obs1->img = IMG_Load(ch);
if ( obs1->img == NULL)
{
return;
}
obs1->pos1.x=10;
obs1->pos1.y=730;
obs1->pos2.x=0;
obs1->pos2.y=0;
obs1->pos2.w=(1920);
obs1->pos2.h=(1080);


}
void initAnime ( background BG[] , char ch[] , char ext[] , int n , int x , int y , int w , int h)
{
int i;
char chi[4], chemin [100];
for (i=0;i<n;i++)
{
strcpy(chemin ,"");
strcpy (chi,"");
sprintf (chi,"%d",i+1);
printf("\n%s",chi);
strcpy(chemin,ch);
strcat (chemin , chi);
strcat(chemin, ext);
printf("\n%s",chemin);
BG[i].img=IMG_Load (chemin);
if (BG[i].img == NULL)
printf ("\nerror %s",SDL_GetError());
else
{
BG[i].pos1.x=0;
BG[i].pos1.y=0;
BG[i].pos2.x=0;
BG[i].pos2.y=0;
BG[i].pos2.w=w;
BG[i].pos2.h=h;

}
}
}
void initAnime2 ( background BG[] , char ch[] , char ext[], int n,int x,int y)
{
int i;
char chi[4], chemin [100];
for (i=0;i<n;i++)
{
strcpy(chemin ,"");
strcpy (chi,"");
sprintf (chi,"%d",i+1);
printf("\n%s",chi);
strcpy(chemin,ch);
strcat (chemin , chi);
strcat(chemin, ext);
printf("\n%s",chemin);
BG[i].img=IMG_Load (chemin);
if (BG[i].img == NULL)
printf ("\nerror %s",SDL_GetError());
else
{
BG[i].pos1.x=x;
BG[i].pos1.y=y;
BG[i].pos2.x=0;
BG[i].pos2.y=0;
BG[i].pos2.w=(197);
BG[i].pos2.h=(61);

}
}
}
void playAnime (background T[], SDL_Surface *screen , int n,int *i)
{
if ((*i)<=n-2)
(*i)++;
else
(*i)=0;
if (SDL_BlitSurface(T[*i].img , &T[*i].pos2 , screen , &T[*i].pos1)==-1)
printf("\n%s",SDL_GetError());


}

void scrolling (background * b, int direction )
{
if (direction==1)
{
if(b->pos2.x>7080)
{
b->pos2.x=0;
}
else
b->pos2.x=b->pos2.x+6;

}

}
void scrollinganime (background T[], int direction )
{
int i;
if (direction==1)
{
for (i=0;i<24;i++)
{
if((T[i].pos2.x>7080))
{
T[i].pos2.x=0;
}
else
{
T[i].pos2.x=T[i].pos2.x+6;
}

}
}
}
void caranim (background T[], int direction )
{
int i;
if (direction==3)
{
for (i=0;i<12;i++)
{
if ((T[i].pos1.y >=550))
{
T[i].pos1.y=T[i].pos1.y-5;
}
}
}
else if (direction==4)
{
for (i=0;i<12;i++)
{
if ((T[i].pos1.y < 950))
{
T[i].pos1.y=T[i].pos1.y+5;

}
}
}
}

SDL_Color GetPixel(SDL_Surface *p , int x , int y)
{
SDL_Color color;
Uint32 col=0;

char * Pos = (char*)p->pixels;
Pos += (p->pitch * y);
Pos += (p->format->BytesPerPixel * x);
memcpy (&col ,Pos, p->format->BytesPerPixel );

SDL_GetRGB(col , p->format,&color.r , &color.g,&color.b );
return color;

}

void tab(car *C)
{

C->T[0].x=C->b[0].pos1.x;
C->T[0].y=C->b[0].pos1.y;
C->T[0].c=0;

C->T[1].x=C->b[0].pos1.x+C->b[0].pos2.w/2;
C->T[1].y=C->b[0].pos1.y;
C->T[1].c=0;

C->T[2].x=C->b[0].pos1.x + C->b[0].pos2.w;
C->T[2].y=C->b[0].pos1.y;
C->T[2].c=0;

C->T[3].x=C->b[0].pos1.x+C->b[0].pos2.w;
C->T[3].y=C->b[0].pos1.y + C->b[0].pos2.h /2;
C->T[3].c=0;

C->T[4].x=C->b[0].pos1.x+C->b[0].pos2.w;
C->T[4].y=C->b[0].pos1.y+C->b[0].pos2.h;
C->T[4].c=0;

C->T[5].x=C->b[0].pos1.x + C->b[0].pos2.w/2;
C->T[5].y=C->b[0].pos1.y+ C->b[0].pos2.h ;
C->T[5].c=0;

C->T[6].x=C->b[0].pos1.x;
C->T[6].y=C->b[0].pos1.y+C->b[0].pos2.h;
C->T[6].c=0;

C->T[7].x=C->b[0].pos1.x;
C->T[7].y=C->b[0].pos1.y+C->b[0].pos2.h/2;
C->T[7].c=0;


}

void collision (car *C , background B , int *done)
{
SDL_Color color ,color2;
int i=0;
color.r=0;
color.g=0;
color.b=0;
tab(C);
while (i<8)
{
color2=GetPixel(B.img , C->T[i].x +B.pos2.x , C->T[i].y+B.pos2.y);
if ((color.r==color2.r)&&(color.g==color2.g)&&(color.b==color2.b) )
{
C->T[i].c = 1;
}
if ( ( i==3) && ((color.r==0)&&(color.g==0)&&(color.b==255) ) )
*done=1;
i++;
}
}


void afficher(background b,SDL_Surface *screen)
{
SDL_BlitSurface(b.img,&b.pos2,screen,&b.pos1);
}

void liberer( background b)
{
SDL_FreeSurface(b.img);
}
void freeAnime (background T[],int n)
{
int i;
for (i=0;i<n;i++)
SDL_FreeSurface(T[i].img);
}


75 changes: 75 additions & 0 deletions bg.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
#ifndef Bg_H
#define Bg_H
#include </usr/include/SDL/SDL_mixer.h>
#include </usr/include/SDL/SDL.h>
#include </usr/include/SDL/SDL_image.h>
#include </usr/include/SDL/SDL_ttf.h>
#define SCREEN_W 1920
#define SCREEN_H 720
#include "text.h"
typedef struct
{
char url;
SDL_Rect pos_img_affiche;
SDL_Rect pos_img_ecran;
SDL_Surface *img;
}image;
typedef struct
{
SDL_Rect pos1;
SDL_Rect pos2;
SDL_Surface *img;
}background;

Mix_Music* initsound ();

typedef struct
{
int score;
int temps;
char playername[20];
}scoreinfo;

typedef struct
{
int x;
int y;
int c;
}point;

typedef struct
{
point T[8];
background b[13];
}car;


void initobs1(background *obs1,char ch[]);

void initBack( background *b,char ch[]);


SDL_Color GetPixel(SDL_Surface *p , int x , int y);
void collision (car *C , background B , int *done);
void tab(car *C);


void initialiser_imageBIRDS(image *imge);
void afficher_imageBIRDS(SDL_Surface *screen, image imge);



void scrolling (background * b, int direction );
void afficher(background b,SDL_Surface *screen);
void initAnime ( background BG[] , char ch[] , char ext[] , int n , int x , int y , int w , int h);
void initAnime2 ( background BG[] , char ch[] , char ext[], int n,int x,int y);
void savescore(scoreinfo xs,char *ch);
void bestscore(char *ch,scoreinfo ts[],Text t2,SDL_Surface *screen);
void caranim (background T[], int direction );
void scrollinganime (background T[], int direction );
void playAnime (background T[], SDL_Surface *screen , int n,int *i);


void liberer( background b);
void freeAnime (background T[],int n);
#endif
Binary file added bg.o
Binary file not shown.
Binary file removed bgm1.mp3
Binary file not shown.
Binary file added car animation/1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added car animation/10.png
Binary file added car animation/11.png
Binary file added car animation/12.png
Binary file added car animation/2.png
Binary file added car animation/3.png
Binary file added car animation/4.png
Binary file added car animation/5.png
Binary file added car animation/6.png
Binary file added car animation/7.png
Binary file added car animation/8.png
Binary file added car animation/9.png
Loading