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

Lecture Map via Fichier

parent be46ebf7
No related branches found
No related tags found
No related merge requests found
......@@ -6,7 +6,8 @@
"stdio.h": "c",
"sprites.h": "c",
"sdl2-ttf-light.h": "c",
"stdlib.h": "c"
"stdlib.h": "c",
"utility.h": "c"
},
"C_Cpp.errorSquiggles": "disabled"
}
\ No newline at end of file
......@@ -20,6 +20,9 @@ doc: $(PROG)
doxygen $(PROG)
.PHONY: clean
start:
$(PROG)
clean:
del /f /q *.o *~ $(PROG)
rd /s /q latex html
\ No newline at end of file
#include "world.h"
#include "../utility/utility.h"
void update_data(world_t *world){
world->ligneArriver->y += (int)world->speed_h;
......@@ -65,14 +65,21 @@ int handle_sprite_collide(sprite_t *sp1, sprite_t *sp2, world_t *world, int make
void init_walls(world_t *world){
world->nb_murs = 6;
world->murs = malloc(sizeof(sprite_t) * 10);
world->murs[0] = init_sprite(world->murs[0], 48, 0, 3*METEORITE_SIZE, 6*METEORITE_SIZE);
world->murs[1] = init_sprite(world->murs[1], 252, 0, 3*METEORITE_SIZE, 6*METEORITE_SIZE);
world->murs[2] = init_sprite(world->murs[2], 16, -352, 1*METEORITE_SIZE, 5*METEORITE_SIZE);
world->murs[3] = init_sprite(world->murs[3], 188, -352, 7*METEORITE_SIZE, 5*METEORITE_SIZE);
world->murs[4] = init_sprite(world->murs[4], 48, -672, 3*METEORITE_SIZE, 6*METEORITE_SIZE);
world->murs[5] = init_sprite(world->murs[5], 252, -672, 3*METEORITE_SIZE, 6*METEORITE_SIZE);
world->nb_murs = 0;
world->murs = malloc(sizeof(sprite_t) * MAX_LENGTH*MAX_LINES);
int nblignes = 0;
char **txt = lirefile("maps/default.txt", &nblignes);
printf("aaiaa");
for (int i = 0; i < nblignes; i++) {
for (int j = 0; j < 26; j++) {
if (txt[i][j] == '1'){
world->murs[world->nb_murs] = init_sprite(world->murs[world->nb_murs], j*METEORITE_SIZE, i*METEORITE_SIZE, METEORITE_SIZE, METEORITE_SIZE);
world->nb_murs++;
}
}
printf("%s\n", txt[i]);
}
printf("aaaa");
}
......
No preview for this file type
......@@ -21,4 +21,24 @@ char * int_to_str(int n) {
char *str = malloc(sizeof(char) * 10);
sprintf(str, "%d", n);
return str;
}
char **lirefile(char *filename, int *num_lines) {
FILE *file = fopen(filename, "r");
if (file == NULL) {
perror("Error opening file");
return NULL;
}
char **lines = malloc(MAX_LINES * sizeof(char *));
*num_lines = 0;
char buffer[MAX_LENGTH];
while (fgets(buffer, MAX_LENGTH, file) != NULL && *num_lines < MAX_LINES) {
lines[*num_lines] = malloc(MAX_LENGTH * sizeof(char));
sprintf(lines[*num_lines], "%s", buffer);
(*num_lines)++;
}
fclose(file);
return lines;
}
\ No newline at end of file
......@@ -12,6 +12,8 @@
#ifndef Utility_h
#define Utility_h
#define MAX_LINES 1000
#define MAX_LENGTH 200
/**
* \brief Concatène plusieurs chaines de caractères
......@@ -31,4 +33,14 @@ char * strcats(char* dest, int num_args, ...);
*/
char * int_to_str(int n);
/**
* \brief Lit un fichier et retourne un tableau de lignes
*
* \param filename Le nom du fichier
* \param num_lines Le nombre de lignes
* \return char**
*/
char ** lirefile(char *filename, int *num_lines);
#endif
\ No newline at end of file
No preview for this file type
010000000011110000000000
001001111100011100000110
\ No newline at end of file
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