File: TutorialPanelB.cpp

package info (click to toggle)
primrose 6%2Bdfsg1-1
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 5,232 kB
  • ctags: 3,287
  • sloc: cpp: 27,302; php: 765; ansic: 636; objc: 272; makefile: 139; sh: 136; perl: 67
file content (358 lines) | stat: -rw-r--r-- 8,579 bytes parent folder | download | duplicates (5)
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
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
#include "TutorialPanelB.h"

#include "numeral.h"

#include "gameControl.h"
#include "sound.h"


#include <GL/gl.h>


extern Color nextPieceDemoColors[3];


TutorialPanelB::TutorialPanelB( int inW, int inH )
        : Panel( inW, inH ),
          mNextButton( inW - ( 19 + 21 ), 19 + 21, "next" ),
          mNextPanel( inW, inH ),
          mDemoStage( 0 ),
          mStepsBetweenStages( 50 ), mStepCount( 0 ) {


    addButton( &mNextButton );
    addSubPanel( &mNextPanel );
    


    int x, y, i;
    
    i=0;
    
    int gridH = 4;
    int gridW = 7;
    
    int yOffset = inH / 3 - 12;
    
    for( y=0; y<gridH; y++ ) {
        for( x=0; x<gridW; x++ ) {
            
            mAllDemoSpaces[i] = 
            mGridDemo[y][x] =
                new GridSpace( x * 40 + 19 + 21, y * 40 + yOffset + 21 );
          
            mAllDemoSpaces[i]->mAddToGlobalScore = false;
            
            
            i++;
            }
        }
    
    // set neighbor relationships
    for( y=0; y<gridH; y++ ) {
        for( x=0; x<gridW; x++ ) {
        
            
            if( y > 0 ) {
                mGridDemo[y][x]->mNeighbors[ GridSpace::top ] = 
                    mGridDemo[y-1][x];
                }
            if( y < gridH-1 ) {
                mGridDemo[y][x]->mNeighbors[ GridSpace::bottom ] = 
                    mGridDemo[y+1][x];
                }
            if( x > 0 ) {
                mGridDemo[y][x]->mNeighbors[ GridSpace::left ] = 
                    mGridDemo[y][x-1];
                }
            if( x < gridW-1 ) {
                mGridDemo[y][x]->mNeighbors[ GridSpace::right ] = 
                    mGridDemo[y][x+1];
                }
            }
        }
    
    mInnerSpaces[0] = mGridDemo[1][2];
    mInnerSpaces[1] = mGridDemo[1][3];
    mInnerSpaces[2] = mGridDemo[2][3];
    mInnerSpaces[3] = mGridDemo[2][4];
    
    mInnerSpacesX[0] = 2;
    mInnerSpacesX[1] = 3;
    mInnerSpacesX[2] = 3;
    mInnerSpacesX[3] = 4;
    

    mOuterSpaces[0] = mGridDemo[0][3];
    mOuterSpaces[1] = mGridDemo[1][4];
    mOuterSpaces[2] = mGridDemo[2][5];
    mOuterSpaces[3] = mGridDemo[3][4];
    mOuterSpaces[4] = mGridDemo[3][3];
    mOuterSpaces[5] = mGridDemo[2][2];
    mOuterSpaces[6] = mGridDemo[1][1];
    
    mKeySpace = mGridDemo[0][2];

    setStageZero();
    }



void TutorialPanelB::setStageZero() {
    
    int i;
    
    for( i=0; i<4; i++ ) {
        mInnerSpaces[i]->setColor( nextPieceDemoColors[0].copy() );
        }
    for( i=0; i<7; i++ ) {
        mOuterSpaces[i]->setColor( nextPieceDemoColors[1].copy() );
        }
    mKeySpace->setColor( NULL );
    
    }


    
TutorialPanelB::~TutorialPanelB() {
    for( int i=0; i<28; i++ ) {
        delete mAllDemoSpaces[i];
        }
    }



void TutorialPanelB::setVisible( char inIsVisible ) {
    Panel::setVisible( inIsVisible );
    
    }



char TutorialPanelB::pointerUp( int inX, int inY ) {
    char consumed = Panel::pointerUp( inX, inY );
    
    if( consumed ) {
        return true;
        }
    

    if( ! isSubPanelVisible() ) {

        if( mNextButton.isInside( inX, inY ) ) {
            
            mNextPanel.setVisible( true );
            
            return true;
            }
        }
    
    return false;
    }



