summaryrefslogtreecommitdiff
path: root/src/credits.c
diff options
context:
space:
mode:
authorVito Caputo <vcaputo@pengaru.com>2018-04-15 14:57:17 -0700
committerVito Caputo <vcaputo@pengaru.com>2018-04-15 14:57:17 -0700
commit1d1ce1b2df4a5f97a1c34a90337d0c3732f7959e (patch)
treebe3149f96a1546e1806756488a56cecc749b35a8 /src/credits.c
*: initial commit of whale compo
This is my contribution to our Hungrycat production blender 2018 entry, assets to follow.
Diffstat (limited to 'src/credits.c')
-rw-r--r--src/credits.c120
1 files changed, 120 insertions, 0 deletions
diff --git a/src/credits.c b/src/credits.c
new file mode 100644
index 0000000..c171d84
--- /dev/null
+++ b/src/credits.c
@@ -0,0 +1,120 @@
+/*
+ * Copyright (C) 2018 Vito Caputo - <vcaputo@pengaru.com>
+ *
+ * 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 <http://www.gnu.org/licenses/>.
+ */
+
+#include <assert.h>
+#include <SDL.h>
+#include <SDL_mixer.h>
+#include <math.h>
+
+#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);
+}
© All Rights Reserved