~ubuntu-branches/ubuntu/quantal/zaz/quantal

« back to all changes in this revision

Viewing changes to src/ballpath.cpp

  • Committer: Package Import Robot
  • Author(s): Miriam Ruiz
  • Date: 2011-11-16 02:28:10 UTC
  • mfrom: (1.1.1)
  • Revision ID: package-import@ubuntu.com-20111116022810-d3tehh974q280vit
Tags: 1.0.0~dfsg1-1
* New Upstream Release
* Upgraded Standards-Version from 3.8.3 to 3.9.2
* New homepage: http://phuzzboxmedia.com/index.php/games/open-sourced-zaz
* Refreshed patches
* Moved package to DebSrc 3

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
#include "ballpath.h"
20
20
#include "game.h"
21
21
 
22
 
BallPath::BallPath(Bezier path, GLuint *textures, Scenes::Mixer **mixer, bool drawPath)
23
 
        :  path(path), drawPath(drawPath), hasGap(false), tex(textures), rollSound(0), playRoll(false), mixer(mixer),
 
22
BallPath::BallPath(Bezier path, GLuint *textures, Scenes::Mixer **mixer, bool drawPath, double ballSizeFactor)
 
23
        :  ballSize(BALLSIZE), path(path), drawPath(drawPath), hasGap(false), tex(textures), rollSound(0), playRoll(false), mixer(mixer),
24
24
        extraBallFading(false), extraBallFadeinTimeout(0)
25
25
{
26
26
//    std::vector<XY> pts = path.GenerateBalls(ballSize, stepsPerBall);
 
27
    ballSize = (int)(ballSize * ballSizeFactor);
27
28
    std::vector<XY> pts = path.GenerateUniform((double)ballSize / (double)stepsPerBall);
28
 
    pthLen = pts.size() -1;
29
 
 
30
29
    std::vector<XY>::iterator i;
31
30
    for (i = pts.begin(); i != pts.end(); ++i)
32
 
        ballPath.push_back(PathStep(i->x, i->y));
 
31
        ballPath.push_back(PathStep(i->x, i->y, 0, i->under, i->hidden));
33
32
 
 
33
    pthLen = ballPath.size();
34
34
    GenRotation();
35
35
}
36
36
 
40
40
 
