Skip to content
Snippets Groups Projects
Commit 165be733 authored by aitouali1u's avatar aitouali1u
Browse files

Jeu de Course

parent d3e5b7dd
No related branches found
No related tags found
Loading
V5/IMG/barrage.bmp

89.5 KiB

V5/IMG/barrage.png

12.6 KiB

V5/IMG/boutton.bmp

58.7 KiB

V5/IMG/boutton.png

2.53 KiB

V5/IMG/bullet.bmp

330 B

V5/IMG/enemy_car.bmp

17.7 KiB

V5/IMG/enemy_car.png

2.92 KiB

V5/IMG/exit.bmp

58.7 KiB

V5/IMG/finish_line.bmp

1.88 MiB

V5/IMG/finish_line.png

2.46 KiB

V5/IMG/main_car.bmp

17.7 KiB

V5/IMG/menu.bmp

2.08 MiB

V5/IMG/new_game.bmp

58.7 KiB

V5/IMG/road.bmp

2.08 MiB

V5/IMG/settings.bmp

58.7 KiB

V5/IMG/voiture.png

4.02 KiB

CC = gcc
CFLAGS = -W -Wall -ansi -std=c99 -g
LIBS = -L./SDL2_ttf/.libs -L./SDL2_image/.libs
LDFLAGS = `sdl2-config --cflags --libs` -lSDL2_ttf -lSDL2_image -lSDL2_ttf
INCLUDES = -I./SDL2_ttf -I./SDL2_image
EXEC = main
SRC = main.c fonctions_SDL.c data.c logic.c colision.c events.c graphics.c liste.c
OBJ = $(SRC:.c=.o) -lm
all: $(EXEC)
main: $(OBJ)
$(CC) $(CFLAGS) $(INCLUDES) -o $@ $^ $(LIBS) $(LDFLAGS)
%.o: %.c
$(CC) $(CFLAGS) -o $@ -c $<
clean:
rm -rf *.o *~
mrproper: clean
rm -rf $(EXEC)
/**
* \file collision.c
* \brief Gestion des collisions du jeu
* \author YATIME Marouane - AIT OUALI Marouane
* \date 3 janvier 2022 */
#include "colision.h"
#include "liste.h"
#include <stdio.h>
void handle_Main_Barrage_collision(sprite_t *sp1, sprite_t *sp2, world_t *world, resources_t *textures,
SDL_Renderer *renderer) {
if (sprites_collide(sp1, sp2)) {
sp1->direction = 2;
tout_deplacer(world, renderer, textures);
sp1->direction = 0;
sp1->speed = 0;
}
}
void handle_Main_Enemy_collision(world_t *world, sprite_t *sp1, sprite_t *sp2) {
if (sprites_collide(sp1, sp2)) {
int push = 200 + (rand() % (100 * world->Main_car.speed));
if (world->Main_car.life > 0) {
world->Main_car.life--;
if (world->Main_car.life <= 0 && world->dead == 0) {
world->dead = 1;
world->time_mort = time(NULL);
}
if (sp1->position.x <= sp2->position.x) {
if (sp1->position.y <= sp2->position.y) {
sp2->position.x += push;
sp2->position.y += push;
} else {
sp2->position.x += push;
sp2->position.y -= push;
}
} else {
if (sp1->position.y <= sp2->position.y) {
sp2->position.x -= push;
sp2->position.y += push;
} else {
sp2->position.x += push;
sp2->position.y -= push;
}
}
}
}
}
void handle_Bullet_Enemy_collision(world_t *world, sprite_t *sp1, sprite_t *sp2) {
if (sprites_collide(sp1, sp2)) {
int recul = 100 + (rand() % 100);
if (sp1->position.x <= sp2->position.x) {
if (sp1->position.y <= sp2->position.y) {
sp2->position.x += recul;
} else {
sp2->position.x += recul;
}
} else {
if (sp1->position.y <= sp2->position.y) {
sp2->position.x -= recul;
} else {
sp2->position.x += recul;
}
}
if (sp2->life > 0) {
sp2->life--;
int temp = 0;
temp = sp2->h;
sp2->h = sp2->w;
sp2->w = temp;
sp2->direction = sp1->direction;
if (sp1->direction != 1) {
sp2->position.x -= sp2->w;
}
}
sp2->count = 0;
sp1->position.x = 100000;
sp1->position.y = 100000;
}
}
/**
* \file collision.h
* \brief Gestion des collisions du jeu
* \author YATIME Marouane - AIT OUALI Marouane
* \date 3 janvier 2022 */
#ifndef V1_COLISION_H
#define V1_COLISION_H
#include "data.h"
#include "logic.h"
void handle_Main_Enemy_collision(world_t *world, sprite_t *sp1, sprite_t *sp2);
void handle_Bullet_Enemy_collision(world_t *world, sprite_t *sp1, sprite_t *sp2);
void handle_Main_Barrage_collision(sprite_t *sp1, sprite_t *sp2, world_t *world, resources_t *textures,
SDL_Renderer *renderer);
#endif //V1_COLISION_H
/**
* \file const.h
* \brief Rassemblement des constantes utiles au jeu
* \author YATIME Marouane - AIT OUALI Marouane
* \date 3 janvier 2022 */
#include <SDL2/SDL.h>
#include <SDL2/SDL_ttf.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <time.h>
#include <math.h>
#include <string.h>
#include "fonctions_SDL.h"
#ifndef V1_CONSTANTS_H
#define V1_CONSTANTS_H
#define SCREEN_WIDTH 840
#define SCREEN_HEIGHT 650
#define CAR_STEP 50
#define SPEED_LIIMIT 10
#define NUMBER_ENEMY_CAR 0
#define NUMBER_LIFES 10
#define NUMBER_BARRAGE 50
#define NUMBER_ROADS 100
struct resources_s {
SDL_Texture *main_car;
SDL_Texture *enemy_car;
SDL_Texture *barrage;
SDL_Texture *road;
SDL_Texture *bullet;
SDL_Texture *menu;
SDL_Texture *exit_button;
SDL_Texture *new_game_button;
SDL_Texture *settings_button;
SDL_Texture *finish_line;
TTF_Font *font;
};
typedef struct resources_s resources_t;
#endif
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment