Merge pull request 'New timer draw functions and rewrite of times.py' (#10) from KikooDX/AST3_C:master into master

Reviewed-on: https://gitea.planet-casio.com/Tituya/AST3_C/pulls/10
This commit is contained in:
Tituya 2021-05-05 17:07:40 +02:00
commit dfc151ff1a
5 changed files with 57 additions and 41 deletions

View File

@ -51,6 +51,7 @@ add_custom_command(
set(SOURCES
src/collide.c
src/drawlevel.c
src/draw_time.c
src/main.c
src/menu.c
src/save.c

View File

@ -1,3 +1,3 @@
#!/usr/bin/bash
#!/bin/sh
echo "opening editor"
python3 editor/AST3generator.py

View File

@ -1,4 +1,4 @@
#pragma once
void check_medal(unsigned int frame_level, int id_level, int x, int y);
void draw_time(int id_level);
void draw_time(int id_level);

44
src/draw_time.c Normal file
View File

@ -0,0 +1,44 @@
#include "define.h"
#include "times.h"
#include <gint/display.h>
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 */
i = 4;
while (i-- > 0) {
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)
{
const float time = level_time[id_level - 1];
int i;
i = 4;
while (i-- > 0) {
const int draw_y = 140 + 20 * i;
dsubimage(340, draw_y, &img_medals, 12 * (3 - i), 0, 12, 12,
DIMAGE_NONE);
dprint(355, draw_y + 1, C_BLACK, "%.2j",
(int)(time * medal_multiplier[i] * 100));
}
}

49
time.py
View File

@ -1,5 +1,5 @@
gold = 1.2
argent = 1.5
silver = 1.5
bronze = 2
x = 340
@ -11,7 +11,7 @@ lvm = open("generated/include/define.h","r")
ids=timeslevel.readlines()
times=[]
for i in ids:
for i in ids:
times.append(i.rstrip())
nblvl = int(''.join(filter(str.isdigit,lvm.readline())))
@ -19,43 +19,14 @@ nblvl = int(''.join(filter(str.isdigit,lvm.readline())))
while(len(times) < nblvl):
times.append("0.00")
dest.write("#include \"times.h\"\n\
#include \"define.h\"\n\
#include <gint/display.h>\n\
#include <gint/keyboard.h>\n\n\
extern bopti_image_t img_medals;\n\
float level_time[] = {")
dest.write("""#include "times.h"
#include "define.h"
#include <gint/display.h>
#include <gint/keyboard.h>
dest.write(f"{','.join(times)}")
extern bopti_image_t img_medals;
float level_time[] = {\n\t""")
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("{}".format(',\n\t'.join(times)))
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(argent)+") || (frame_level/FPS <= (unsigned int)(time*"+str(argent)+") && \n\
(unsigned int)((framefloat)/FPS*100-frame_level/FPS*100) <= (unsigned int)((time*"+str(argent)+")*100-(int)(time*"+str(argent)+")*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\
\n\
void draw_time(int id_level)\n\
{\n\
float time=1.0;\n")
dest.write("\ntime = level_time[id_level-1];\n\n\
dsubimage("+str(x)+","+str(y)+",&img_medals,36,0,12,12,DIMAGE_NONE);\n\
dprint("+str(x+15)+","+str(y)+",C_BLACK,\"%.2j\",(int)(time*100));\n\
dsubimage("+str(x)+","+str(y+20)+",&img_medals,24,0,12,12,DIMAGE_NONE);\n\
dprint("+str(x+15)+","+str(y+20)+",C_BLACK,\"%.2j\",(int)(time*"+str(gold)+"*100));\n\
dsubimage("+str(x)+","+str(y+40)+",&img_medals,12,0,12,12,DIMAGE_NONE); \n\
dprint("+str(x+15)+","+str(y+40)+",C_BLACK,\"%.2j\",(int)(time*"+str(argent)+"*100));\n\
dsubimage("+str(x)+","+str(y+60)+",&img_medals,0,0,12,12,DIMAGE_NONE); \n\
dprint("+str(x+15)+","+str(y+60)+",C_BLACK,\"%.2j\",(int)(time*"+str(bronze)+"*100));\n\
}")
dest.write("\n};")