41
41
void BallPath::GenRotation()
42
42
{
43
 
    for (int i = 1; i < pthLen - 1; ++i)
 
43
    for (uint i = 1; i < pthLen - 1; ++i)
44
44
    {
45
45
        XY pt1 = XY(ballPath[i - 1].x, ballPath[i - 1].y);
46
46
        XY pt2 = XY(ballPath[i + 1].x, ballPath[i + 1].y);
54
54
 
55
55
Bonus BallPath::DrawBonus()
56
56
{
 
57
    int freq = bonusFrequency;
 
58
    if (state.bonusFrequency > 0)
 
59
        freq = state.bonusFrequency;
 
60
 
57
61
    int b = (rand()%(int(BONUS_BOMB))) + 1;
58
62
 
59
63
    int d = rand()%100;
60
64
 
61
 
    if (d > 100 - bonusFrequency)
 
65
    if (d > 100 - freq)
62
66
    {
63
67
        if (b == BONUS_BOMB)
64
68
        {
65
 
            if (!state.hadBonusBomb)
 
69
            if (state.survival)
 
70
                return BONUS_NONE;
 
71
 
 
72
            if (!state.hadBonusBomb || state.kidsMode)
66
73
            {
67
74
                state.hadBonusBomb = true;
68
75
                return BONUS_BOMB;
73
80
 
74
81
        if (b == BONUS_REVERSE)
75
82
        {
76
 
            if (!state.hadBonusReverse)
 
83
            if (state.survival)
 
84
                return BONUS_NONE;
 
85
 
 
86
            if (!state.hadBonusReverse || state.kidsMode)
77
87
            {
78
88
                state.hadBonusReverse = true;
79
89
                return BONUS_REVERSE;
82
92
            return BONUS_NONE;
83
93
        }
84
94
 
 
95
        if (b == BONUS_ACCURACY && state.kidsMode)
 
96
            return BONUS_NONE;
 
97
 
85
98
        return Bonus(b);
86
99
    }
87
100
 
98
111
    }
99
112
 
100
113
    if (balls.size() < 2)
 
114
    {
 
115
        if (state.ballsToDraw > 0)
 
116
            state.ballsToDraw--;
 
117
 
101
118
        return Ball(rand() % state.colors, DrawBonus(), 0);
 
119
    }
102
120
 
103
121
    bool ok = false;
104
122
    int b = 0;
113
131
            ok = false;
114
132
    }
115
133
 
 
134
    if (state.ballsToDraw > 0)
 
135
        state.ballsToDraw--;
 
136
 
116
137
    return Ball(b, DrawBonus(), 0);
117
138
}
118
139
 
127
148
            if (extraBallFadeinTimeout == 0)
128
149
            {
129
150
                extraBallFading = false;
130
 
                balls.push_front(Ball(state.extraBall, BONUS_NONE, (uint)balls[0].pos - (stepsPerBall)));
 
151
                balls.push_front(Ball(state.extraBall, BONUS_NONE, balls[0].upos() - (stepsPerBall)));
131
152
                balls[0].size = stepsPerBall;
132
153
                state.extraBall = -1;
133
154
            }
162
183
            explosions.clear();
163
184
    }
164
185
 
165
 
 
166
186
    if (!pointSprites.empty())
167
187
    {
168
188
        vector<PointSprite>::iterator i;
201
221
            state.bonusSlow = false;
202
222
    }
203
223
 
204
 
    if (playRoll)
 
224
    if (playRoll || state.speedUp)
205
225
    {
206
226
        if (rollSound == 0)
207
227
            if (mixer != NULL)
216
236
        }
217
237
    }
218
238
 
219
 
    if (state.bonusReverseBallsLeft > 0)
 
239
    if ((state.bonusReverseBallsLeft > 0) && (!state.speedUp))
220
240
    {
221
241
        if (balls.size() == 0)
222
242
        {
275
295
            {
276
296
                Ball db = DrawBall();
277
297
                balls.push_front(Ball(db.col, db.bonus, 0));
278
 
                if (state.ballsToDraw > 0)
279
 
                    state.ballsToDraw--;
280
298
            }
281
299
        }
282
300
 
287
305
                {
288
306
                    Ball db = DrawBall();
289
307
                    balls.push_front(Ball(db.col, db.bonus, 0));
290
 
                    if (state.ballsToDraw > 0)
291
 
                        state.ballsToDraw--;
292
308
                }
293
309
                else
294
310
                {
295
311
                    if (state.extraBall != -1)
296
 
                    {
297
 
                        if (balls.empty() && !extraBallFading)
298
 
                        {
299
 
                            InsertBall (ShotAddr (-1), state.extraBall);
300
 
                            state.extraBall = -1;
301
 
                        }
302
 
                        else
303
 
                        {
304
 
                            if (balls[0].pos > STEPSPERBALL * 2)
 
312
                        if (balls[0].pos > STEPSPERBALL * 2)
 
313
                            if (!extraBallFading)
305
314
                            {
306
 
                                if (!extraBallFading)
307
 
                                {
308
 
                                    extraBallFadeinTimeout = extraBallFadeinTime;
309
 
                                    extraBallFading = true;
310
 
                                    if (mixer != NULL)
311
 
                                        (*mixer)->EnqueueSample(sfx_extraball, sfxVol);
312
 
                                }
 
315
                                extraBallFadeinTimeout = extraBallFadeinTime;
 
316
                                extraBallFading = true;
 
317
                                if (mixer != NULL)
 
318
                                    (*mixer)->EnqueueSample(sfx_extraball, sfxVol);
313
319
                            }
314
 
                        }
315
 
                    }
316
320
                }
317
321
            }
318
322
    }
319
323
 
 
324
 
 
325
    // this could happen...
 
326
    if (state.extraBall != -1 && balls.empty())
 
327
    {
 
328
        extraBallFading = false;
 
329
        state.extraBall = -1;
 
330
    }
 
331
 
320
332
    if (state.ballsFromStart > 0)
321
333
    {
322
334
        Drive(stepsPerBall / 4);
323
335
    }
324
336
    else
325
337
    {
326
 
        Drive(state.feedRate);
 
338
        if (state.speedUp)
 
339
        {
 
340
            Drive(state.feedRate * speedUpMultiplier);
 
341
            state.bonusPause = false;
 
342
            state.bonusSlow = false;
 
343
            state.bonusReverseBallsLeft = 0;
 
344
        }
 
345
        else
 
346
        {
 
347
            Drive(state.feedRate);
 
348
        }
327
349
        Attract();
328
350
        Eliminate();
329
351
    }
