1
/*************************************************************************
4
Copyright (c) 2004, Mika Halttunen
6
This software is provided 'as-is', without any express or implied
7
warranty. In no event will the authors be held liable for any damages
8
arising from the use of this software.
10
Permission is granted to anyone to use this software for any purpose,
11
including commercial applications, and to alter it and redistribute
12
it freely, subject to the following restrictions:
14
1. The origin of this software must not be misrepresented; you must
15
not claim that you wrote the original software. If you use this
16
software in a product, an acknowledgment in the product documentation
17
would be appreciated but is not required.
19
2. Altered source versions must be plainly marked as such, and must
20
not be misrepresented as being the original software.
22
3. This notice may not be removed or altered from any source
26
Mika Halttunen <lsoft@mbnet.fi>
28
*************************************************************************/
32
#include "SDL_opengl.h"
33
#include "SDL_image.h"
37
#include "select_special.h"
38
#include "special_power.h"
43
#include "soundmusic.h"
48
// Special selection icons
49
GLuint special_icons[3];
51
// Icon background texture
54
// This structure holds the icon menu data
57
// This holds the time spent in the menu
58
static Uint32 menu_time;
60
// This holds the number of burning enemies when entered the menu
61
static int num_burning;
63
// Number of enemies when entered the menu
64
static int num_enemies_menu;
67
extern int killed_5_diamonds;
71
const char icon_names[NUM_ICONS][128] = { "Trap", "Wild Fire", "Napalm Strike", "Will O' The Wisp", "Potato Man", "Flower Power", "Teleport", "Turn", "Lightning Bolt" };
74
const int icon_colors[NUM_ICONS] = { COL_RED, COL_RED, COL_RED, COL_GREEN, COL_GREEN, COL_GREEN, COL_BLUE, COL_BLUE, COL_BLUE };
78
// Draw the special selection icons
79
void draw_special_selection() {
80
if(!icon_menu.visible && icon_menu.pos <= 0.05f)
84
set_font_scale(0.2f, 0.2f);
86
// Translate to the correct position
89
glTranslatef(-NUM_ICONS * 0.5f, 3.45f - 1.1f * icon_menu.pos, -8.5f); // 2.35f
90
glTranslatef(0.5f, 0.5f, 0);
92
// Texture coordinates
93
float texx = 0.0f, texy = 0.0f;
96
for(int f=0; f<NUM_ICONS; f++) {
97
// Determine if the icon is disabled
98
bool disabled = (icon_menu.count[f] == 0 || (icon_menu.is_on_block && (f == RED_POWER_TRAP || f == GREEN_POWER_FLOWERPOWER)));
99
if(f == GREEN_POWER_WISP && wisp.alive)
101
if(f == GREEN_POWER_POTATOMAN && potatoman.alive)
103
if(f == RED_POWER_WILDFIRE && (!num_enemies_menu || num_burning == 5))
105
if(f == BLUE_POWER_TURN && !num_enemies_menu)
107
if(f == BLUE_POWER_LIGHTNING && !num_enemies_menu)
109
if(using_special_power && which_special_power == BLUE_POWER_LIGHTNING && f == BLUE_POWER_LIGHTNING)
111
if(using_special_power && which_special_power == BLUE_POWER_LIGHTNING && f == BLUE_POWER_TURN)
114
// Select the correct color
115
float a = (f == icon_menu.selected) ? 0.8f : 0.6f;
116
if(f == 0 || f == 1 || f == 2)
117
glColor4f(1,.75f,.75f,a);
118
else if(f == 3 || f == 4 || f == 5)
119
glColor4f(.75f,1,.75f,a);
121
glColor4f(.75f,.75f,1,a);
124
glColor4f(.5f,.5f,.5f,a);
126
// Draw the background
127
BIND_TEXTURE(icon_bg);
128
glBegin(GL_TRIANGLE_STRIP);
129
glTexCoord2f(1,1); glVertex2f( 0.5f, 0.5f);
130
glTexCoord2f(0,1); glVertex2f(-0.5f, 0.5f);
131
glTexCoord2f(1,0); glVertex2f( 0.5f, -0.5f);
132
glTexCoord2f(0,0); glVertex2f(-0.5f, -0.5f);
135
// Set up the texture coordinates for the icon
139
texx = 0; texy = 0.5f; break;
141
texx = 0.5f; texy = 0.5f; break;
143
texx = 0; texy = 0; break;
145
texx = 0.5f; texy = 0; break;
146
case 4: // Potato man
147
texx = 0; texy = 0.5f; break;
148
case 5: // Flower power
149
texx = 0.5f; texy = 0.5f; break;
151
texx = 0; texy = 0; break;
153
texx = 0.5f; texy = 0; break;
155
texx = 0; texy = 0; break;
161
// Bind the correct texture
162
if(f == 0 || f == 1 || f == 2 || f == 3)
163
BIND_TEXTURE(special_icons[0]);
164
else if(f == 4 || f == 5 || f == 6 || f == 7)
165
BIND_TEXTURE(special_icons[1]);
167
BIND_TEXTURE(special_icons[2]);
170
float col = 1.0f - 0.5f * (1.0f - icon_menu.anim[f]);
171
//glColor4f(1,1,1,col);
173
// Select the correct color
174
float c = 0.6f + 0.4f * icon_menu.anim[f];
175
if(f == 0 || f == 1 || f == 2)
176
glColor4f(1,c,c,col);
177
else if(f == 3 || f == 4 || f == 5)
178
glColor4f(c,1,c,col);
180
glColor4f(c,c,1,col);
183
glColor3f(.5f,.5f,.5f);
187
float size = 0.45f - 0.15f * (1.0f-icon_menu.anim[f]);
190
glBegin(GL_TRIANGLE_STRIP);
191
glTexCoord2f(texx + t_add, texy + t_add); glVertex2f( size, size);
192
glTexCoord2f(texx, texy + t_add); glVertex2f(-size, size);
193
glTexCoord2f(texx + t_add, texy); glVertex2f( size, -size);
194
glTexCoord2f(texx, texy); glVertex2f(-size, -size);
198
// Draw the amount of the corresponding bonuses
201
sprintf(str, "%2d", icon_menu.count[f]);
202
glprint_num(-NUM_ICONS*0.5f + 0.55f + f, 3.55f - 1.1f*icon_menu.pos, -8.5f, str);
206
glTranslatef(1.0f, 0, 0);
217
// Handle the special selection menu
218
void do_special_selection() {
219
int who = icon_menu.who - 1;
221
if(icon_menu.wait > 0)
224
// Scroll into the screen
225
if(icon_menu.pos < 1.0f && icon_menu.visible)
226
icon_menu.pos += 0.05f;
227
else if(icon_menu.pos > 0 && !icon_menu.visible) {
228
icon_menu.pos -= 0.05f;
232
if(!icon_menu.visible || level_pause)
237
// Handle the animation
238
int i = icon_menu.selected;
239
if(icon_menu.anim[i] < 1.0f)
240
icon_menu.anim[i] += 0.1f;
242
for(int f=0; f<NUM_ICONS; f++)
243
if(i != f && icon_menu.anim[f] > 0.0f)
244
icon_menu.anim[f] -= 0.1f;
246
// Handle the keyboard input
247
if(key[config.key_left[who]]) {
248
if(icon_menu.lkey_down == false) {
249
icon_menu.lkey_down = true;
250
icon_menu.selected--;
251
if(icon_menu.selected < 0)
252
icon_menu.selected = NUM_ICONS-1;
254
add_comment(icon_colors[icon_menu.selected], (char*)icon_names[icon_menu.selected]);
257
play_sound(SND_MENU1, false);
261
icon_menu.lkey_down = false;
263
if(key[config.key_right[who]]) {
264
if(icon_menu.rkey_down == false) {
265
icon_menu.rkey_down = true;
266
icon_menu.selected++;
267
if(icon_menu.selected > NUM_ICONS-1)
268
icon_menu.selected = 0;
270
add_comment(icon_colors[icon_menu.selected], (char*)icon_names[icon_menu.selected]);
273
play_sound(SND_MENU1, false);
277
icon_menu.rkey_down = false;
280
// Invoke a special power
281
if((key[config.key_shoot[who]] || key[SDLK_RETURN]) && icon_menu.wait == 0) {
282
int power = icon_menu.selected;
284
bool disabled = (icon_menu.count[power] == 0 || (icon_menu.is_on_block && (power == RED_POWER_TRAP || power == GREEN_POWER_FLOWERPOWER)));
285
if(power == GREEN_POWER_WISP && wisp.alive)
287
if(power == GREEN_POWER_POTATOMAN && potatoman.alive)
289
if(power == RED_POWER_WILDFIRE && (!num_enemies_menu || num_burning == 5))
291
if(power == BLUE_POWER_TURN && !num_enemies_menu)
293
if(power == BLUE_POWER_LIGHTNING && !num_enemies_menu)
295
if(using_special_power && which_special_power == BLUE_POWER_LIGHTNING && power == BLUE_POWER_LIGHTNING)
297
if(using_special_power && which_special_power == BLUE_POWER_LIGHTNING && power == BLUE_POWER_TURN)
300
if(disabled || (icon_menu.who == 1 && p1.dying))
302
if(disabled || (icon_menu.who == 2 && p2.dying))
305
// Use up the special power
306
invoke_special_power(icon_menu.who, power);
308
add_comment(COL_YELLOW, "%s chosen.", (char*)icon_names[power]);
311
icon_menu.visible = false;
314
// Restore the timing
315
if(!killed_5_diamonds) {
316
Uint32 diff = SDL_GetTicks() - menu_time;
321
play_sound(SND_MENU2, false);
327
if(key[config.key_special[who]] && icon_menu.wait == 0) {
328
icon_menu.visible = false;
331
// Restore the timing
332
if(!killed_5_diamonds) {
333
Uint32 diff = SDL_GetTicks() - menu_time;
338
play_sound(SND_MENU2, false);
345
// Load the special selection icons
347
special_icons[0] = load_png("icons1.png", true, false, false);
348
special_icons[1] = load_png("icons2.png", true, false, false);
349
special_icons[2] = load_png("icons3.png", true, false, false);
350
icon_bg = load_png("iconbg.png", true, false, false);
354
// Open the icon menu
355
void open_icon_menu(int who, bool standing_on_block) {
356
if(icon_menu.wait == 0) {
357
icon_menu.visible = true;
360
icon_menu.is_on_block = standing_on_block;
362
// Choose the first enabled icon
363
if(!icon_menu.count[icon_menu.selected]) {
364
for(int f=0; f<NUM_ICONS; f++) {
365
if(icon_menu.count[f]) {
366
icon_menu.selected = f;
372
// Count the burning enemies
374
list<ENEMY>::iterator e;
375
for(e = enemylist.begin(); e != enemylist.end(); ++e)
379
num_enemies_menu = enemylist.size();
381
// Save the level timing
382
menu_time = SDL_GetTicks();
387
// Initialize the special selection icons
388
void init_special_selection() {
389
// Select the first enabled icon
390
icon_menu.selected = 0;
392
for(f=0; f<NUM_ICONS; f++) {
393
if(icon_menu.count[f]) {
394
icon_menu.selected = f;
399
for(f=0; f<NUM_ICONS; f++)
400
icon_menu.anim[f] = 0.0f;
402
icon_menu.anim[icon_menu.selected] = 1.0f;
404
icon_menu.visible = false;
405
icon_menu.lkey_down = icon_menu.rkey_down = false;
409
icon_menu.is_on_block = false;