~ubuntu-branches/ubuntu/trusty/tomatoes/trusty

« back to all changes in this revision

Viewing changes to .pc/06_SDLK_KP_ENTER.diff/src/select_special.cpp

  • Committer: Package Import Robot
  • Author(s): Bart Martens
  • Date: 2012-05-23 05:13:05 UTC
  • Revision ID: package-import@ubuntu.com-20120523051305-21nvzupxhtuovr5y
Tags: 1.55-5
* Switch to dpkg-source 3.0 (quilt) format, debhelper 9, no cdbs.
* debian/README.Debian-source: Moved into debian/copyright.
* debian/tomatoes.6, debian/manpages: Added.  Closes: #626934.
* debian/tomatoes.desktop: Updated.  Closes: #626933.
* debian/patches/flags.diff: Added.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*************************************************************************
 
2
 
 
3
                         "I Have No Tomatoes"
 
4
                  Copyright (c) 2004, Mika Halttunen
 
5
 
 
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.
 
9
 
 
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:
 
13
 
 
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.
 
18
 
 
19
    2. Altered source versions must be plainly marked as such, and must
 
20
    not be misrepresented as being the original software.
 
21
 
 
22
    3. This notice may not be removed or altered from any source
 
23
    distribution.
 
24
 
 
25
 
 
26
 Mika Halttunen <lsoft@mbnet.fi>
 
27
 
 
28
*************************************************************************/
 
29
 
 
30
#include <stdlib.h>
 
31
#include "SDL.h"
 
32
#include "SDL_opengl.h"
 
33
#include "SDL_image.h"
 
34
#include "texture.h"
 
35
#include "init.h"
 
36
#include "font.h"
 
37
#include "select_special.h"
 
38
#include "special_power.h"
 
39
#include "player.h"
 
40
#include "game.h"
 
41
#include "mymath.h"
 
42
#include "comments.h"
 
43
#include "soundmusic.h"
 
44
#include "levels.h"
 
45
#include "helpers.h"
 
46
 
 
47
 
 
48
// Special selection icons
 
49
GLuint special_icons[3];
 
50
 
 
51
// Icon background texture
 
52
GLuint icon_bg;
 
53
 
 
54
// This structure holds the icon menu data
 
55
ICON_MENU icon_menu;
 
56
 
 
57
// This holds the time spent in the menu
 
58
static Uint32 menu_time;
 
59
 
 
60
// This holds the number of burning enemies when entered the menu
 
61
static int num_burning;
 
62
 
 
63
// Number of enemies when entered the menu
 
64
static int num_enemies_menu;
 
65
 
 
66
// From bonus.cpp
 
67
extern int killed_5_diamonds;
 
68
 
 
69
 
 
70
// Icon names
 
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" };
 
72
 
 
73
// Icon colors
 
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 };
 
75
 
 
76
 
 
77
 
 
78
// Draw the special selection icons
 
79
void draw_special_selection() {
 
80
        if(!icon_menu.visible && icon_menu.pos <= 0.05f)
 
81
                return;
 
82
 
 
83
        // Set smaller fonts
 
84
        set_font_scale(0.2f, 0.2f);
 
85
 
 
86
        // Translate to the correct position
 
87
        glPushMatrix();
 
88
        glLoadIdentity();
 
89
        glTranslatef(-NUM_ICONS * 0.5f, 3.45f - 1.1f * icon_menu.pos, -8.5f);   // 2.35f
 
90
        glTranslatef(0.5f, 0.5f, 0);
 
91
 
 
92
        // Texture coordinates
 
93
        float texx = 0.0f, texy = 0.0f;
 
94
 
 
95
        // Draw the icons
 
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)
 
100
                        disabled = true;
 
101
                if(f == GREEN_POWER_POTATOMAN && potatoman.alive)
 
102
                        disabled = true;
 
103
                if(f == RED_POWER_WILDFIRE && (!num_enemies_menu || num_burning == 5))
 
104
                        disabled = true;
 
105
                if(f == BLUE_POWER_TURN && !num_enemies_menu)
 
106
                        disabled = true;
 
107
                if(f == BLUE_POWER_LIGHTNING && !num_enemies_menu)
 
108
                        disabled = true;
 
