From 5cd0a1991a8e0f94f923a2637ff216846485d630 Mon Sep 17 00:00:00 2001 From: Lephenixnoir Date: Sun, 16 Jan 2022 22:54:11 +0100 Subject: [PATCH] fadeout effect + levels up to 8_4 --- CMakeLists.txt | 4 +++ assets-cg/level/level5_1.txt | 18 ++++++------- assets-cg/level/level5_2.txt | 10 ++++---- assets-cg/level/level5_3.txt | 4 +-- assets-cg/level/level5_4.txt | 8 +++--- assets-cg/level/level5_5.txt | 8 +++--- assets-cg/level/level5_6.txt | 18 ++++++------- assets-cg/level/level7_4.txt | 10 ++++---- assets-cg/level/level7_5.txt | 16 ++++++------ assets-cg/level/level7_6.txt | 14 +++++------ assets-cg/level/level8_1.txt | 2 +- assets-cg/level/level8_2.txt | 6 ++--- assets-cg/level/level8_3.txt | 8 +++--- assets-cg/level/level8_4.txt | 18 ++++++------- converters.py | 17 ++++++++----- src/duet.h | 18 ++++++++++--- src/main.c | 10 +++++++- src/physics.c | 31 ++++++++++++++++++++--- src/render.c | 49 ++++++++++++++++++++++++++++++++---- 19 files changed, 180 insertions(+), 89 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index d770dd6..326b120 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -60,6 +60,10 @@ set(ASSETS assets-cg/level/level7_4.txt assets-cg/level/level7_5.txt assets-cg/level/level7_6.txt + assets-cg/level/level8_1.txt + assets-cg/level/level8_2.txt + assets-cg/level/level8_3.txt + assets-cg/level/level8_4.txt ) fxconv_declare_converters(converters.py) diff --git a/assets-cg/level/level5_1.txt b/assets-cg/level/level5_1.txt index 4d56f39..c8a2416 100644 --- a/assets-cg/level/level5_1.txt +++ b/assets-cg/level/level5_1.txt @@ -2,36 +2,36 @@ !1.0 left -middle slow_1 +middle slow right -middle slow_1 +middle slow left -left slow_1 +left slow square left -square right slow_1 +square right slow middle -right slow_1 +right slow left -left slow_1 +left slow right -left slow_1 +left slow middle -left slow_1 +left slow right -right slow_1 +right slow diff --git a/assets-cg/level/level5_2.txt b/assets-cg/level/level5_2.txt index aba1133..79b8bed 100644 --- a/assets-cg/level/level5_2.txt +++ b/assets-cg/level/level5_2.txt @@ -4,7 +4,7 @@ left left -left slow_1 +left slow left small right @@ -19,16 +19,16 @@ middle square left -square right slow_1 +square right slow right -right slow_1 +right slow left -left slow_1 +left slow left -left slow_1 +left slow diff --git a/assets-cg/level/level5_3.txt b/assets-cg/level/level5_3.txt index a89fc88..ddea544 100644 --- a/assets-cg/level/level5_3.txt +++ b/assets-cg/level/level5_3.txt @@ -7,7 +7,7 @@ right right -square left slow_1 +square left slow square right @@ -21,7 +21,7 @@ left fast_1 middle -left slow_1 +left slow left diff --git a/assets-cg/level/level5_4.txt b/assets-cg/level/level5_4.txt index bb14410..72ad12e 100644 --- a/assets-cg/level/level5_4.txt +++ b/assets-cg/level/level5_4.txt @@ -4,7 +4,7 @@ right right -left slow_1 +left slow small right left @@ -23,13 +23,13 @@ small left left -left slow_1 +left slow right outer_rotate_left middle rotate_right -right slow_1 +right slow right @@ -37,4 +37,4 @@ middle rotate_left right -right slow_1 +right slow diff --git a/assets-cg/level/level5_5.txt b/assets-cg/level/level5_5.txt index fc2ac28..872c869 100644 --- a/assets-cg/level/level5_5.txt +++ b/assets-cg/level/level5_5.txt @@ -6,7 +6,7 @@ right right -right slow_1 +right slow right outer_rotate_left @@ -24,17 +24,17 @@ right fast_1 left -right slow_1 +right slow right -right slow_1 +right slow right middle -middle slow_1 +middle slow middle fast_1 diff --git a/assets-cg/level/level5_6.txt b/assets-cg/level/level5_6.txt index 5e14ef5..2af5838 100644 --- a/assets-cg/level/level5_6.txt +++ b/assets-cg/level/level5_6.txt @@ -3,34 +3,34 @@ middle left -small right slow_1 +small right slow square left -square right slow_1 +square right slow -right slow_1 +right slow small left left -left slow_1 +left slow -left square slow_1 +left square slow right square right -small left slow_1 +small left slow -right slow_1 +right slow right -square left slow_1 +square left slow square right square left -square right slow_1 +square right slow diff --git a/assets-cg/level/level7_4.txt b/assets-cg/level/level7_4.txt index d3b4928..5323c1e 100644 --- a/assets-cg/level/level7_4.txt +++ b/assets-cg/level/level7_4.txt @@ -1,6 +1,6 @@ #But if we expect something,\nhow can it move us? !1.2 -right slow_1 +right slow right @@ -9,7 +9,7 @@ small right square left -square right slow_1 +square right slow square right fast_1 @@ -22,7 +22,7 @@ left fast_1 middle -square left slow_1 +square left slow square right @@ -41,7 +41,7 @@ middle rotate_right middle rotate_right -middle slow_1 +middle slow square right @@ -49,7 +49,7 @@ square left middle rotate_right -middle slow_1 +middle slow middle fast_1 diff --git a/assets-cg/level/level7_5.txt b/assets-cg/level/level7_5.txt index 978eef5..11634f4 100644 --- a/assets-cg/level/level7_5.txt +++ b/assets-cg/level/level7_5.txt @@ -6,7 +6,7 @@ right square right -square left slow_1 +square left slow left slide @@ -14,10 +14,10 @@ left slide left slide -middle slow_1 +middle slow right -small left slow_1 +small left slow middle fast_1 @@ -28,7 +28,7 @@ small left right -right slow_1 +right slow right fast_1 @@ -36,7 +36,7 @@ left middle rotate_right -square left slow_1 +square left slow square right @@ -59,13 +59,13 @@ left right outer_rotate_left left -small right slow_1 +small right slow right -right slow_1 +right slow -middle slow_1 +middle slow square right fast_1 diff --git a/assets-cg/level/level7_6.txt b/assets-cg/level/level7_6.txt index 944a0f9..44aab11 100644 --- a/assets-cg/level/level7_6.txt +++ b/assets-cg/level/level7_6.txt @@ -4,13 +4,13 @@ square left square right -square left slow_1 +square left slow square right right slide -square left slow_1 +square left slow square right @@ -30,7 +30,7 @@ middle fast_1 left -middle slow_1 +middle slow square left fast_1 @@ -60,7 +60,7 @@ left square right -square left slow_1 +square left slow left outer_rotate_right @@ -69,13 +69,13 @@ small left right -right slow_1 +right slow square left square right -right slow_1 +right slow right @@ -84,7 +84,7 @@ small right square left -sqaure right slow_1 +sqaure right slow left fast_1 diff --git a/assets-cg/level/level8_1.txt b/assets-cg/level/level8_1.txt index 1be40b4..e52d185 100644 --- a/assets-cg/level/level8_1.txt +++ b/assets-cg/level/level8_1.txt @@ -1,5 +1,5 @@ #I wish you could see this. - +!1.0 left left fadeout_2 diff --git a/assets-cg/level/level8_2.txt b/assets-cg/level/level8_2.txt index 64612f3..90c552a 100644 --- a/assets-cg/level/level8_2.txt +++ b/assets-cg/level/level8_2.txt @@ -1,5 +1,5 @@ #You wouldn't be here if it\nweren't for me. - +!1.1 middle left fadeout_2 @@ -8,9 +8,9 @@ middle fadeout_2 right fadeout_2 -square left +square left fadeout_3 -square right +square right fadeout_3 middle fadeout_2 diff --git a/assets-cg/level/level8_3.txt b/assets-cg/level/level8_3.txt index 838a02b..3f26298 100644 --- a/assets-cg/level/level8_3.txt +++ b/assets-cg/level/level8_3.txt @@ -1,20 +1,20 @@ #Admit it. - +!1.15 left left fadeout_2 -right fast_2 fadeout_3 +right fast_1 fadeout_3 left fadeout_3 -right fadeout_1 +right fadeout_2 left fast_1 fadeout_3 right fadeout_3 -left fadeout_1 +left fadeout_2 right fast_1 fadeout_3 diff --git a/assets-cg/level/level8_4.txt b/assets-cg/level/level8_4.txt index 17662d3..917e693 100644 --- a/assets-cg/level/level8_4.txt +++ b/assets-cg/level/level8_4.txt @@ -1,27 +1,27 @@ #Change is good for you. - -right +!1.2 +right slow fadeout_3 right fadeout_3 left fast_1 fadeout_3 small right fadeout_3 -square right slide fast_2 fadeout_3 +square right slide fadeout_3 -square left slide fast_2 fadeout_3 +square left slide fadeout_3 -right fadeout_3 +right slow fadeout_3 right fadeout_3 square right slide fadeout_3 -sqaure left slide fadeout_3 +square left slide fadeout_3 -right fast_2 fadeout_3 +right fast_1 fadeout_3 -left fast_2 fadeout_3 +left fadeout_3 right slide fadeout_3 @@ -32,6 +32,6 @@ right slide fadeout_3 right fadeout_3 small left fadeout_3 -middle fast_2 fadeout_3 +middle fast_1 fadeout_3 right fadeout_3 diff --git a/converters.py b/converters.py index 05c65ae..58d8d1b 100644 --- a/converters.py +++ b/converters.py @@ -24,15 +24,13 @@ def convert_level(input, output, params, target): if line.startswith("!"): speed = float(line[1:]) - print(speed) - blocks = bytes() block_count = 0 for (tempo, rects) in enumerate(lines): for r in [r for r in rects if r]: r = r.strip().split() - shape, action, position = -1, 0, -1 + shape, action, fadeout, position = -1, 0, 0, -1 # Anti-bad-notation if "middle" in r and "rotate" in r and ("left" in r or "right" in r): @@ -69,8 +67,6 @@ def convert_level(input, output, params, target): action = 2 if "fast_1" in r: action = 3 - if "fadeout" in r: - action = 4 if "outer_rotate_left" in r: action = 5 if "outer_rotate_right" in r: @@ -81,13 +77,21 @@ def convert_level(input, output, params, target): action = 8 if "fast_3" in r: action = 9 - if "slow_1" in r: + if "slow" in r: action = 10 if "rotate" in r and position == 0: action = 6 if "rotate" in r and position == 1: action = 5 + # Fadeout + if "fadeout_1" in r: + fadeout = 1 + if "fadeout_2" in r: + fadeout = 2 + if "fadeout_3" in r: + fadeout = 3 + # Implicit rules # Rotating in the middle -> long @@ -110,6 +114,7 @@ def convert_level(input, output, params, target): blocks += fxconv.u32(shape) blocks += fxconv.u32(position) blocks += fxconv.u32(action) + blocks += fxconv.u32(fadeout) block_count += 1 o = fxconv.ObjectData() diff --git a/src/duet.h b/src/duet.h index 61cdf06..acd517d 100644 --- a/src/duet.h +++ b/src/duet.h @@ -28,15 +28,22 @@ typedef enum { Action_RotateLeft = 1, Action_RotateRight = 2, Action_Speed1 = 3, - Action_FadeOut = 4, + Action__4 = 4, Action_OuterRotateLeft = 5, Action_OuterRotateRight = 6, Action_Slide = 7, Action_Speed2 = 8, Action_Speed3 = 9, - Action_Slow1 = 10, + Action_Slow = 10, } action_t; +typedef enum { + Fadeout_None = 0, + Fadeout_1 = 1, + Fadeout_2 = 2, + Fadeout_3 = 3, +} fadeout_t; + typedef enum { Position_Left = 0, Position_Right = 1, @@ -48,6 +55,7 @@ typedef struct { shape_t shape; position_t position; action_t action; + fadeout_t fadeout; } rectmeta_t; typedef struct { @@ -79,6 +87,7 @@ typedef struct { float y_init; /* px */ float x, y; /* px */ float r; /* rad */ + int opacity; /* 0..256 */ rectmeta_t const *meta; } rect_t; @@ -111,7 +120,8 @@ typedef struct game { void dcircle(int x, int y, int r, int color, bool fill); -void dtriangle(int x1, int y1, int x2, int y2, int x3, int y3, int color); +void dtriangle(int x1, int y1, int x2, int y2, int x3, int y3, int color, + int opacity); void drectoid(rect_t const *r, float extra_size, int color); @@ -151,6 +161,8 @@ extern level_t level4_1, level4_2, level4_3, level4_4, level4_5, level4_6; extern level_t level5_1, level5_2, level5_3, level5_4, level5_5, level5_6; extern level_t level6_1, level6_2, level6_3, level6_4, level6_5, level6_6; extern level_t level7_1, level7_2, level7_3, level7_4, level7_5, level7_6; +extern level_t level8_1, level8_2, level8_3, level8_4, level8_5, level8_6, + level8_7, level8_8, level8_9; extern episode_t episodes[]; extern int episode_count; diff --git a/src/main.c b/src/main.c index 5234fc7..cb020aa 100644 --- a/src/main.c +++ b/src/main.c @@ -73,6 +73,13 @@ episode_t episodes[] = { &level7_1, &level7_2, &level7_3, &level7_4, &level7_5, &level7_6 }, }, + { + .name = "acceptance", + .level_count = 4, + .levels = (level_t *[]){ + &level8_1, &level8_2, &level8_3, &level8_4 + }, + }, }; int episode_count = sizeof(episodes) / sizeof(episodes[0]); @@ -300,7 +307,8 @@ void game_loop(int current_episode, int current_level) for(int i = 0; i < 10; i++) { int x=DWIDTH+2-40*i-20, y=20; - rect_t rect = { .x=x, .y=y, .w=20, .h=20, .r=1.0*game.time }; + rect_t rect = { .x=x, .y=y, .w=20, .h=20, .r=1.0*game.time, + .opacity=256 }; drectoid(&rect, 0, C_RGB(4, 4, 4)); } for(int j = 1; j < 6; j++) { diff --git a/src/physics.c b/src/physics.c index f699a2f..77826f9 100644 --- a/src/physics.c +++ b/src/physics.c @@ -116,6 +116,7 @@ void rect_load(rect_t *r, rectmeta_t const *meta) } r->y = r->y_init; + r->opacity = 256; } float cubic_ease(float t) @@ -131,6 +132,8 @@ void rect_physics(rect_t *r, rectmeta_t const *meta, float absolute_time) r->y = r->y_init; r->r = 0; + /* Action */ + if(meta->action == Action_RotateLeft) { float vr = 2.0; /* rad/tempo */ r->r = -0.3 + time * vr; @@ -144,9 +147,6 @@ void rect_physics(rect_t *r, rectmeta_t const *meta, float absolute_time) float speeding_period = fminf(2.0, fmaxf(0.0, time + 4.0)); r->x -= RECT_SPEED * (speeding_period - 2.0); } - else if(meta->action == Action_FadeOut) { - // TODO - } else if(meta->action == Action_OuterRotateLeft) { float vr = 0.7; /* rad/tempo */ r->r = time * vr; @@ -172,6 +172,7 @@ void rect_physics(rect_t *r, rectmeta_t const *meta, float absolute_time) /* Stay there indefinitely */ else r->y += amp; } +#if 0 else if(meta->action == Action_Speed2) { /* Speed x1.5 permanently */ r->x -= RECT_SPEED * time * 0.5; @@ -179,9 +180,31 @@ void rect_physics(rect_t *r, rectmeta_t const *meta, float absolute_time) else if(meta->action == Action_Speed3) { // TODO } - else if(meta->action == Action_Slow1) { +#endif + else if(meta->action == Action_Slow) { /* Speed x2/3 until they come close enough to you */ if(time <= -1.0) r->x += RECT_SPEED * (time + 1) / 3; } + + /* Fadeout */ + + if(meta->fadeout == Fadeout_2) { + /* Reduce opacity to 0 between -4 and -2.5 */ + if(time > -2.5) + r->opacity = 0; + else if(time >= -4.0) + r->opacity = 256 * (1 - (time + 4) / 1.5); + else + r->opacity = 256; + } + if(meta->fadeout == Fadeout_3) { + /* Reduce opacity to 0 between -1 and 0.5 */ + if(time > 0.5) + r->opacity = 0; + else if(time >= -1.0) + r->opacity = 256 * (1 - (time + 1) / 1.5); + else + r->opacity = 256; + } } diff --git a/src/render.c b/src/render.c index 5bc1300..4e6d694 100644 --- a/src/render.c +++ b/src/render.c @@ -26,6 +26,23 @@ void dcircle(int cx, int cy, int r0, int color, bool fill) while(x < 0); } +/* Blend to white (slow) */ +static uint16_t blend(uint16_t bg, uint16_t fg, int opacity) +{ + int R_bg = (bg >> 11); + int G_bg = (bg >> 6) & 0x1f; + int B_bg = bg & 0x1f; + + int R_fg = (fg >> 11); + int G_fg = (fg >> 6) & 0x1f; + int B_fg = fg & 0x1f; + + int R = (R_fg * opacity + R_bg * (256 - opacity)) >> 8; + int G = (G_fg * opacity + G_bg * (256 - opacity)) >> 8; + int B = (B_fg * opacity + B_bg * (256 - opacity)) >> 8; + return C_RGB(R, G, B); +} + /* From Windmill::render_triangle_black */ static int edge_start(int x1, int y1, int x2, int y2, int px, int py) { @@ -39,7 +56,8 @@ static int max(int x, int y) { return (x > y) ? x : y; } -void dtriangle(int x1, int y1, int x2, int y2, int x3, int y3, int color) +void dtriangle(int x1, int y1, int x2, int y2, int x3, int y3, int color, + int opacity) { // calcul du rectangle circonscrit au triangle int min_x = max(0, min(x1, min(x2, x3))); @@ -71,7 +89,12 @@ void dtriangle(int x1, int y1, int x2, int y2, int x3, int y3, int color) // si le pixel (x;y) est dans le triangle if ((u0 | u1 | u2) > 0) { - dpixel(x, y, color); + int i = DWIDTH * y + x; + + if(opacity > 0xff) + gint_vram[i] = color; + else + gint_vram[i] = blend(gint_vram[i], color, opacity); } u0 += u0_step_y; u1 += u1_step_y; u2 += u2_step_y; } @@ -81,6 +104,9 @@ void dtriangle(int x1, int y1, int x2, int y2, int x3, int y3, int color) void drectoid(rect_t const *r, float extra_size, int color) { + if(r->opacity == 0) + return; + float w = r->w + 2 * extra_size; float h = r->h + 2 * extra_size; @@ -91,7 +117,20 @@ void drectoid(rect_t const *r, float extra_size, int color) float y0[4] = { -h/2, -h/2, h/2, h/2 }; if(r->r == 0) { - drect(r->x+x0[1], r->y+y0[1], r->x+x0[3], r->y+y0[3], color); + int x1=r->x+x0[1], x2=r->x+x0[3], y1=r->y+y0[1], y2=r->y+y0[3]; + if(r->opacity > 0xff) + drect(x1, y1, x2, y2, color); + else { + y1 = max(y1, 0); + y2 = min(y2, DHEIGHT-1); + x1 = max(x1, 0); + x2 = min(x2, DWIDTH-1); + for(int y = y1; y <= y2; y++) + for(int x = x1; x <= x2; x++) { + int i = y * DWIDTH + x; + gint_vram[i] = blend(gint_vram[i], color, r->opacity); + } + } return; } @@ -104,8 +143,8 @@ void drectoid(rect_t const *r, float extra_size, int color) y[i] = r->y - x0[i] * sin + y0[i] * cos; } - dtriangle(x[0], y[0], x[1], y[1], x[2], y[2], color); - dtriangle(x[2], y[2], x[3], y[3], x[0], y[0], color); + dtriangle(x[0], y[0], x[1], y[1], x[2], y[2], color, r->opacity); + dtriangle(x[2], y[2], x[3], y[3], x[0], y[0], color, r->opacity); } void render_player(int x, int y, float angle)