345
367
        playRoll = true;
346
368
 
347
369
    balls[0].pos+=d;
348
 
    balls[0].frame+= ((double)BALLANIMFRAMES/(double)STEPSPERBALL/2.0) * (double)d;
 
370
    balls[0].frame+= ((double)ballAnimFrames/(double)STEPSPERBALL/2.0) * (double)d;
349
371
 
350
372
    if (!balls[0].elim)
351
373
    {
363
385
    if (balls[0].size > stepsPerBall)
364
386
        balls[0].size = stepsPerBall;
365
387
 
366
 
    if (balls[0].frame > BALLANIMFRAMES)
367
 
        balls[0].frame -= (double)BALLANIMFRAMES;
 
388
    if (balls[0].frame > (double)ballAnimFrames)
 
389
        balls[0].frame -= (double)ballAnimFrames;
368
390
 
369
391
    for (uint b = 1; b < balls.size(); b++)
370
392
    {
377
399
 
378
400
        if ((balls[b].pos - balls[b - 1].pos) < balls[b - 1].size)
379
401
        {
380
 
            balls[b].pos = balls[b - 1].pos + balls[b - 1].size;
381
 
            balls[b].frame += ((double)BALLANIMFRAMES/(double)STEPSPERBALL/2.0) * (double)d;
382
 
            if (balls[b].frame > BALLANIMFRAMES)
383
 
                balls[b].frame -= (double)BALLANIMFRAMES;
 
402
            balls[b].                           pos = balls[b - 1].pos + balls[b - 1].size;
 
403
            balls[b].frame += ((double)ballAnimFrames/(double)STEPSPERBALL/2.0) * (double)d;
 
404
            if (balls[b].frame > (double)ballAnimFrames)
 
405
                balls[b].frame -= (double)ballAnimFrames;
384
406
        }
385
407
    }
386
408
 
387
409
    // is a ball outside
388
410
    int lball = balls.size() - 1;
389
 
    if (balls[lball].pos >= pthLen)
 
411
    if (balls[lball].upos() >= pthLen)
390
412
    {
391
413
        state.ballOut = true;
392
414
        deque<Ball>::iterator i;
485
507
            i = balls.begin();
486
508
            i += b;
487
509
 
488
 
            int pan = (int)ballPath[(uint)balls[b].pos].x - 50;
 
510
            int pan = (int)ballPath[balls[b].upos()].x - 50;
489
511
 
490
512
            if (balls[b].bonus == BONUS_PAUSE)
491
513
            {
519
541
 
520
542
            if (balls[b].bonus == BONUS_BOMB)
521
543
            {
522
 
                int bs = (int)balls[b].pos - bombDistance * stepsPerBall;
523
 
                int be = (int)balls[b].pos + bombDistance * stepsPerBall;
 
544
                int bdist = bombDistance;
 
545
//                              if (state.kidsMode)
 
546
//                                      bdist *= 1.5;
 
547
 
 
548
                int bs = (int)balls[b].pos - bdist * stepsPerBall;
 
549
                int be = (int)balls[b].pos + bdist * stepsPerBall;
524
550
 
525
551
                if (bs < 0)
526
552
                    bs = 0;
527
553
 
528
 
                if (be >= pthLen)
 
554
                if (be >= (int)pthLen)
529
555
                    be = pthLen;
530
556
 
531
557
                for (uint f = 0; f < balls.size(); ++f)
563
589
                state.score += score;
564
590
            }
565
591
 
566
 
            double x = ballPath[(uint)balls[b].pos].x;
567
 
            double y = ballPath[(uint)balls[b].pos].y;
 
592
            double x = ballPath[balls[b].upos()].x;
 
593
            double y = ballPath[balls[b].upos()].y;
568
594
 
569
595
            pointSprites.push_back(PointSprite(score, x, y));
570
596
            balls.erase(i);
587
613
 
588
614
        if ((balls[b + 1].col == col)
589
615
                && (balls[b + 2].col == col)
590
 
                && (balls[b].size == stepsPerBall)
591
 
                && (balls[b + 1].size == stepsPerBall)
592
 
                && (balls[b + 2].size == stepsPerBall)
593
 
                && (balls[b + 2].pos - balls[b + 1].pos < (double)STEPSPERBALL * 1.01)
 
616
                /*                && (balls[b].size == stepsPerBall)
 
617
                                && (balls[b + 1].size == stepsPerBall)
 
618
                                && (balls[b + 2].size == stepsPerBall)
 
619
                */                && (balls[b + 2].pos - balls[b + 1].pos < (double)STEPSPERBALL * 1.01)
594
620
                && (balls[b + 1].pos - balls[b].pos < (double)STEPSPERBALL * 1.01))
595
621
        {
 
622
            if (!balls[b].elim)
 
623
                balls[b].explode = true;
 
624
 
 
625
            if (!balls[b + 1].elim)
 
626
                balls[b + 1].explode = true;
 
627
 
 
628
            if (!balls[b + 2].elim)
 
629
                balls[b + 2].explode = true;
 
630
 
596
631
            balls[b].elim = true;
597
632
            balls[b + 1].elim = true;
598
633
            balls[b + 2].elim = true;
599
 
 
600
 
            balls[b].explode = true;
601
 
            balls[b + 1].explode = true;
602
 
            balls[b + 2].explode = true;
603
634
        }
604
635
    }
605
636
 
609
640
        if (balls[b].explode)
610
641
        {
611
642
            balls[b].explode = false;
612
 
            double x = ballPath[(uint)balls[b].pos].x;
613
 
            double y = ballPath[(uint)balls[b].pos].y;
 
643
            double x = ballPath[balls[b].upos()].x;
 
644
            double y = ballPath[balls[b].upos()].y;
614
645
 
615
646
            explosions.push_back(Explosion(x, y));
616
647
 
685
716
        balls[b].pos -= pullSpeed;
686
717
        balls[b].frame -= pullSpeed / 2;
687
718
        if (balls[b].frame < 0)
688
 
            balls[b].frame += 100;
 
719
            balls[b].frame += ballAnimFrames;
689
720
    }
690
721
 
691
722
    if ((balls[gapball].pos - balls[gapball - 1].pos) < (double)stepsPerBall)
695
726
        {
696
727
            balls[b].pos += push;
697
728
            balls[b].frame += push / 2;
698
 
            if (balls[b].frame > 100)
699
 
                balls[b].frame -= 100;
 
729
            if (balls[b].frame > ballAnimFrames)
 
730
                balls[b].frame -= ballAnimFrames;
700
731
        }
701
732
    }
702
733
}
703
734
 
