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

Barre de progression non fini

parent 7c545ff5
No related branches found
No related tags found
No related merge requests found
Showing
with 2241 additions and 30 deletions
CFLAGS = -O3 -Dmain=SDL_main
LDFLAGS = -lm -lmingw32 -lSDL2main -lSDL2 -lSDL2_ttf
LDFLAGS = -lm -lmingw32 -lSDL2main -lSDL2 -lSDL2_ttf -lSDL2_image
SDL2_INCLUDE_DIR = src/include
SDL2_LIBRARIES_DIR = src/lib
......
File added
......@@ -4,13 +4,17 @@
#include <math.h>
void init_ressource(SDL_Renderer *renderer, ressources_t *textures){
textures->background = load_image( "ressources/Elements/background2.bmp",renderer);
textures->background = load_image( "ressources/Elements/backgrounds/1.png",renderer);
textures->background2 = load_image( "ressources/Elements/backgrounds/3.png",renderer);
textures->background3 = load_image( "ressources/Elements/backgrounds/2.png",renderer);
textures->ship = load_image( "ressources/spaceship.bmp",renderer);
textures->finishLine = load_image( "ressources/finish_line.bmp",renderer);
textures->font = load_font("ressources/font/arial.ttf", 14);
textures->color = (SDL_Color){255, 255, 255, 255};
textures->BarreProgression = load_image( "ressources/Elements/BarreProgression.png",renderer);
textures->vaisseauMini = load_image( "ressources/spaceship.bmp",renderer);
init_ressource_element(renderer, textures);
}
......@@ -19,10 +23,10 @@ void init_ressource_element(SDL_Renderer *renderer, ressources_t *textures){
textures->e_rotate = load_image("ressources/Elements/reverse.bmp", renderer);
}
void apply_background(SDL_Renderer *renderer, SDL_Texture *texture, world_t *world){
void apply_background(SDL_Renderer *renderer, SDL_Texture *texture, world_t *world, int parallax){
if(texture != NULL){
//printf("%f %f\n", (SCREEN_WIDTH/2+(0-SCREEN_WIDTH/2)*cos(angle)-(0-SCREEN_HEIGHT/2)*sin(angle)), (SCREEN_HEIGHT/2+(0-SCREEN_WIDTH/2)*sin(angle)+(0-SCREEN_HEIGHT/2)*cos(angle)));
apply_texture(texture, renderer, 0, 0, world->angle*180/M_PI);
apply_texture(texture, renderer, 0, -1800+world->parallax/parallax, world->angle*180/M_PI);
}
}
......@@ -73,7 +77,9 @@ void refresh_graphics(SDL_Renderer *renderer, world_t *world,ressources_t *textu
clear_renderer(renderer);
//application des textures dans le renderer
apply_background(renderer, textures->background, world);
apply_background(renderer, textures->background, world, 7);
apply_background(renderer, textures->background2, world, 3);
apply_background(renderer, textures->background3, world, 9);
if (!world->isMenu){
apply_sprite(renderer, textures->ship, world->vaisseau, world);
......@@ -87,8 +93,11 @@ void refresh_graphics(SDL_Renderer *renderer, world_t *world,ressources_t *textu
apply_text(renderer, 10, 10, 100, 33, world->str, textures->font, textures->color);
}else{
apply_text(renderer, 10, 10, 100, 33, "Menu", textures->font, textures->color);
printf("aaa");
}
apply_sprite(renderer, textures->BarreProgression, world->BarreProgression, world);
apply_sprite(renderer, textures->vaisseauMini, world->vaisseauMini, world);
update_screen(renderer);
}
......
......@@ -33,10 +33,14 @@
*/
struct ressources_s{
SDL_Texture* background; /*!< Texture liée à l'image du fond de l'écran. */
SDL_Texture* background2; /*!< Texture liée à l'image du fond de l'écran. (effet parallax) */
SDL_Texture* background3; /*!< Texture liée à l'image du fond de l'écran. (effet parallax) */
SDL_Texture* ship; /*!< Texture liée à l'image du vaisseau. */
SDL_Texture* meteorite; /*!< Texture liée à l'image du météorite. */
SDL_Texture* e_rotate; /*!< Texture liée à l'image de l'élément de rotation. */
SDL_Texture* finishLine; /*!< Texture liée à l'image de la ligne d'arrivée. */
SDL_Texture* BarreProgression; /*!< Texture liée à l'image de l'air. */
SDL_Texture* vaisseauMini; /*!< Texture liée à l'image du vaisseau. */
TTF_Font *font; // Font
SDL_Color color; // Color
long double angle; /*!< Angle de rotation de l'image. */
......@@ -65,7 +69,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);
void apply_background(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
......
No preview for this file type
#include "world.h"
#include "../utility/utility.h"
void init_data(world_t * world){
//on n'est pas à la fin du jeu
world->gameover = 0;
world->speed_h = (float)INITIAL_SPEED;
// Initialisation du vaisseau
world->vaisseau = init_sprite(world->vaisseau, SCREEN_WIDTH/2 - SHIP_SIZE/2, SCREEN_HEIGHT - SHIP_SIZE-15, SHIP_SIZE, SHIP_SIZE, '0');
init_walls(world);
world->ligneArriver = init_sprite(world->ligneArriver, 0, -world->nb_lines_murs*METEORITE_SIZE-30 , SCREEN_WIDTH, FINISH_LINE_HEIGHT, 'z');
world->BarreProgression = init_sprite(world->BarreProgression, 10, SCREEN_HEIGHT - 500, 50, 400, 'y');
world->vaisseauMini = init_sprite(world->vaisseauMini, 10, SCREEN_HEIGHT - 130, 20, 20, 'x');
print_sprite(world->vaisseau);
world->startTimer = SDL_GetTicks();
world->timer = SDL_GetTicks();
world->str = malloc(sizeof(char)*100);
world->angle = 0.0;
world->isFlipping = 0;
world->isMenu = false;
world->parallax = 0;
}
void update_data(world_t *world){
if (!world->isMenu){
world->ligneArriver->y += (int)world->speed_h;
world->vaisseauMini->y = 16028 + world->ligneArriver->y + SCREEN_HEIGHT -100;
printf("%d\n", world->ligneArriver->y);
world->parallax += (int)world->speed_h;
update_walls(world);
if (isOverScreen(world->vaisseau)){
if (world->vaisseau->x < 0) world->vaisseau->x = 0;
......@@ -28,25 +52,6 @@ int is_game_over(world_t *world){
}
void init_data(world_t * world){
//on n'est pas à la fin du jeu
world->gameover = 0;
world->speed_h = (float)INITIAL_SPEED;
// Initialisation du vaisseau
world->vaisseau = init_sprite(world->vaisseau, SCREEN_WIDTH/2 - SHIP_SIZE/2, SCREEN_HEIGHT - SHIP_SIZE, SHIP_SIZE, SHIP_SIZE, '0');
init_walls(world);
world->ligneArriver = init_sprite(world->ligneArriver, 0, -world->nb_lines_murs*METEORITE_SIZE-30 , SCREEN_WIDTH, FINISH_LINE_HEIGHT, 'z');
print_sprite(world->vaisseau);
world->startTimer = SDL_GetTicks();
world->timer = SDL_GetTicks();
world->str = malloc(sizeof(char)*100);
world->angle = 0.0;
world->isFlipping = 0;
world->isMenu = true;
}
void clean_data(world_t *world){
/* utile uniquement si vous avez fait de l'allocation dynamique (malloc); la fonction ici doit permettre de libérer la mémoire (free) */
free(world->vaisseau);
......
......@@ -37,6 +37,8 @@ struct world_s{
sprite_t *vaisseau ; /*!< Représentation du vaisseau */
sprite_t **murs; /*<Représentation des météorites>*/
sprite_t **murs2; /*<Représentation des météorites et de l'air>*/
sprite_t *BarreProgression;
sprite_t *vaisseauMini;
int nb_murs; // Nombre de météorites
int nb_lines_murs; // Nombre de lignes de météorites
sprite_t *ligneArriver;
......@@ -48,6 +50,8 @@ struct world_s{
double angle; // Angle de rotation de la map
int isFlipping; // Indique si l'on est en train de faire une rotation de l'écran et dans quelle sens (0 : non droite, 1 : vers la droite, -1 : vers la gauche, -2 : non gauche)
bool isMenu;
int parallax;
};
typedef struct world_s world_t;
......
No preview for this file type
No preview for this file type
ressources/Elements/BarreProgression.png

8.04 KiB

ressources/Elements/backgrounds/1.png

912 KiB

ressources/Elements/backgrounds/2.png

523 KiB

ressources/Elements/backgrounds/3.png

66.4 KiB

ressources/Elements/backgrounds/4.png

52.5 KiB

ressources/Elements/backgrounds/5.png

464 KiB

......@@ -9,7 +9,7 @@
#include "sdl2-light.h"
#include <stdio.h>
#include <stdlib.h>
#include <SDL2/SDL_image.h>
int init_sdl(SDL_Window **window, SDL_Renderer **renderer, int width, int height)
......@@ -37,8 +37,11 @@ SDL_Texture *load_image(const char path[], SDL_Renderer *renderer)
tmp = SDL_LoadBMP(path);
if(NULL == tmp)
{
fprintf(stderr, "Erreur pendant chargement image BMP: %s", SDL_GetError());
return NULL;
tmp = IMG_Load(path);
if (NULL == tmp){
fprintf(stderr, "Erreur pendant chargement image BMP: %s", SDL_GetError());
return NULL;
}
}
SDL_SetColorKey(tmp, SDL_TRUE, SDL_MapRGB(tmp->format, 255, 0, 255));
texture = SDL_CreateTextureFromSurface(renderer, tmp);
......
No preview for this file type
No preview for this file type
This diff is collapsed.
# sdl2_image cmake project-config-version input for ./configure scripts
set(PACKAGE_VERSION "@MAJOR_VERSION_MACRO@.@MINOR_VERSION_MACRO@.@MICRO_VERSION_MACRO@")
if(PACKAGE_VERSION VERSION_LESS PACKAGE_FIND_VERSION)
set(PACKAGE_VERSION_COMPATIBLE FALSE)
else()
set(PACKAGE_VERSION_COMPATIBLE TRUE)
if(PACKAGE_FIND_VERSION STREQUAL PACKAGE_VERSION)
set(PACKAGE_VERSION_EXACT TRUE)
endif()
endif()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment