Skip to content
Snippets Groups Projects
Commit ea839c0c authored by SmallIshMink's avatar SmallIshMink
Browse files

Mise a jour de l'heure en fonction du début réel du jeu

parent d1658249
No related branches found
No related tags found
No related merge requests found
......@@ -32,9 +32,16 @@ void init_ressource_element(SDL_Renderer *renderer, ressources_t *textures){
textures->nb_init += 3;
}
void apply_background_parralax(SDL_Renderer *renderer, SDL_Texture *texture, world_t *world, int parallax){
if(texture != NULL){
apply_texture(texture, renderer, 0, (int)(-1800+(world->parallax/parallax)), world->angle*180/M_PI);
}
}
void apply_background(SDL_Renderer *renderer, SDL_Texture *texture, world_t *world, int parallax){
if(texture != NULL){
apply_texture(texture, renderer, 0, -1800+world->parallax/parallax, world->angle*180/M_PI);
apply_texture(texture, renderer, 0, 0, world->angle*180/M_PI);
}
}
......@@ -96,44 +103,44 @@ void apply_walls(SDL_Renderer * renderer, SDL_Texture *texture, world_t *world,
void refresh_graphics(SDL_Renderer *renderer, world_t *world,ressources_t *textures){
//on vide le renderer
clear_renderer(renderer);
//application des textures dans le renderer
apply_background(renderer, textures->background, world, 7);
apply_background(renderer, textures->background2, world, 3);
apply_background(renderer, textures->background3, world, 9);
if (world->isMenu == 0){
ingame(renderer,world,textures);
}else if(world -> isMenu==1){
inmenu(renderer,world,textures);
}
update_screen(renderer);
}
void inmenu(SDL_Renderer *renderer, world_t *world,ressources_t *textures){
apply_background(renderer, textures->bmenu, world);
apply_background(renderer, textures->bmenu, world, 0);
}
void ingame(SDL_Renderer *renderer, world_t *world,ressources_t *textures){
if (world->ismenu == 0){
apply_background(renderer, textures->background, world);//application des textures dans le renderer
apply_sprite(renderer, textures->ship, world->vaisseau, world);
apply_sprite(renderer, textures->finishLine, world->ligneArriver, world);
apply_walls(renderer, textures->meteorite, world, textures);
apply_sprite(renderer, textures->soleil, world->soleil, world);
apply_text(renderer, 10, 10, 100, 33, world->str, textures->font, textures->color);
apply_text(renderer, SCREEN_WIDTH-(60+10*number_of_numbers(world->money)), 10, 15*number_of_numbers(world->money), 30, world->coins_str, textures->font, textures->color);
apply_sprite_fixed(renderer, textures->BarreProgression, world->BarreProgression, world);
apply_sprite_fixed(renderer, textures->vaisseauMini, world->vaisseauMini, world);
apply_sprite_fixed(renderer, textures->soleilBarre, world->soleilBarre, world);
apply_sprite_fixed(renderer, textures->coins, world->coins, world);
}else{
apply_text(renderer, 10, 10, 100, 33, "Menu", textures->font, textures->color);
printf("aaa");
}
//application des textures dans le renderer
// Backgrounds
apply_background_parralax(renderer, textures->background, world, 7);
apply_background_parralax(renderer, textures->background2, world, 3);
apply_background_parralax(renderer, textures->background3, world, 9);
apply_sprite(renderer, textures->ship, world->vaisseau, world);
apply_sprite(renderer, textures->finishLine, world->ligneArriver, world);
apply_walls(renderer, textures->meteorite, world, textures);
apply_sprite(renderer, textures->soleil, world->soleil, world);
apply_text(renderer, 10, 10, 100, 33, world->temps_str, textures->font, textures->color); // Temps de jeu
apply_text(renderer, SCREEN_WIDTH-(60+10*number_of_numbers(world->money)), 10, 15*number_of_numbers(world->money), 30, world->coins_str, textures->font, textures->color);
// HUD
apply_sprite_fixed(renderer, textures->BarreProgression, world->BarreProgression, world);
apply_sprite_fixed(renderer, textures->vaisseauMini, world->vaisseauMini, world);
apply_sprite_fixed(renderer, textures->soleilBarre, world->soleilBarre, world);
apply_sprite_fixed(renderer, textures->coins, world->coins, world);
// Update de l'écran
update_screen(renderer);
}
void clean(SDL_Window *window, SDL_Renderer * renderer, ressources_t *textures, world_t * world){
......
......@@ -78,7 +78,7 @@ void init_ressource_element(SDL_Renderer *renderer, ressources_t *textures);
* \param renderer le renderer
* \param texture la texture liée au fond
*/
void apply_background(SDL_Renderer *renderer, SDL_Texture *texture, world_t *world, int parallax);
void apply_background_parralax(SDL_Renderer *renderer, SDL_Texture *texture, world_t *world, int parallax);
/**
* \brief La fonction qui applique la texture \a texture sur le renderer \a renderer en fonction des données du sprite \a sprite (avec rotation)
......
......@@ -4,36 +4,40 @@
void update_data(world_t *world){
if (world->isMenu==0){
world->ligneArriver->y += (int)world->speed_h;
world->soleil->y += (int)world->speed_h;
world->vaisseauMini->dy -= world->speed_h/(MAX_LINES*METEORITE_REAL_SIZE+700)*400;
world->vaisseauMini->y = (int)world->vaisseauMini->dy;
outBorder(world);
world->parallax += (int)world->speed_h;
update_walls(world);
if (isOverScreen(world->vaisseau)){
if (world->vaisseau->x < 0) world->vaisseau->x = 0;
if (world->vaisseau->x + world->vaisseau->w > SCREEN_WIDTH) world->vaisseau->x = SCREEN_WIDTH - world->vaisseau->w;
if (world->vaisseau->y < 0) world->vaisseau->y = 0;
if (world->vaisseau->y + world->vaisseau->h > SCREEN_HEIGHT) world->vaisseau->y = SCREEN_HEIGHT - world->vaisseau->h;
world->money2 = world->money;
if (!world->invicibility){
for(int i = 0; i < world->nb_murs; i++){
collide(world->vaisseau, world->murs[i], world);
}
}
for(int i = 0; i < world->nb_murs; i++){
collide(world->vaisseau, world->murs[i], world, 0);
collide(world->vaisseau, world->ligneArriver, world);
if (timer_update_s(world) != 0){
world->temps_str[0] = '\0';
world->temps_str = strcats(world->temps_str, 3, "temps: ",int_to_str((int)world->timer/1000), "s");
}
collide(world->vaisseau, world->ligneArriver, world, 1);
allEvents(world);
world->timer = SDL_GetTicks();
world->timer = SDL_GetTicks() - world->startTimer;;
}else if(world->isMenu == 1){
world->startTimer = SDL_GetTicks();
}
}
int is_game_over(world_t *world){
return world->gameover;
}
void init_data(world_t * world){
//on n'est pas à la fin du jeu
world->gameover = 0;
world->speed_h = (float)INITIAL_SPEED;
init_walls(world);
world->ligneArriver = init_sprite(world->ligneArriver, 0, -world->nb_lines_murs*METEORITE_SIZE-30 , SCREEN_WIDTH, FINISH_LINE_HEIGHT, 'z');
world->ligneArriver = init_sprite(world->ligneArriver, 0, -world->nb_lines_murs*METEORITE_SIZE-30 , SCREEN_WIDTH, FINISH_LINE_HEIGHT, 'z', 0);
InitMenu(world);
print_sprite(world->vaisseau);
// Initialisation du vaisseau
......@@ -48,9 +52,8 @@ void init_data(world_t * world){
world->vaisseauMini->y = SCREEN_HEIGHT - (110);
world->vaisseauMini->dy = SCREEN_HEIGHT - (110);
world->startTimer = SDL_GetTicks();
world->timer = SDL_GetTicks();
world->str = malloc(sizeof(char)*100); // Allocation de la mémoire pour le string temps
world->temps_str = malloc(sizeof(char)*100); // Allocation de la mémoire pour le string temps
world->coins_str = malloc(sizeof(char)*100); // Allocation de la mémoire pour le string coins
......@@ -63,48 +66,19 @@ void init_data(world_t * world){
world->mouseX = 0;
world->mouseY = 0;
world->isMenu = false;
world->money = 0;
world->parallax = 0;
world->invicibility = false;
}
void update_data(world_t *world){
if (!world->isMenu){
world->ligneArriver->y += (int)world->speed_h;
world->soleil->y += (int)world->speed_h;
world->vaisseauMini->dy -= world->speed_h/(MAX_LINES*METEORITE_REAL_SIZE+700)*400;
world->vaisseauMini->y = (int)world->vaisseauMini->dy;
outBorder(world);
world->parallax += (int)world->speed_h;
update_walls(world);
world->money2 = world->money;
if (!world->invicibility){
for(int i = 0; i < world->nb_murs; i++){
collide(world->vaisseau, world->murs[i], world);
}
}
if (timer_update_s(world) != 0){
world->str[0] = '\0';
world->str = strcats(world->str, 3, "temps: ",int_to_str((int)world->timer/1000), "s");
}
collide(world->vaisseau, world->ligneArriver, world); // Collision avec la ligne d'arriver
allEvents(world);
world->timer = SDL_GetTicks();
}
}
void outBorder(world_t *world){
if (isOverScreen(world->vaisseau)){
if (world->vaisseau->x < 0) world->vaisseau->x = 0;
if (world->vaisseau->x + world->vaisseau->w > SCREEN_WIDTH) world->vaisseau->x = SCREEN_WIDTH - world->vaisseau->w;
if (world->vaisseau->y < 0) world->vaisseau->y = 0;
if (world->vaisseau->y + world->vaisseau->h > SCREEN_HEIGHT) world->vaisseau->y = SCREEN_HEIGHT - world->vaisseau->h;
if (world->vaisseau->x < 0) world->vaisseau->x = 0;
if (world->vaisseau->x + world->vaisseau->w > SCREEN_WIDTH) world->vaisseau->x = SCREEN_WIDTH - world->vaisseau->w;
if (world->vaisseau->y < 0) world->vaisseau->y = 0;
if (world->vaisseau->y + world->vaisseau->h > SCREEN_HEIGHT) world->vaisseau->y = SCREEN_HEIGHT - world->vaisseau->h;
}
}
......@@ -113,8 +87,8 @@ int is_game_over(world_t *world){
}
int timer_update_s(world_t *world){
if (world->timer%1000 <= 110|| world->timer%1000 >= 985){
return world->timer%1000;
if ((world->timer)%1000 <= 110|| (world->timer)%1000 >= 985){
return (world->timer)%1000;
}
return 0;
}
......@@ -216,7 +190,7 @@ void clean_data(world_t *world){
free(world->vaisseau);
free(world->ligneArriver);
free(world->murs);
free(world->str);
free(world->temps_str);
free(world->vaisseauMini);
free(world->soleilBarre);
free(world->soleil);
......@@ -224,6 +198,10 @@ void clean_data(world_t *world){
free(world->coins);
free(world->coins_str);
free(world->air);
free(world->play);
free(world->exit);
free(world->magasin);
free(world->sound);
printf("clean_data");
}
\ No newline at end of file
......@@ -57,7 +57,7 @@ struct world_s{
float speed_h; /*!< Vitesse de déplacement horizontal des éléments du jeu */
unsigned int startTimer; /*!< Timer de départ */
unsigned int timer; /*!< Timer de jeu */
char * str; // String affichant le temps sur le jeu
char * temps_str; // String affichant le temps sur le jeu
char * coins_str;
double angle; // Angle de rotation de la map
......@@ -66,7 +66,6 @@ struct world_s{
int mouseX;
int mouseY;
bool isMenu;
int money;
int money2;
......
No preview for this file type
......@@ -107,7 +107,7 @@ void init(SDL_Window **window, SDL_Renderer ** renderer, ressources_t *textures,
// Initialisation du ttf
init_ttf();
init_ressource(*renderer,textures);
}
......@@ -133,13 +133,13 @@ int main( int argc, char* args[] )
frameTime = SDL_GetTicks() - ticks;
//gestion des évènements
handle_events(&event,&world);
//mise à jour des données liée à la physique du monde
update_data(&world);
//rafraichissement de l'écran
refresh_graphics(renderer,&world,&textures);
if (frameTime < 16) {
SDL_Delay(16 - frameTime); // 16 ms = 60 fps
}
......
No preview for this file type
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment