diff --git a/Makefile b/Makefile index 52820db..f410968 100644 --- a/Makefile +++ b/Makefile @@ -4,8 +4,11 @@ LFLAGS = -lSDL2 -lSDL2_image -lm -lncurses all: bin/back -test: bin/back - bin/back +test0: bin/back + bin/back templates.txt 47 + +test1: bin/back + bin/back templates_lv2.txt 49 bin/back: obj/main.o obj/generation.o obj/display.o obj/base.o obj/hash.o obj/move.o mkdir -p bin diff --git a/bin/back b/bin/back index 39a460a..f25716c 100755 Binary files a/bin/back and b/bin/back differ diff --git a/src/base.c b/src/base.c index 471a869..aba5b62 100644 --- a/src/base.c +++ b/src/base.c @@ -99,6 +99,17 @@ int line_count(char* filename) { return (n+1); } +int str_to_int(char* s) { + int res = 0 ; + int i = 0 ; + while(s[i] != '\0' && is_an_integer(s[i])) { + res *= 10 ; + res += (int)s[i] - 48 ; + i++; + }; + return res; +} + int get_integer(FILE* ptr) { char c = fgetc(ptr); diff --git a/src/base.h b/src/base.h index 701fdde..c693eb7 100644 --- a/src/base.h +++ b/src/base.h @@ -25,6 +25,8 @@ double distance_pt(int x1, int x2, int y1, int y2); int line_count(char* filename); +int str_to_int(char* s); + int get_integer(FILE* ptr); int get_integer_plus_align(FILE* ptr, FILE* ptr2); diff --git a/src/display.c b/src/display.c index 9153fe5..ff17c0c 100644 --- a/src/display.c +++ b/src/display.c @@ -139,9 +139,6 @@ void drawStringToRenderer(SDL_Renderer* renderer, imgs data, char* s, int X, int void drawChunkToRenderer(SDL_Renderer* renderer, chunk* ch, int xmin, int xmax, int ymin, int ymax) { if(ch->draw_id != draw_par) { ch->draw_id = draw_par ; - //printf("[DDDDD] chunk (%d, %d) has signature : \n", ch.chx, ch.chy); - //signature(ch.chdata); - //printf("\n"); for(int i = 0; i < 8; i++) { uint8_t cur = ch->chdata.lines[i] ; for(int j = 0; j < 8; j++) { @@ -150,13 +147,16 @@ void drawChunkToRenderer(SDL_Renderer* renderer, chunk* ch, int xmin, int xmax, int cux2 = 50*(8*ch->chx + j+1); int cuy2 = 50*(8*ch->chy + i+1); if(true) { - //if(cux - 50/zoom > xmin || cux - 50/zoom < xmax || cuy > ymin || cuy < ymax) { if(cur%2 == 1) { int nxmin = to_int((to_double(cux) - to_double(xmin)) * to_double(__width__)) / (to_double(xmax) - to_double(xmin)) ; int nymin = to_int((to_double(cuy) - to_double(ymin)) * to_double(__height__)) / (to_double(ymax) - to_double(ymin)) ; int nxmin2 = to_int((to_double(cux2) - to_double(xmin)) * to_double(__width__)) / (to_double(xmax) - to_double(xmin)) ; int nymin2 = to_int((to_double(cuy2) - to_double(ymin)) * to_double(__height__)) / (to_double(ymax) - to_double(ymin)) ; - placeRectToRenderer(renderer, nxmin, nymin, nxmin2 - nxmin, nymin2 - nymin, 255, 255, 255, SDL_ALPHA_OPAQUE); + if(abs(ch->chx + ch->chy)%2 == 0) { + placeRectToRenderer(renderer, nxmin, nymin, nxmin2 - nxmin, nymin2 - nymin, 255, 192, 192, SDL_ALPHA_OPAQUE); + } else { + placeRectToRenderer(renderer, nxmin, nymin, nxmin2 - nxmin, nymin2 - nymin, 192, 192, 255, SDL_ALPHA_OPAQUE); + } }; cur = cur / 2 ; } diff --git a/src/generation.c b/src/generation.c index 82d6ef2..9cdd6a4 100644 --- a/src/generation.c +++ b/src/generation.c @@ -215,7 +215,8 @@ void generate_chunk_all(int cx, int cy) { } } }; - //printf("\ngenerating %d\n", idx); + //printf("generating %d at (%d, %d)...\n", idx, cx, cy); + //print_template(idx); generate_chunk(cx, cy, idx); } @@ -250,10 +251,10 @@ void parse_one(FILE* ptr, FILE* ptr2, int index) { configs[index].lines[i] *= 2 ; configs[index].lines[i] += xres ; - if(j == 0) { + if(j == 7) { configs[index].westsig *= 2; configs[index].westsig += xres; - } else if(j == 7) { + } else if(j == 0) { configs[index].eastsig *= 2; configs[index].eastsig += xres; } diff --git a/src/main.c b/src/main.c index 4aab574..98bedf3 100644 --- a/src/main.c +++ b/src/main.c @@ -19,6 +19,15 @@ #include "move.h" int main(int argc, char** argv) { + + if(argc != 3) { + fprintf(stderr, "usage : bin/back \n"); + exit(1); + }; + + char* filename = argv[1]; + int length = str_to_int(argv[2]); + srand(time(NULL)); //-------------------------------------------------------------------------------// @@ -43,13 +52,16 @@ int main(int argc, char** argv) { /* -------------------------------------------------------- */ //one_debug(); - parse_configs("templates.txt", 47); + parse_configs(filename, length); initialize(rend); - //print_template(1); - //rotateTemplateClockWise(1); - //print_template(1); + int temp = render_distance ; + for(int i = 1; i <= temp; i++) { + printf("%d/%d\n", i, temp); + render_distance = i ; + drawMapToRenderer(rend, -300 * 250/zoom + to_int(50 * (8*player_cx + player_x + εx)), 300 * 250/zoom + to_int(50 * (8*player_cx + player_x + εx)), -300 * 250/zoom + to_int(50 * (8*player_cy + player_y + εy)), 300 * 250/zoom + to_int(50 * (8*player_cy + player_y + εy))); + }; moveFunctionMaster(rend); @@ -61,5 +73,7 @@ int main(int argc, char** argv) { SDL_DestroyWindow(win); SDL_Quit(); + /* -------------------------------------------------------- */ + return 0; } \ No newline at end of file diff --git a/templates_lv2.txt b/templates_lv2.txt new file mode 100644 index 0000000..ab1a6b9 --- /dev/null +++ b/templates_lv2.txt @@ -0,0 +1,442 @@ +1 1 1 1 1 1 1 1 +1 0 0 0 0 0 0 1 +1 0 1 1 1 1 0 1 +1 0 1 0 0 1 0 1 +1 0 1 0 0 1 0 1 +1 0 1 1 1 1 0 1 +1 0 0 0 0 0 0 1 +1 1 1 1 1 1 1 1 + +1 1 1 1 1 1 1 1 +1 1 1 1 1 1 1 1 +1 1 1 1 1 1 1 1 +1 1 1 1 1 1 1 1 +1 1 1 1 1 1 1 1 +1 1 1 1 1 1 1 1 +1 1 1 1 1 1 1 1 +1 1 1 1 1 1 1 1 + +1 0 1 1 1 1 0 1 +0 0 0 0 0 0 0 0 +1 1 1 0 0 1 1 1 +1 1 1 0 0 1 1 1 +1 1 1 0 0 1 1 1 +1 1 1 0 0 1 1 1 +0 0 0 0 0 0 0 0 +1 0 1 1 1 1 0 1 + +1 0 1 1 1 1 1 1 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