void TutorialPanelB::step() {
    Panel::step();
    
        
    int i;

    for( i=0; i<28; i++ ) {
        mAllDemoSpaces[i]->step();
        }
        
    
    if( isVisible() && ! isSubPanelVisible() ) {
        mStepCount++;
        }
    else {
        // return to step 0
        mDemoStage = 0;
        mStepCount = 0;
        }
    


    // check if we need to revert back to stage zero
    // this might happen after we close or after displaying a sub-panel
    if( mDemoStage == 0 
        && 
        ( ! mKeySpace->isEmpty() || mInnerSpaces[0]->isEmpty() )
        && 
        mInnerSpaces[0]->isAnimationDone() ) {
        
        // lingering at end of score animation
        
        setStageZero();
        }
        
    

    if( mStepCount >= mStepsBetweenStages ) {
        

        mStepCount = 0;
        
        mDemoStage++;
        
        if( mDemoStage > 5 ) {
            mDemoStage = 0;
            }
        

        if( mDemoStage == 0 ) {
            setStageZero();
            }
        else if( mDemoStage == 1 ) {
            // hold zero longer
            }
        else if( mDemoStage == 2 ) {
            mKeySpace->setColor( nextPieceDemoColors[1].copy() );

            if( getSoundOn() ) {
                
                int x = 2;
                
                float leftVolume, rightVolume;
                
                computeEarLoudness( x, &leftVolume, &rightVolume );
                
                playPlacementSound( mKeySpace->getColorIndex(), 
                                    leftVolume, rightVolume );
                }

            }
        else if( mDemoStage == 3 ) {
            // accumulate average volume
            float leftEarWeight = 0;
            float rightEarWeight = 0;
            
            int oldColorIndex = mInnerSpaces[0]->getColorIndex();

            for( i=0; i<4; i++ ) {
                mInnerSpaces[i]->mScore = 20;
                mInnerSpaces[i]->flipToClear();
                
                float lV, rV;
                
                computeEarLoudness( mInnerSpacesX[i], &lV, &rV );
                leftEarWeight += lV;
                rightEarWeight += rV;        
                }

            if( getSoundOn() ) {
                
                playClearingSound( oldColorIndex, 4,
                                   1,
                                   leftEarWeight / 4,
                                   rightEarWeight / 4 );
                }
                
            }
        else if( mDemoStage == 4 ) {
            // hold stage 2 for extra step
            }
        else if( mDemoStage == 5 ) {
            // blank before next cycle
            for( i=0; i<28; i++ ) {
                mAllDemoSpaces[i]->setColor( NULL );
                }
            // this stage short
            mStepCount += mStepsBetweenStages / 2;
            }
        
            

        }
    
    }



extern Color tutorialTextColor;

        
void TutorialPanelB::drawBase() {
    
    Panel::drawBase();
    
    if( mFadeProgress > 0 ) {
        
        glEnable( GL_BLEND );
        glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
        
        drawString( "clear a tile group of one color", left, 
                    19,
                    mGridDemo[0][0]->mY - 20 - 60,
                    &tutorialTextColor, mFadeProgress );        
        drawString( "by surrounding it with another", left, 
                    19,
                    mGridDemo[0][0]->mY - 20 - 40,
                    &tutorialTextColor, mFadeProgress );        
        drawString( "color and score points", left, 
                    19,
                    mGridDemo[0][0]->mY - 20 - 20,
                    &tutorialTextColor, mFadeProgress );        

        drawString( "the surrounding tiles flip to", left, 
                    19,
                    mGridDemo[3][0]->mY + 20 + 20,
                    &tutorialTextColor, mFadeProgress );
        drawString( "the color that was cleared", left, 
                    19,
                    mGridDemo[3][0]->mY + 20 + 40,
                    &tutorialTextColor, mFadeProgress );


        drawString( "clear bigger groups for even", left, 
                    19,
                    mGridDemo[3][0]->mY + 20 + 91,
                    &tutorialTextColor, mFadeProgress );        

        drawString( "more points", left, 
                    19,
                    mGridDemo[3][0]->mY + 20 + 111,
                    &tutorialTextColor, mFadeProgress );        
        

        glDisable( GL_BLEND );
        

        int i;
        
        int numGridSpaces = 28;
        
        for( i=0; i<numGridSpaces; i++ ) {
            mAllDemoSpaces[i]->drawGrid( mFadeProgress );
            }
        for( i=0; i<numGridSpaces; i++ ) {
            mAllDemoSpaces[i]->drawPieceCenter( mFadeProgress );
            }
        for( i=0; i<numGridSpaces; i++ ) {
            mAllDemoSpaces[i]->drawPieceHalo( mFadeProgress );
            }
        

        }
    

    
    }



void TutorialPanelB::closePressed() {
    // return to step 0
    mDemoStage = 0;
    mStepCount = 0;
    

    // can't do this safely here because score animation might still be
    // running 
    // setStageZero();
    }