109
                if(using_special_power && which_special_power == BLUE_POWER_LIGHTNING && f == BLUE_POWER_LIGHTNING)
 
110
                        disabled = true;
 
111
                if(using_special_power && which_special_power == BLUE_POWER_LIGHTNING && f == BLUE_POWER_TURN)
 
112
                        disabled = true;
 
113
 
 
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);
 
120
                else
 
121
                        glColor4f(.75f,.75f,1,a);
 
122
 
 
123
                if(disabled)
 
124
                        glColor4f(.5f,.5f,.5f,a);
 
125
 
 
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);
 
133
                glEnd();
 
134
 
 
135
                // Set up the texture coordinates for the icon
 
136
                switch(f) {
 
137
                        default:
 
138
                        case 0:         // Trap
 
139
                                texx = 0; texy = 0.5f; break;
 
140
                        case 1:         // Wild fire
 
141
                                texx = 0.5f; texy = 0.5f; break;
 
142
                        case 2:         // Napalm
 
143
                                texx = 0; texy = 0; break;
 
144
                        case 3:         // Wisp
 
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;
 
150
                        case 6:         // Teleport
 
151
                                texx = 0; texy = 0; break;
 
152
                        case 7:         // Turn
 
153
                                texx = 0.5f; texy = 0; break;
 
154
                        case 8:         // Lightning
 
155
                                texx = 0; texy = 0; break;
 
156
                }
 
157
                float t_add = 0.5f;
 
158
                if(f == 8)
 
159
                        t_add = 1.0f;
 
160
 
 
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]);
 
166
                else
 
167
                        BIND_TEXTURE(special_icons[2]);
 
168
 
 
169
 
 
170
                float col = 1.0f - 0.5f * (1.0f - icon_menu.anim[f]);
 
171
                //glColor4f(1,1,1,col);
 
172
 
 
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);
 
179
                else
 
180
                        glColor4f(c,c,1,col);
 
181
 
 
182
                if(disabled)
 
183
                        glColor3f(.5f,.5f,.5f);
 
184
 
 
185
 
 
186
                // Draw the icon
 
187
                float size = 0.45f - 0.15f * (1.0f-icon_menu.anim[f]);
 
188
                if(disabled)
 
189
                        size = 0.3f;
 
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);
 
195
                glEnd();
 
196
 
 
197
 
 
198
                // Draw the amount of the corresponding bonuses
 
199
                glColor3f(1,1,0.7f);
 
200
                char str[5] = "";
 
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);
 
203
 
 
204
 
 
205
                // Translate right
 
206
                glTranslatef(1.0f, 0, 0);
 
207
        }
 
208
 
 
209
        glPopMatrix();
 
210
 
 
211
        // Restore the fonts
 
212
        set_font_scale(1,1);
 
213
 
 
214
}
 
215
 
 
216
 
 
217
// Handle the special selection menu
 
218
void do_special_selection() {
 
219
        int who = icon_menu.who - 1;
 
220
 
 
221
        if(icon_menu.wait > 0)
 
222
                icon_menu.wait--;
 
223
 
 
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;
 
229
                return;
 
230
        }
 
231
 
 
232
        if(!icon_menu.visible || level_pause)
 
233
                return;
 
234
 
 
235
 
 
236
 
 
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;
 
241
 
 
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;
 
245
 
 
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;
 
253
 
 
254
                        add_comment(icon_colors[icon_menu.selected], (char*)icon_names[icon_menu.selected]);
 
255
 
 
256
                        // Play the sound
 
257
                        play_sound(SND_MENU1, false);
 
258
                }
 
259
        }
 
260
        else
 
261
                icon_menu.lkey_down = false;
 
262
 
 
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;
 
269
 
 
270
                        add_comment(icon_colors[icon_menu.selected], (char*)icon_names[icon_menu.selected]);
 
271
 
 
272
                        // Play the sound
 
273
                        play_sound(SND_MENU1, false);
 
274
                }
 
275
        }
 
276
        else
 
277
                icon_menu.rkey_down = false;
 
278
 
 
279
 
 
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;
 
283
 
 
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)
 
286
                        disabled = true;
 
287
                if(power == GREEN_POWER_POTATOMAN && potatoman.alive)
 