704
 
void BallPath::Render()
 
735
void BallPath::Render(bool render_balls, bool render_sprites, bool render_under, bool render_over)
705
736
{
706
737
    glLoadIdentity();
707
738
    // balls
708
739
    glEnable(GL_TEXTURE_2D);
709
740
    glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
710
 
    for (uint i = 0; i < balls.size(); ++i)
711
 
    {
712
 
        int pos = (int)balls[i].pos;
713
 
 
714
 
        int fr = (int)balls[i].frame;
715
 
        if (fr > 99)
716
 
            fr = 0;
717
 
 
718
 
        double ts = (ballOneTextureSize * 10.0) / double(ballTextureSize);
719
 
        double tx = (double)((fr % 10) / 10.0f) * ts;
720
 
        double ty = (double)((fr / 10) / 10.0f) * ts;
721
 
        ts *= 0.1;
722
 
 
723
 
        double bs = ((double)balls[i].size / (stepsPerBall)) * ballSize;
724
 
 
725
 
        if (balls[i].pos < stepsPerBall)
726
 
        {
727
 
            bs = ((double)balls[i].pos / (stepsPerBall / 4)) * ballSize;
728
 
            if (bs > 5.0)
729
 
                bs = 5.0;
730
 
        }
731
 
 
732
 
        if (balls[i].pos > pthLen - stepsPerBall)
733
 
        {
734
 
            bs = ((double)(balls[i].pos - (pthLen - stepsPerBall))/ (stepsPerBall / 4)) * ballSize;
735
 
            bs = ballSize - bs;
736
 
            if (bs < 0.0)
737
 
                bs = 0.0;
738
 
        }
739
 
 
740
 
        if (pos <= pthLen)
741
 
        {
742
 
            glLoadIdentity();
743
 
            glTranslated(ballPath[pos].x, ballPath[pos].y, 1);
744
 
            glBindTexture(GL_TEXTURE_2D, tex[balls[i].col]);
745
 
            glScaled(bs, bs, bs);
746
 
            glRotated(ballPath[pos].r, 0, 0, 1.0);
747
 
            glBegin(GL_QUADS);
748
 
            glTexCoord2d(tx, ty);
749
 
            glVertex3d(-0.5, 0.5, 0);
750
 
            glTexCoord2d(tx, ty + ts);
751
 
            glVertex3d(-0.5, -0.5, 0);
752
 
            glTexCoord2d(tx + ts, ty + ts);
753
 
            glVertex3d(0.5, -0.5, 0);
754
 
            glTexCoord2d(tx + ts, ty);
755
 
            glVertex3d(0.5, 0.5, 0);
756
 
            glEnd();
757
 
 
758
 
 
759
 
            if (balls[i].bonus != BONUS_NONE)
 
741
    if (render_balls)
 
742
        for (uint i = 0; i < balls.size(); ++i)
 
743
        {
 
744
            uint pos = balls[i].upos();
 
745
 
 
746
            int fr = (int)balls[i].frame;
 
747
            if (fr > ballAnimFrames - 1)
 
748
                fr = 0;
 
749
 
 
750
//            double ts = (ballOneTextureSize * 8.0) / double(ballTextureSize);
 
751
            double ts = 1.0 / double(ballTextureCount);
 
752
            double tx = (double)((fr % ballTextureCount)) * ts;
 
753
            double ty = (double)((fr / ballTextureCount)) * ts;
 
754
            //ts *= 0.1;
 
755
 
 
756
            double bs = ((double)balls[i].size / (stepsPerBall)) * ballSize;
 
757
 
 
758
            if (balls[i].pos < stepsPerBall)
 
759
            {
 
760
                bs = ((double)balls[i].pos / (stepsPerBall / 4)) * ballSize;
 
761
                if (bs > ballSize)
 
762
                    bs = ballSize;
 
763
            }
 
764
 
 
765
            if (balls[i].pos > pthLen - stepsPerBall)
 
766
            {
 
767
                bs = ((double)(balls[i].pos - (pthLen - stepsPerBall))/ (stepsPerBall / 4)) * ballSize;
 
768
                bs = ballSize - bs;
 
769
                if (bs < 0.0)
 
770
                    bs = 0.0;
 
771
            }
 
772
 
 
773
            bool render_this_ball = false;
 
774
 
 
775
            if (pos < pthLen)
 
776
            {
 
777
                render_this_ball = true;
 
778
 
 
779
                if ((ballPath[pos].under || ballPath[pos].hidden) && !render_under)
 
780
                    render_this_ball = false;
 
781
 
 
782
                if ((!ballPath[pos].under && !ballPath[pos].hidden) && !render_over)
 
783
                    render_this_ball = false;
 
784
            }
 
785
 
 
786
            if (render_this_ball)
760
787
            {
761
788
                glLoadIdentity();
762
789
                glTranslated(ballPath[pos].x, ballPath[pos].y, 2);
 
790
                glBindTexture(GL_TEXTURE_2D, tex[balls[i].col]);
 
791
                if (ballPath[pos].under || ballPath[pos].hidden)
 
792
                    glTranslated(0.0, 0.0, -1);
 
793
 
763
794
                glScaled(bs, bs, bs);
 
795
 
764
796
                glRotated(ballPath[pos].r, 0, 0, 1.0);
765
 
                glBindTexture(GL_TEXTURE_2D, tex[NBALLCOLORS + (balls[i].bonus - 1) ]);
 
797
 
766
798
                glBegin(GL_QUADS);
767
 
                glTexCoord2d(0, 0);
 
799
                glTexCoord2d(tx, ty);
768
800
                glVertex3d(-0.5, 0.5, 0);
769
 
                glTexCoord2d(0, 1);
 
801
                glTexCoord2d(tx, ty + ts);
770
802
                glVertex3d(-0.5, -0.5, 0);
771
 
                glTexCoord2d(1, 1);
 
803
                glTexCoord2d(tx + ts, ty + ts);
772
804
                glVertex3d(0.5, -0.5, 0);
773
 
                glTexCoord2d(1, 0);
 
805
                glTexCoord2d(tx + ts, ty);
774
806
                glVertex3d(0.5, 0.5, 0);
775
807
                glEnd();
 
808
 
 
809
                if (balls[i].bonus != BONUS_NONE)
 
810
                {
 
811
                    glLoadIdentity();
 
812
                    glTranslated(ballPath[pos].x, ballPath[pos].y, 2.1);
 
813
 
 
814
                    if (ballPath[pos].under || ballPath[pos].hidden)
 
815
                        glTranslated(0.0, 0.0, -1);
 
816
 
 
817
                    glScaled(bs, bs, bs);
 
818
                    glRotated(ballPath[pos].r, 0, 0, 1.0);
 
819
                    glBindTexture(GL_TEXTURE_2D, tex[NBALLCOLORS + (balls[i].bonus - 1) ]);
 
820
                    glBegin(GL_QUADS);
 
821
                    glTexCoord2d(0, 0);
 
822
                    glVertex3d(-0.5, 0.5, 0);
 
823
                    glTexCoord2d(0, 1);
 
824
                    glVertex3d(-0.5, -0.5, 0);
 
825
                    glTexCoord2d(1, 1);
 
826
                    glVertex3d(0.5, -0.5, 0);
 
827
                    glTexCoord2d(1, 0);
 
828
                    glVertex3d(0.5, 0.5, 0);
 
829
                    glEnd();
 
830
                }
776
831
            }
777
832
        }
778
 
    }
779
833
 
780
834
    // extraball
781
 
    if (!balls.empty())
782
 
        if (extraBallFading && balls[0].pos > stepsPerBall)
783
 
        {
784
 
            float alpha = float((extraBallFadeinTime - extraBallFadeinTimeout)) / float(extraBallFadeinTime);
785
 
            int pos = (int)(alpha * (balls[0].pos - stepsPerBall));
786
 
 
787
 
            double bs = ((double)balls[0].size / (stepsPerBall)) * ballSize;
788
 
            double x = ballPath[pos].x;
789
 
            double y = ballPath[pos].y;
790
 
            double ts = ((ballOneTextureSize * 10.0) / double(ballTextureSize)) * 0.1;
791
 
 
792
 
 
793
 
            glLoadIdentity();
794
 
            glTranslated(x, y, 5);
795
 
            glRotated(ballPath[pos].r, 0, 0, 1.0);
796
 
            glScaled(bs, bs, bs);
797
 
            glColor4f(1.0f, 1.0f, 1.0f, alpha);
798
 
            glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
799
 
            glBindTexture(GL_TEXTURE_2D, tex[state.extraBall]);
800
 
            glBegin(GL_QUADS);
801
 
            glTexCoord2d(0, 0);
802
 
            glVertex3d(-0.5, 0.5, 0);
803
 
            glTexCoord2d(0, ts);
804
 
            glVertex3d(-0.5, -0.5, 0);
805
 
            glTexCoord2d(ts, ts);
806
 
            glVertex3d(0.5, -0.5, 0);
807
 
            glTexCoord2d(ts, 0);
808
 
            glVertex3d(0.5, 0.5, 0);
809
 
            glEnd();
810
 
            glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
811
 
        }
 
835
    if (render_balls)
 
836
        if (!balls.empty())
 
837
            if (extraBallFading && balls[0].pos > stepsPerBall)
 
838
            {
 
839
                float alpha = float((extraBallFadeinTime - extraBallFadeinTimeout)) / float(extraBallFadeinTime);
 
840
                int pos = (int)(alpha * (balls[0].pos - stepsPerBall));
 
841
 
 
842
                if (pos < 0)
 
843
                    pos = 0;
 
844
 
 
845
                double bs = ((double)balls[0].size / (stepsPerBall)) * ballSize;
 
846
                double x = ballPath[pos].x;
 
847
                double y = ballPath[pos].y;
 
848
                double ts = 1.0 / double(ballTextureCount);
 
849
 
 
850
                glLoadIdentity();
 
851
                glTranslated(x, y, 2);
 
852
 
 
853
                bool render_this_ball = true;
 
854
 
 
855
                if ((ballPath[pos].under || ballPath[pos].hidden) && !render_under)
 
856
                    render_this_ball = false;
 
857
 
 
858
                if ((!ballPath[pos].under && !ballPath[pos].hidden) && !render_over)
 
859
                    render_this_ball = false;
 
860
 
 
861
                if (ballPath[pos].under || ballPath[pos].hidden)
 
862
                    glTranslated(0.0, 0.0, -1);
 
863
 
 
864
                if (render_this_ball)
 
865
                {
 
866
                    glRotated(ballPath[pos].r, 0, 0, 1.0);
 
867
                    glScaled(bs, bs, bs);
 
868
                    glColor4f(1.0f, 1.0f, 1.0f, alpha);
 
869
                    glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
 
870
                    glBindTexture(GL_TEXTURE_2D, tex[state.extraBall]);
 
871
                    glBegin(GL_QUADS);
 
872
                    glTexCoord2d(0, 0);
 
873
                    glVertex3d(-0.5, 0.5, 0);
 
874
                    glTexCoord2d(0, ts);
 
875
                    glVertex3d(-0.5, -0.5, 0);
 
876
                    glTexCoord2d(ts, ts);
 
877
                    glVertex3d(0.5, -0.5, 0);
 
878
                    glTexCoord2d(ts, 0);
 
879
                    glVertex3d(0.5, 0.5, 0);
 
880
                    glEnd();
 
881
                    glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
 
882
                }
 
883
            }
812
884
 
813
885
    // explosions
814
886
    vector<Explosion>::iterator expl;
815
887
 
816
888
    double z = 20;
817
 
    for (expl = explosions.begin(); expl != explosions.end(); ++expl)
818
 
    {
819
 
        if (expl->frame < 17)
 
889
    if (render_sprites)
 
890
        for (expl = explosions.begin(); expl != explosions.end(); ++expl)
820
891
        {
821
 
            double tx = (expl->frame % 4);
822
 
            double ty = (expl->frame / 4);
823
 
 
824
 
            tx*=0.25;
825
 
            ty*=0.25;
826
 
 
827
 
            glLoadIdentity();
828
 
            glTranslated(expl->x, expl->y, z);
829
 
            glRotated(expl->r, 0.0, 0.0, 1.0);
830
 
            glBindTexture(GL_TEXTURE_2D, tex[NBALLCOLORS + BONUS_BOMB]);
831
 
            glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
832
 
            glColor4d(1.0, 1.0, 1.0, 0.5);
833
 
            glScaled(expl->s, expl->s, 1.0);
834
 
 
835
 
            glBegin(GL_QUADS);
836
 
            glTexCoord2d(tx, ty);
837
 
            glVertex3d(-0.5, 0.5, 0);
838
 
            glTexCoord2d(tx, ty + 0.25);
839
 
            glVertex3d(-0.5, -0.5, 0);
840
 
            glTexCoord2d(tx + 0.25, ty + 0.25);
841
 
            glVertex3d(0.5, -0.5, 0);
842
 
            glTexCoord2d(tx + 0.25, ty);
843
 
            glVertex3d(0.5, 0.5, 0);
844
 
 
845
 
            glEnd();
 
892
            if (expl->frame < 17)
 
893
            {
 
894
                double tx = (expl->frame % 4);
 
895
                double ty = (expl->frame / 4);
 
896
 
 
897
                tx*=0.25;
 
898
                ty*=0.25;
 
899
 
 
900
                glLoadIdentity();
 
901
                glTranslated(expl->x, expl->y, z);
 
902
                glRotated(expl->r, 0.0, 0.0, 1.0);
 
903
                glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
 
904
                glBindTexture(GL_TEXTURE_2D, tex[NBALLCOLORS + BONUS_BOMB]);
 
905
//            glBindTexture(GL_TEXTURE_2D, tex[NBALLCOLORS + 1]);
 
906
                glColor4d(1.0, 1.0, 1.0, 0.7);
 
907
                glScaled(expl->s, expl->s, 1.0);
 
908
 
 
909
                glBegin(GL_QUADS);
 
910
                glTexCoord2d(tx, ty);
 
911
                glVertex3d(-0.5, 0.5, 0);
 
912
                glTexCoord2d(tx, ty + 0.25);
 
913
                glVertex3d(-0.5, -0.5, 0);
 
914
                glTexCoord2d(tx + 0.25, ty + 0.25);
 
915
                glVertex3d(0.5, -0.5, 0);
 
916
                glTexCoord2d(tx + 0.25, ty);
 
917
                glVertex3d(0.5, 0.5, 0);
 
918
 
 
919
                glEnd();
 
920
                glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
 
921
            }
 
922
            z+=1.0;
846
923
        }
847
 
        z+=1.0;
848
 
    }
849
 
 
850
924
 
851
925
    // pointsprites
852
926
    vector<PointSprite>::iterator psi;
853
 
 
854
 
    for (psi = pointSprites.begin(); psi != pointSprites.end(); ++psi)
855
 
    {
856
 
        if (psi->time)
 
927
    if (render_sprites)
 
928
        for (psi = pointSprites.begin(); psi != pointSprites.end(); ++psi)
857
929
        {
858
 
            float alpha = float(psi->time) / float(pointSpriteFadeoutTime);
859
 
 
860
 
            glColor4f(1.0, 1.0, 1.0, alpha);
861
 
            glLoadIdentity();
862
 
            glTranslated(psi->x, psi->y, 50);
863
 
            glScaled(0.1, 0.1, 0.1);
864
 
 
865
 
            char scoretxt[256];
866
 
            sprintf(scoretxt, "%d", psi->points);
867
 
            glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
868
 
            font3->Render(scoretxt);
869
 
            glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
 
930
            if (psi->time)
 
931
            {
 
932
                float alpha = float(psi->time) / float(pointSpriteFadeoutTime);
 
933
 
 
934
                glColor4f(1.0, 1.0, 1.0, alpha);
 
935
                glLoadIdentity();
 
936
                glTranslated(psi->x, psi->y, 50);
 
937
                glScaled(0.1, 0.1, 0.1);
 
938
 
 
939
                char scoretxt[256];
 
940
                sprintf(scoretxt, "%d", psi->points);
 
941
                glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
 
942
                font3->Render(scoretxt);
 
943
                glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
 
944
            }
870
945
        }
871
 
    }
872
946
 
873
947
    glDisable(GL_TEXTURE_2D);
874
948
}
897
971
            if (balls[b].elim)
898
972
                continue;
899
973
 
900
 
            double bx = ballPath[(uint)balls[b].pos].x;
901
 
            double by = ballPath[(uint)balls[b].pos].y;
 
974
            if (ballPath[balls[b].upos()].hidden)
 
975
                continue;
 
976
 
 
977
            double bx = ballPath[balls[b].upos()].x;
 
978
            double by = ballPath[balls[b].upos()].y;
902
979
 
903
980
            if (fabs(px - bx) < ((double)ballSize / 1.5) && fabs(py - by) < ((double)ballSize / 1.5))
904
981
            {
927
1004
 
928
1005
    for (uint b = 0; b < balls.size(); ++b)
929
1006
    {
930
 
        double bx = ballPath[(uint)balls[b].pos].x;
931
 
        double by = ballPath[(uint)balls[b].pos].y;
 
1007
        double bx = ballPath[balls[b].upos()].x;
 
1008
        double by = ballPath[balls[b].upos()].y;
932
1009
 
 
1010
        if (ballPath[balls[b].upos()].hidden)
 
1011
            continue;
933
1012
 
934
1013
        if (fabs(x - bx) < ((double)ballSize) && fabs(y - by) < ((double)ballSize))
935
1014
        {
936
1015
            double dist = sqrt(pow(fabs(bx - x), 2.0) + pow(fabs(by - y), 2.0));
937
1016
 
938
1017
            double distf;
939
 
            if (balls[b].pos > 0)
 
1018
            if (balls[b].upos() > 0)
940
1019
            {
941
 
                bx = ballPath[(uint)balls[b].pos - 1].x;
942
 
                by = ballPath[(uint)balls[b].pos - 1].y;
 
1020
                bx = ballPath[balls[b].upos() - 1].x;
 
1021
                by = ballPath[balls[b].upos() - 1].y;
943
1022
                distf = sqrt(pow(fabs(bx - x), 2.0) + pow(fabs(by - y), 2.0));
944
1023
            }
945
1024
            else
946
1025
            {
947
 
                bx = ballPath[(uint)balls[b].pos].x;
948
 
                by = ballPath[(uint)balls[b].pos].y;
 
1026
                bx = ballPath[balls[b].upos()].x;
 
1027
                by = ballPath[balls[b].upos()].y;
949
1028
                distf = sqrt(pow(fabs(bx - x), 2.0) + pow(fabs(by - y), 2.0));
950
1029
            }
951
1030
 
952
 
            bx = ballPath[(uint)balls[b].pos + 1].x;
953
 
            by = ballPath[(uint)balls[b].pos + 1].y;
 
1031
            bx = ballPath[balls[b].upos() + 1].x;
 
1032
            by = ballPath[balls[b].upos() + 1].y;
954
1033
            double distb = sqrt(pow(fabs(bx - x), 2.0) + pow(fabs(by - y), 2.0));
955
1034
 
956
1035
            if (dist < ldist)