/* * 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 "filler-node.h" #include "macros.h" #include "whale.h" #include "stage.h" #include "svg-node.h" /* the opening intro */ void whale_intro_event(whale_t *whale, SDL_Event *ev) { switch (ev->type) { case SDL_KEYDOWN: case SDL_MOUSEBUTTONDOWN: /* skip intro sequence */ whale_set_context(whale, WHALE_CONTEXT_GAME); break; default: break; } } typedef enum intro_fsm_t { INTRO_FSM_BLACK, INTRO_FSM_WHALE, INTRO_FSM_ASTRO, INTRO_FSM_CRATER, INTRO_FSM_LEAVE, } intro_fsm_t; void whale_intro_update(whale_t *whale) { static stage_node_t *bobby, *astro, *crater; static unsigned initialized; static intro_fsm_t state; Uint32 now = whale_ticks(whale, WHALE_TICKS_TIMER); stage_t *stage = whale_get_stage(whale); if (!initialized) { whale_set_music(whale, "assets/music.ogg", 0); whale_ticks_reset(whale, WHALE_TICKS_MUSIC); /* get ticks approximately aligned with music start */ whale_ticks_reset(whale, WHALE_TICKS_TIMER); /* TODO: there should be a "reset all" or something */ bobby = svg_node_new_file(stage, "bobby", "assets/whale.svg", 2, (aabb_t){{-1.f, -.2f},{-.4f, .2f}}); fatal_if(!bobby, "Unable to load whale svg"); astro = svg_node_new_file(stage, "astro", "assets/astro.svg", 2, (aabb_t){{-.3f, -.2f},{.3f, .2f}}); fatal_if(!astro, "Unable to load astro svg"); crater = svg_node_new_file(stage, "crater", "assets/crater.svg", 3, (aabb_t){{.4f, -.2f},{1.f, .2f}}); fatal_if(!crater, "Unable to load crater svg"); stage_node_set_locked(stage, bobby); stage_node_set_locked(stage, crater); stage_node_set_active(stage, bobby); stage_node_set_active(stage, astro); stage_node_set_active(stage, crater); now = whale_ticks(whale, WHALE_TICKS_TIMER); initialized = 1; } switch (state) { case INTRO_FSM_BLACK: if (now > 500) /* brief delay for things to settle for the viewer */ state++; break; case INTRO_FSM_WHALE: if (now < 2000) { stage_node_set_alpha(stage, bobby, ((float)(now - 500)) * (1.0f / 1500.0f)); } else { stage_node_set_alpha(stage, bobby, 1.0f); state++; } break; case INTRO_FSM_ASTRO: if (now < 3500) { stage_node_set_alpha(stage, astro, ((float)(now - 2000)) * (1.0f / 1500.0f)); } else { stage_node_set_alpha(stage, astro, 1.0f); state++; } break; case INTRO_FSM_CRATER: if (now < 5000) { stage_node_set_alpha(stage, crater, ((float)(now - 3500)) * (1.0f / 1500.0f)); } else { stage_node_set_alpha(stage, crater, 1.0f); state++; } break; case INTRO_FSM_LEAVE: whale_set_context(whale, WHALE_CONTEXT_GAME); break; default: assert(0); } }