288
                        disabled = true;
 
289
                if(power == RED_POWER_WILDFIRE && (!num_enemies_menu || num_burning == 5))
 
290
                        disabled = true;
 
291
                if(power == BLUE_POWER_TURN && !num_enemies_menu)
 
292
                        disabled = true;
 
293
                if(power == BLUE_POWER_LIGHTNING && !num_enemies_menu)
 
294
                        disabled = true;
 
295
                if(using_special_power && which_special_power == BLUE_POWER_LIGHTNING && power == BLUE_POWER_LIGHTNING)
 
296
                        disabled = true;
 
297
                if(using_special_power && which_special_power == BLUE_POWER_LIGHTNING && power == BLUE_POWER_TURN)
 
298
                        disabled = true;
 
299
 
 
300
                if(disabled || (icon_menu.who == 1 && p1.dying))
 
301
                        return;
 
302
                if(disabled || (icon_menu.who == 2 && p2.dying))
 
303
                        return;
 
304
 
 
305
                // Use up the special power
 
306
                invoke_special_power(icon_menu.who, power);
 
307
 
 
308
                add_comment(COL_YELLOW, "%s chosen.", (char*)icon_names[power]);
 
309
 
 
310
                // Close the menu
 
311
                icon_menu.visible = false;
 
312
                icon_menu.wait = 15;
 
313
 
 
314
                // Restore the timing
 
315
                if(!killed_5_diamonds) {
 
316
                        Uint32 diff = SDL_GetTicks() - menu_time;
 
317
                        level_time += diff;
 
318
                }
 
319
 
 
320
                // Play the sound
 
321
                play_sound(SND_MENU2, false);
 
322
                return;
 
323
        }
 
324
 
 
325
 
 
326
        // Cancel the menu
 
327
        if(key[config.key_special[who]] && icon_menu.wait == 0) {
 
328
                icon_menu.visible = false;
 
329
                icon_menu.wait = 15;
 
330
 
 
331
                // Restore the timing
 
332
                if(!killed_5_diamonds) {
 
333
                        Uint32 diff = SDL_GetTicks() - menu_time;
 
334
                        level_time += diff;
 
335
                }
 
336
 
 
337
                // Play the sound
 
338
                play_sound(SND_MENU2, false);
 
339
        }
 
340
 
 
341
}
 
342
 
 
343
 
 
344
 
 
345
// Load the special selection icons
 
346
void load_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);
 
351
}
 
352
 
 
353
 
 
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;
 
358
                icon_menu.wait = 15;
 
359
                icon_menu.who = who;
 
360
                icon_menu.is_on_block = standing_on_block;
 
361
 
 
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;
 
367
                                        break;
 
368
                                }
 
369
                        }
 
370
                }
 
371
 
 
372
                // Count the burning enemies
 
373
                num_burning = 0;
 
374
                list<ENEMY>::iterator e;
 
375
                for(e = enemylist.begin(); e != enemylist.end(); ++e)
 
376
                        if((*e).burning)
 
377
                                num_burning++;
 
378
 
 
379
                num_enemies_menu = enemylist.size();
 
380
 
 
381
                // Save the level timing
 
382
                menu_time = SDL_GetTicks();
 
383
        }
 
384
}
 
385
 
 
386
 
 
387
// Initialize the special selection icons
 
388
void init_special_selection() {
 
389
        // Select the first enabled icon
 
390
        icon_menu.selected = 0;
 
391
        int f;
 
392
        for(f=0; f<NUM_ICONS; f++) {
 
393
                if(icon_menu.count[f]) {
 
394
                        icon_menu.selected = f;
 
395
                        break;
 
396
                }
 
397
        }
 
398
 
 
399
        for(f=0; f<NUM_ICONS; f++)
 
400
                icon_menu.anim[f] = 0.0f;
 
401
 
 
402
        icon_menu.anim[icon_menu.selected] = 1.0f;
 
403
 
 
404
        icon_menu.visible = false;
 
405
        icon_menu.lkey_down = icon_menu.rkey_down = false;
 
406
        icon_menu.wait = 0;
 
407
        icon_menu.pos = 0;
 
408
        icon_menu.who = 0;
 
409
        icon_menu.is_on_block = false;
 
410
}
 
411