1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
|
/*
* 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 "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);
}
}
|