I have been combating with the extent up display screen – all of the bits and items animating in, with the correct timing and the whole lot.
Became an entire unreadable heap of spaghetti, which simply barely labored. Any additions and I might be utterly misplaced.
Y’know the kind of “after I wrote this code, solely god and I knew what it did – now solely god is aware of”, however already 5 minutes after the very fact.
Simply had a bit state variable, only a counter, which I’d increment someplace in the entire heap of spaghetti, after which go into one other if-else case updating the blood splatters, or the playing cards animating into the display screen.
I believe I simply anticipated this to be much less advanced, however I needed a number of issues occurring after each other, and shortly I used to be left with a 200-ish line monstrosity that was shortly rising out of hand.
A literal bathe thought introduced me to the easy resolution: My information construction (none) was the mistaken one for this sort of factor.
All I wanted to scrub it up was a fundamental loop that known as an array of capabilities with the corresponding replace and draw capabilities break up into them.
states = {
{ –blood splatters and title
animation_duration = 0.75,
replace = wait_update,
draw = operate ()
SCREEN_MAIN_GAME.draw()
native cw = level_up_canvas:getWidth()
native ch = level_up_canvas:getHeight()
native spl = SPRITES.ui.splatter_left.picture
native spr = SPRITES.ui.splatter_right.picture
native title = SPRITES.ui.choose_your_curse.picture
native v_unit = SCREEN_H / 25
native shadow_offset = v_unit / 2
native scale_factor = SCREEN_W / NATIVE_SCREEN_W
native spl_x = 0
native spl_y = ch / 5
native spr_x = cw – spl:getWidth() * scale_factor
native spr_y = 0
native splatter_left_percentage = UTIL.ease_in_quint(animation_percentage)
LG.setCanvas(level_up_canvas)
LG.clear(0, 0, 0, 0)
–draw the splatters
if OPTIONS.ui.childsafe_mode then
LG.setColor(INK_BLACK)
else
LG.setColor(BLOOD_RED)
finish
circular_splash_shader:ship(“visible_dist”, splatter_left_percentage * cw)
LG.setShader(circular_splash_shader)
LG.draw(
spl,
spl_x,
spl_y,
0,
scale_factor
)
LG.draw(
spr,
spr_x,
spr_y,
0,
scale_factor
)
LG.setShader()
LG.setColor(1, 1, 1, 1)
SHARED_SHADERS.reveal_shader:ship(“mask_canvas”, level_up_canvas)
LG.setShader(SHARED_SHADERS.reveal_shader)
LG.draw(
title,
cw / 2 – (title:getWidth() / 2 * scale_factor),
ch * .55 – (title:getHeight() / 2 * scale_factor),
0,
scale_factor
)
LG.setShader()
LG.setCanvas()
draw_title()
finish
},
{ –wait
animation_duration = 0.25,
replace = wait_update,
draw = operate ()
SCREEN_MAIN_GAME.draw()
draw_title()
finish
},
{ –animate in playing cards
animation_duration = 1,
replace = operate ()
animation_percentage = get_animation_percentage()
native card_rot_percentage = UTIL.ease_out_circ(animation_percentage)
for i = 1, card_amount do
playing cards[i].y = card_bottom_y – card_heights[i] * UTIL.ease_out_circ(animation_percentage)
if i == selected_card_index then
playing cards[i].y = playing cards[i].y – card_selection_height
finish
playing cards[i].rot_x = card_rot_percentage * card_rotations[i]
finish
if animation_percentage == 1 then
state = state + 1
time_start = LT.getTime()
finish
finish,
draw = operate ()
SCREEN_MAIN_GAME.draw()
draw_title()
draw_cards()
finish
},
{ –wait
animation_duration = 0.1,
replace = wait_update,
draw = operate ()
SCREEN_MAIN_GAME.draw()
draw_title()
draw_cards()
finish
},
{ –flip playing cards
animation_duration = 1,
replace = operate ()
animation_percentage = get_animation_percentage()
native card_rot_percentage = UTIL.ease_in_quint(animation_percentage)
for i = 1, card_amount do
playing cards[i].rot_z = -math.pi + card_rot_percentage * math.pi * 2
finish
if animation_percentage == 1 then
state = state + 1
time_start = LT.getTime()
finish
finish,
draw = operate ()
SCREEN_MAIN_GAME.draw()
draw_title()
draw_cards()
finish
},
{ –wait for enter
animation_duration = 1,
replace = operate ()
user_input_blocked = false
–next state is being set by consumer enter
for i = 1, #playing cards do
playing cards[i].y = card_bottom_y – card_heights[i] * UTIL.ease_out_circ(animation_percentage)
if i == selected_card_index then
playing cards[i].y = playing cards[i].y – card_selection_height
finish
finish
finish,
draw = operate ()
SCREEN_MAIN_GAME.draw()
draw_title()
draw_cards()
finish
},
{ –animate out playing cards
animation_duration = 1,
replace = operate ()
animation_percentage = get_animation_percentage()
for i = 1, card_amount do
if i ~= selected_card_index then
playing cards[i].y = card_bottom_y – card_heights[i] * (1 – UTIL.ease_out_circ(animation_percentage))
finish
–cards[i].rot_z = animation_percentage
finish
if animation_percentage == 1 then
state = state + 1
time_start = LT.getTime()
finish
finish,
draw = operate ()
SCREEN_MAIN_GAME.draw()
draw_title()
draw_cards()
finish
},
{ –fade out card spotlight
animation_duration = .3,
replace = wait_update,
draw = operate ()
SCREEN_MAIN_GAME.draw()
draw_title()
playing cards[selected_card_index]:draw(true, 1 – animation_percentage)
finish
},
{ –burn up remaining card
animation_duration = 2,
replace = wait_update,
draw = operate ()
SCREEN_MAIN_GAME.draw()
draw_title()
dissolve_shader:ship(“time”, UTIL.ease_in_quint(animation_percentage))
LG.setShader(dissolve_shader)
–TODO: optimally, I might spawn just a few embers floating away whereas the cardboard burns up
playing cards[selected_card_index]:draw(false)
LG.setShader()
finish
},
{ –wipe away blood stains
animation_duration = 1.5,
replace = operate ()
animation_percentage = get_animation_percentage()
if animation_percentage == 1 then
state = 1
UTIL.change_screen(SCREEN_MAIN_GAME)
finish
finish,
draw = operate ()
SCREEN_MAIN_GAME.draw()
SHARED_SHADERS.wipeaway_shader:ship(“animation_percentage”, animation_percentage)
LG.setShader(SHARED_SHADERS.wipeaway_shader)
draw_title()
LG.setShader()
finish
},
}
All the pieces I needed in that display screen is there, however but once more, I really feel the discrepancy between my imaginative and prescient and what I can obtain. Want to review extra shaders, want to review extra maths.
I will get there some day.