/* * Copyright (C) 2018 Vito Caputo - * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU General Public License version 3 as published * by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #include #include #include #include #include "aabb.h" #include "macros.h" #include "whale.h" #include "stage.h" #include "svg-node.h" /* the opening credits */ void whale_credits_event(whale_t *whale, SDL_Event *ev) { /* no events handled in credits, their brief */ } typedef enum credits_fsm_t { CREDITS_FSM_FADEOUT, CREDITS_FSM_FADEIN, CREDITS_FSM_PLANETS_FADEOUT, CREDITS_FSM_CREDITS_FADEOUT, } credits_fsm_t; void whale_credits_update(whale_t *whale) { static stage_node_t *bobby, *crater, *planets, *credits; static unsigned initialized; static credits_fsm_t state; Uint32 now = whale_ticks(whale, WHALE_TICKS_TIMER); stage_t *stage = whale_get_stage(whale); if (!initialized) { whale_ticks_reset(whale, WHALE_TICKS_TIMER); /* get ticks approximately aligned with credits start */ bobby = stage_node_lookup_name(stage, "bobby"); fatal_if(!bobby, "Unable to lookup whale node"); crater = stage_node_lookup_name(stage, "crater"); fatal_if(!crater, "Unable to lookup crater node"); planets = stage_node_lookup_name(stage, "planets"); fatal_if(!crater, "Unable to lookup planets node"); credits = svg_node_new_file(stage, "credits", "assets/credits.svg", 0, (aabb_t){{-.8f, -.8f}, {.8f, .8f}}); fatal_if(!credits, "Unable to load credits svg"); now = whale_ticks(whale, WHALE_TICKS_TIMER); initialized = 1; } switch (state) { case CREDITS_FSM_FADEOUT: if (now < 2000) { float t = 1.0f - ((float)now) * (1.0f / 2000.0f); stage_node_set_alpha(stage, bobby, t); stage_node_set_alpha(stage, crater, t); } else { stage_node_free(stage, bobby); stage_node_free(stage, crater); stage_node_set_active(stage, credits); state++; } break; case CREDITS_FSM_FADEIN: if (now < 4000) { stage_node_set_alpha(stage, planets, 1.0f - ((float)(now - 2000)) * (1.0f / 15000.0f)); stage_node_set_alpha(stage, credits, ((float)(now - 2000)) * (1.0f / 2000.0f)); } else { stage_node_set_alpha(stage, credits, 1.0f); state++; } break; case CREDITS_FSM_PLANETS_FADEOUT: if (now < 17000) { stage_node_set_alpha(stage, planets, 1.0f - ((float)(now - 2000)) * (1.0f / 15000.0f)); } else { stage_node_free(stage, planets); state++; } break; case CREDITS_FSM_CREDITS_FADEOUT: if (now < 20000) { stage_node_set_alpha(stage, credits, 1.0f - ((float)(now - 17000)) * (1.0f / 3000.0f)); } else { stage_node_free(stage, credits); exit(0); } break; default: assert(0); } if (!Mix_PlayingMusic() || now > 20000) exit(0); }