add episode transitions

This commit is contained in:
Lephenixnoir 2021-08-22 00:41:42 +02:00
parent ac7489a172
commit d98158b379
Signed by: Lephenixnoir
GPG Key ID: 1BBA026E13FC0495
2 changed files with 43 additions and 6 deletions

View File

@ -98,6 +98,8 @@ typedef struct game {
float time_dead;
/* Time spent during level transition */
float time_transition;
/* Time spent during episode transition */
float time_episode_transition;
/* Forced rotation speed for level transitions and death rewind */
float forced_player_rota;

View File

@ -17,7 +17,7 @@ typedef enum {
State_Dead,
State_Rewind,
State_Transition,
State_EpisodeCard,
State_EpisodeTransition,
State_Finale,
} state_t;
@ -97,6 +97,12 @@ int main(void)
state_t state = State_Playing;
if(current_level == 0) {
state = State_EpisodeTransition;
game.time_episode_transition = 0;
game.time = -13.0;
}
/* Direction of time (with a factor regulating game speed) */
float const time_direction_forward = 2.7;
float const time_direction_rewind = -40;
@ -136,6 +142,18 @@ int main(void)
state = State_Playing;
}
}
if(state == State_EpisodeTransition) {
time_direction = 1.0;
game.time_episode_transition += (1.0 / 30);
if(game.time_episode_transition >= 1.0) {
game.player_rota = 0;
game.forced_player_rota = 0;
}
if(game.time_episode_transition >= 3.0) {
game.time_episode_transition = 0;
state = State_Playing;
}
}
float dt = (1.0 / 30) * time_direction;
game.time += dt;
@ -161,20 +179,32 @@ int main(void)
// End of level
if(state == State_Playing &&
game.time >= lv->blocks[lv->block_count-1].time + 5) {
bool changed_episode = false;
current_level++;
if(current_level >= episodes[current_episode].level_count) {
current_episode++;
current_level = 0;
changed_episode = true;
}
if(current_episode >= episode_count)
break;
load_level(&game, episodes[current_episode].levels[current_level]);
state = State_Transition;
game.time_transition = 0;
game.forced_player_rota = -game.player_rota / 1.0;
continue;
if(changed_episode) {
state = State_EpisodeTransition;
game.time_episode_transition = 0;
game.forced_player_rota = -game.player_rota / 1.0;
game.time = -13.0;
continue;
}
else {
state = State_Transition;
game.time_transition = 0;
game.forced_player_rota = -game.player_rota / 1.0;
continue;
}
}
// End of rewind
@ -215,7 +245,7 @@ int main(void)
dclear(C_BLACK);
if(game.time < -5.0 && lv->message != NULL) {
if(state == State_Playing && game.time < -5.0 && lv->message) {
int x = DWIDTH/2 + 8 * (strcount(lv->message, '\n') + 1);
/* Split at newlines */
@ -229,6 +259,11 @@ int main(void)
}
}
if(state == State_EpisodeTransition) {
duet_text_opt(DWIDTH/2, DHEIGHT/2, C_WHITE, C_NONE, DTEXT_CENTER,
DTEXT_MIDDLE, episodes[current_episode].name, -1);
}
render_player(PLAYER_X, DHEIGHT/2, game.player_rota);
for(int i = 0; i < game.rect_count; i++)
drectoid(&game.rects[i], C_WHITE);