1 /*
2  * DrawWinRecord.cxx
3  * Daniel Nelson - 11/5/0
4  *
5  * Copyright (C) 2000  Daniel Nelson
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
20  *
21  * Daniel Nelson - aluminumangel.org
22  * 174 W. 18th Ave.
23  * Columbus, OH  43210
24  *
25  * Draws the little win record stars.
26  */
27 
28 #include <GL/glut.h>
29 
30 #include "glext.h"
31 
32 using namespace std;
33 
34 #include "Game.h"
35 #include "Displayer.h"
36 #include "WinRecord.h"
37 
drawWinRecord()38 void Displayer::drawWinRecord (   )
39 {
40   glBindTexture(GL_TEXTURE_2D, mote_textures[MT_FIVE_POINTED_STAR]);
41 
42   int n;
43   if (MetaState::mode & CM_SOLO)
44     n = DC_SOLO_STAR_ID + 1;
45   else
46     n = GC_GAMES_PER_MATCH;
47   while (n--) {
48     Star &star = WinRecord::stars[n];
49 
50     glPushMatrix();
51 
52       switch (WinRecord::record[n]) {
53 
54       // game not yet played
55       case GR_NOT_PLAYED:
56         glColor3f(DC_STAR_UNPLAYED_RED, DC_STAR_UNPLAYED_GREEN,
57          DC_STAR_UNPLAYED_BLUE);
58         glTranslatef(DC_STAR_OFFSET_X + DC_STAR_DISPLACEMENT * n,
59          DC_STAR_OFFSET_Y, DC_EXTERNAL_OFFSET_Z);
60         glScalef(DC_STAR_SIZE_EQUILIBRIUM, -DC_STAR_SIZE_EQUILIBRIUM, 0.0f);
61         glCallList(sparkle_list);
62         break;
63 
64       // game being played
65       case GR_BEING_PLAYED:
66         glColor3f(DC_STAR_UNPLAYED_RED, DC_STAR_UNPLAYED_GREEN,
67          DC_STAR_UNPLAYED_BLUE);
68         glTranslatef(DC_STAR_OFFSET_X + DC_STAR_DISPLACEMENT * n,
69          DC_STAR_OFFSET_Y, DC_EXTERNAL_OFFSET_Z);
70         glRotatef(star.a, 0.0f, 0.0f, 1.0f);
71         glScalef(DC_STAR_SIZE_EQUILIBRIUM, -DC_STAR_SIZE_EQUILIBRIUM, 0.0f);
72         glCallList(sparkle_list);
73         break;
74 
75       // game has been lost
76       case GR_LOST:
77         // star has already faded out
78         if (WinRecord::current_game != n)
79           glColor4f(DC_STAR_UNPLAYED_RED, DC_STAR_UNPLAYED_GREEN,
80            DC_STAR_UNPLAYED_BLUE, DC_STAR_LOST_ALPHA);
81 
82         // star is fading out
83         else if (Game::time_step < DC_CELEBRATION_TIME) {
84           GLfloat fade
85            = Game::time_step * (1.0f / (GLfloat) DC_CELEBRATION_TIME);
86           fade = Game::sqrt(fade);
87           glColor4f(DC_STAR_UNPLAYED_RED, DC_STAR_UNPLAYED_GREEN,
88            DC_STAR_UNPLAYED_BLUE, 1.0f - (1.0f - DC_STAR_LOST_ALPHA) * fade);
89 
90         // star has already faded out
91         } else
92           glColor4f(DC_STAR_UNPLAYED_RED, DC_STAR_UNPLAYED_GREEN,
93            DC_STAR_UNPLAYED_BLUE, DC_STAR_LOST_ALPHA);
94 
95         glTranslatef(DC_STAR_OFFSET_X + DC_STAR_DISPLACEMENT * n,
96          DC_STAR_OFFSET_Y, DC_EXTERNAL_OFFSET_Z);
97         glRotatef(star.a, 0.0f, 0.0f, 1.0f);
98         glScalef(DC_STAR_SIZE_EQUILIBRIUM, -DC_STAR_SIZE_EQUILIBRIUM, 0.0f);
99         glCallList(sparkle_list);
100        break;
101 
102       // game has been won
103       case GR_WON:
104         // if we need to, draw the old star
105         if (WinRecord::draw_old_star && WinRecord::current_game == n) {
106           glPushMatrix();
107             glColor3f(DC_STAR_UNPLAYED_RED, DC_STAR_UNPLAYED_GREEN,
108              DC_STAR_UNPLAYED_BLUE);
109             glTranslatef(DC_STAR_OFFSET_X + DC_STAR_DISPLACEMENT * n,
110              DC_STAR_OFFSET_Y, DC_EXTERNAL_OFFSET_Z);
111             glRotatef(WinRecord::old_star_a, 0.0f, 0.0f, 1.0f);
112             glScalef(WinRecord::old_star_size, -WinRecord::old_star_size, 0.0f);
113             glCallList(sparkle_list);
114           glPopMatrix();
115         }
116 
117         glColor3f(DC_STAR_WIN_RED, DC_STAR_WIN_GREEN, DC_STAR_WIN_BLUE);
118 
119         // star is static but displaced
120         if (n == WinRecord::displaced_star)
121           if (MetaState::mode & CM_SOLO)
122             glTranslatef(DC_STAR_WIN_OFFSET_X, DC_STAR_WIN_SOLO_OFFSET_Y,
123              DC_EXTERNAL_OFFSET_Z);
124           else
125             glTranslatef(DC_STAR_WIN_OFFSET_X, DC_STAR_WIN_OFFSET_Y,
126              DC_EXTERNAL_OFFSET_Z);
127 
128         // star is in motion
129         else if (n == WinRecord::dynamic_star)
130           glTranslatef(DC_STAR_OFFSET_X + DC_STAR_DISPLACEMENT * n
131            + WinRecord::win_star_x, DC_STAR_OFFSET_Y + WinRecord::win_star_y,
132            DC_EXTERNAL_OFFSET_Z);
133 
134         // star is at rest in the standard location
135         else
136           glTranslatef(DC_STAR_OFFSET_X + DC_STAR_DISPLACEMENT * n,
137            DC_STAR_OFFSET_Y, DC_EXTERNAL_OFFSET_Z);
138 
139         glRotatef(star.a, 0.0f, 0.0f, 1.0f);
140         glScalef(star.size, -star.size, 0.0f);
141         glCallList(sparkle_list);
142         break;
143       }
144 
145     glPopMatrix();
146 
147     if (MetaState::mode & CM_SOLO) break;
148   }
149 }
150