diff --git a/src/draw_time.c b/src/draw_time.c index d74ae67..821da59 100644 --- a/src/draw_time.c +++ b/src/draw_time.c @@ -1,3 +1,4 @@ +#include "define.h" #include "times.h" #include @@ -5,9 +6,29 @@ extern bopti_image_t img_medals; extern float level_time[]; +static const float medal_multiplier[4] = {1.0, 1.2, 1.5, 2}; + +void check_medal(unsigned int frame_level, int id_level, int x, int y) +{ + const float time = level_time[id_level - 1]; + const int player_time = (int)((float)frame_level / FPS * 100.0); + int i; + + /* OK, this doesn't have the exact same behavior than the previously + * generated code had. But the conditions were so dirty and hard to + * understand than I simplified it. + * -- KikooDX */ + for (i = 0; i < 4; i += 1) { + const int mtime = (int)(time * medal_multiplier[i] * 100.0); + if (player_time <= mtime) { + dsubimage(x + 15 * (3 - i), y, &img_medals, + 12 * (3 - i), 0, 12, 12, DIMAGE_NONE); + } + } +} + void draw_time(int id_level) { - static const float medal_multiplier[4] = {1.0, 1.2, 1.5, 2}; const float time = level_time[id_level - 1]; int draw_y = 140; int medal_x = 36; diff --git a/time.py b/time.py index b25a040..9da41d6 100755 --- a/time.py +++ b/time.py @@ -23,25 +23,10 @@ dest.write("""#include "times.h" #include "define.h" #include #include + extern bopti_image_t img_medals; -float level_time[] = {""") +float level_time[] = {\n\t""") -dest.write(f"{','.join(times)}") - -dest.write("};\n\ -void check_medal(unsigned int frame_level, int id_level, int x, int y)\n\ -{\n\ -float time=1.0;\n\ -float framefloat = frame_level;") - -dest.write("\ntime = level_time[id_level-1];\n\n\ -if(frame_level/FPS < (unsigned int)time || (frame_level/FPS <= (unsigned int)time && \n\ -(unsigned int)((framefloat)/FPS*100-frame_level/FPS*100) <= (unsigned int)((time)*100-(int)(time)*100))) dsubimage(x+45,y,&img_medals,36,0,12,12,DIMAGE_NONE);\n\ -if(frame_level/FPS < (unsigned int)(time*"+str(gold)+") || (frame_level/FPS <= (unsigned int)(time*"+str(gold)+") && \n\ -(unsigned int)((framefloat)/FPS*100-frame_level/FPS*100) <= (unsigned int)((time*"+str(gold)+")*100-(int)(time*"+str(gold)+")*100))) dsubimage(x+30,y,&img_medals,24,0,12,12,DIMAGE_NONE);\n\ -if(frame_level/FPS < (unsigned int)(time*"+str(silver)+") || (frame_level/FPS <= (unsigned int)(time*"+str(silver)+") && \n\ -(unsigned int)((framefloat)/FPS*100-frame_level/FPS*100) <= (unsigned int)((time*"+str(silver)+")*100-(int)(time*"+str(silver)+")*100))) dsubimage(x+15,y,&img_medals,12,0,12,12,DIMAGE_NONE);\n\ -if(frame_level/FPS < (unsigned int)(time*"+str(bronze)+") || (frame_level/FPS <= (unsigned int)(time*"+str(bronze)+") && \n\ -(unsigned int)((framefloat)/FPS*100-frame_level/FPS*100) <= (unsigned int)((time*"+str(bronze)+")*100-(int)(time*"+str(bronze)+")*100))) dsubimage(x,y,&img_medals,0,0,12,12,DIMAGE_NONE);\n\ -}\n") +dest.write("{}".format(',\n\t'.join(times))) +dest.write("\n};")