-
Notifications
You must be signed in to change notification settings - Fork 0
/
echo_ns.cpp
197 lines (186 loc) · 4.72 KB
/
echo_ns.cpp
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
// echo_ns.cpp
/*
This file is part of L-Echo.
L-Echo is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
L-Echo 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 L-Echo. If not, see <http://www.gnu.org/licenses/>.
*/
#include <cstdlib>
#include <iostream>
#include <set>
#include "echo_platform.h"
#include "echo_error.h"
#include "echo_character.h"
#include "echo_math.h"
#include "echo_ns.h"
#include "echo_gfx.h"
#include "grid.h"
#include "hole.h"
/// The minimum opacity of the "stand-in mannequin"
#define NULL_CHAR_OPACITY_MIN 0.25f
/// Holds important stuff
namespace echo_ns
{
/** Opacity of the "stand-in" mannequin, or the mannequin that marks
* where the character initially lands.
*/
float null_char_opacity = NULL_CHAR_OPACITY_MIN;
/// Are we increasing the character's opacity or decreasing?
int opacity_incr = true;
/// The world's rotation angle. _VERY_ important variable
vector3f angle;
/// The main character; the protagonist, the one the player controls
echo_char* main_char = NULL;
/// The current stage
stage* current_stage = NULL;
/// Has the game started yet?
int started = false;
/// Deallocate everything: stage and character
void deallocate()
{
if(current_stage != NULL)
delete current_stage;
if(main_char != NULL)
delete main_char;
}
/// Initialize everything with the stage (which will be delete if deallocate is called)
void init(stage* st)
{
if(current_stage != NULL)
delete current_stage;
current_stage = st;
if(st != NULL)
{
main_char = new echo_char(st->get_start());
}
else
main_char = NULL;
}
/// Get the ball rolling!
void start()
{
started = true;
}
/// Get the lowest level in the current stage
float get_lowest_level()
{
return(current_stage->get_lowest_level());
}
/// Draws the stage and the character, or a "stand-in" mannequin
void draw()
{
if(current_stage != NULL)
{
current_stage->draw(angle);
if(started)
{
main_char->step();
}
/// Need a stand-in mannequin
else
{
/// Get the starting grid's info
grid* g = current_stage->get_start();
if(g)
{
grid_info_t* info = g->get_info(echo_ns::angle);
if(info)
{
gfx_push_matrix();
gfx_translatef(info->pos->x, info->pos->y, info->pos->z);
#ifndef ECHO_NDS
gfx_outline_start();
draw_character(NULL);
gfx_outline_mid();
#endif
gfx_color3f(null_char_opacity, null_char_opacity, null_char_opacity);
draw_character(NULL);
#ifndef ECHO_NDS
gfx_outline_end();
#endif
gfx_pop_matrix();
/// Change the opacity
/// If we're increasing the opacity
if(opacity_incr)
{
/// Increase the opacity slightly
null_char_opacity += 0.05f;
/// If the opacity is greater than (or equal to) 1
if(null_char_opacity >= 1)
{
/// Change it back to one
null_char_opacity = 1;
/// Start decreasing the opacity
opacity_incr = false;
}
}
/// Else, we're decreasing...
else
{
/// Decrease the opacity slightly
null_char_opacity -= 0.05f;
/// If the opacity is less than the minimum
if(null_char_opacity <= NULL_CHAR_OPACITY_MIN)
/// Start increasing the opacity
/// (don't need to change to NULL_CHAR_OPACITY_MIN because it's OK to cross the threshold)
opacity_incr = true;
}
}
}
}
}
}
/// Pause or unpause the game
void toggle_pause()
{
if(main_char != NULL)
main_char->toggle_pause();
}
/// Is the game paused?
int is_paused()
{
return(main_char->is_paused());
}
/// How many goals are there on this stage?
int num_goals()
{
return(current_stage->get_num_goals());
}
/// How goals has the many character reached?
int num_goals_reached()
{
return(main_char->num_goals_reached());
}
/// How many goals are left?
int goals_left()
{
return(current_stage->get_num_goals() - num_goals_reached());
}
/// Get the speed of the character (see echo_char#speed)
float get_speed()
{
return(main_char->get_speed());
}
/// Change speed to running if we can
void start_run()
{
main_char->start_run();
}
/// Change speed to walking if we can
void start_step()
{
main_char->start_step();
}
/// Toggle running
void toggle_run()
{
main_char->toggle_run();
}
};