-
Notifications
You must be signed in to change notification settings - Fork 7
/
main.cpp
4642 lines (3962 loc) · 116 KB
/
main.cpp
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
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* ************************************************************************* *
SDL-Ball - DX-Ball/Breakout remake with openGL and SDL for Linux
Copyright (C) 2008-2014 Jimmy Christensen ( dusted at dusted dot dk )
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
* ************************************************************************* */
#include <iostream>
#include <iomanip>
#include <fstream>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <unistd.h>
#include <GL/gl.h>
#include <GL/glu.h>
#include <SDL2/SDL.h>
#include <SDL2/SDL_ttf.h>
#include <SDL2/SDL_image.h>
#include <cmath>
#include <cstring>
#include <list>
#include <vector>
#include <sys/stat.h>
#include "display.hpp"
#include <dirent.h>
#ifdef WIN32
#define _OBJC_NO_COM
#include <windows.h>
#include <GL/glext.h>
#endif
/* ******************************************** *
Here are the compile-time options !! ;)
* ******************************************** */
//WIN32
#ifndef DATADIR
#define DATADIR "themes/"
#endif
//To disable sound support:
//#define NOSOUND
#ifdef WITH_WIIUSE
#include <wiiuse.h>
#define MAX_WIIMOTES 1
#endif
#ifndef NOSOUND
#define MIX_CHANNELS 16
#include <SDL2/SDL_mixer.h>
#endif
#define VERSION "2.01"
#define SAVEGAMEVERSION 2
#include "declerations.h"
#define PI 3.14159265
#define RAD 6.28318531
#define BALL_MAX_DEGREE 2.61799388 //150+15 = 165 degrees
#define BALL_MIN_DEGREE 0.261799388 //15 degrees
#define FALSE 0
#define TRUE 1
//#define debugBall 1
// #define DEBUG_DRAW_BALL_QUAD
// #define DEBUG_NO_RELATIVE_MOUSE
// #define DEBUG_SHOW_MOUSE_COORDINATES
#define PO_COIN 0
#define PO_BIGBALL 1
#define PO_NORMALBALL 2
#define PO_SMALLBALL 3
#define PO_EXPLOSIVE 4
#define PO_GLUE 5
#define PO_MULTIBALL 6
#define PO_GROWPADDLE 7
#define PO_SHRINKPADDLE 8
#define PO_AIM 9
#define PO_GUN 10
#define PO_THRU 11
#define PO_LASER 12
#define PO_LIFE 13
#define PO_DIE 14
#define PO_DROP 15
#define PO_DETONATE 16
#define PO_EXPLOSIVE_GROW 17
#define PO_EASYBRICK 18
#define PO_NEXTLEVEL 19
#define PO_AIMHELP 20
//"Max powerups"
#define MAXPOTEXTURES 21
#define EASY 0
#define NORMAL 1
#define HARD 2
//Sound effects
#define SND_START 0
#define SND_BALL_HIT_BORDER 1
#define SND_BALL_HIT_PADDLE 2
#define SND_NORM_BRICK_BREAK 3
#define SND_EXPL_BRICK_BREAK 4
#define SND_GLASS_BRICK_HIT 5
#define SND_GLASS_BRICK_BREAK 6
#define SND_CEMENT_BRICK_HIT 7
#define SND_PO_HIT_BORDER 8
#define SND_GOOD_PO_HIT_PADDLE 9
#define SND_EVIL_PO_HIT_PADDLE 10
#define SND_SHOT 11
#define SND_DIE 12
#define SND_NEXTLEVEL 13
#define SND_GAMEOVER 14
#define SND_MENUCLICK 15
#define SND_DOOM_BRICK_BREAK 16
#define SND_GLUE_BALL_HIT_PADDLE 17
#define SND_INVISIBLE_BRICK_APPEAR 18
#define SND_HIGHSCORE 19
#define SND_BUY_POWERUP 20
#define SND_NORM_BRICK_BREAKB 21
#define SND_NORM_BRICK_BREAKC 22
#define SND_NORM_BRICK_BREAKD 23
#define SND_NORM_BRICK_BREAKE 24
#define SNDSAMPLES 25
using namespace std;
void writeSettings();
void initNewGame();
void pauseGame();
void resumeGame();
float rndflt(float total, float negative);
class ball;
class paddle_class;
float bounceOffAngle(GLfloat width, GLfloat posx, GLfloat hitx);
int globalTicks;
float globalMilliTicks;
int nonpausingGlobalTicks;
float nonpausingGlobalMilliTicks;
int globalTicksSinceLastDraw;
float globalMilliTicksSinceLastDraw;
struct pos {
GLfloat x;
GLfloat y;
};
struct difficultyStruct {
GLfloat ballspeed[3];
GLfloat maxballspeed[3];
GLfloat hitbrickinc[3];
GLfloat hitpaddleinc[3];
GLfloat slowdown[3];
GLfloat speedup[3];
};
struct difficultyStruct static_difficulty, difficulty;
struct settings {
string sndTheme,gfxTheme,lvlTheme;
bool cfgRes[2];
int displayToUse;
int resx;
int resy;
int fps;
bool showClock;
bool fullscreen;
bool showBg;
bool sound;
bool stereo;
bool eyeCandy;
bool particleCollide;
//Add to menu:
SDL_Keycode keyLeft, keyRight, keyShoot, keyNextPo, keyPrevPo, keyBuyPo;
float controlAccel;
float controlStartSpeed;
float controlMaxSpeed;
bool joyEnabled, joyIsDigital, joyIsPaddle;
int JoyCalMin, JoyCalMax, JoyCalHighJitter, JoyCalLowJitter;
};
struct scrollInfoScruct {
bool drop; //0 right, 1 left, 2 up, 3 down
unsigned int dropspeed;
unsigned int lastTick; // what was the time last they moved
};
struct privFileStruct {
string programRoot;
string settingsFile;
string saveGameFile;
string highScoreFile;
string screenshotDir;
};
struct privFileStruct privFile;
struct vars {
bool titleScreenShow;
int frame;
bool paused;
int menu;
int menuItem;
bool menuPressed;
int menuNumItems;
int menuJoyCalStage;
bool quit;
bool wiiConnect;
int numlevels;
bool transition_half_done;
bool clearScreen;
bool idiotlock; //transition
bool bricksHit; //tells the mainloop if it should copy the updated array of brick status.
GLfloat averageBallSpeed;
int showHighScores;
bool enterSaveGameName;
bool startedPlaying;
int effectnum;
struct scrollInfoScruct scrollInfo;
};
//Ting der har med spillogik at gøre
struct gameVars {
bool shopNextItem, shopPrevItem, shopBuyItem; //When set to 1 shop goes next or prev
int deadTime; //I hvor mange millisekunder har bolden intet rørt
bool nextlevel;
bool gameOver;
bool newLife;
bool newLevel; //Start en ny level
int bricksleft; //hvor mange brikker er der tilbage
};
struct gameVars gVar;
struct player_struct {
int coins;
int multiply;
bool powerup[MAXPOTEXTURES];
bool explodePaddle; //This lock makes the paddle explode and it won't come back until newlife.
int level;
int lives;
int difficulty;
int score;
};
int listSaveGames(string slotName[]);
void loadGame(int slot);
void saveGame(int slot, string name);
struct settings setting;
struct player_struct player;
struct player_struct SOLPlayer;
struct vars var;
displayClass display;
typedef GLfloat texPos[8];
#ifndef uint // WIN32
typedef unsigned int uint;
#endif
struct texProp {
GLuint texture; //Den GLtexture der er loaded
GLfloat xoffset;// Hvor stort er springet mellem hver subframe
GLfloat yoffset; //
int cols,rows; //hvor mange rækker og kolonner er der i denne textur
int ticks;
uint frames; //This many frames in each se
bool bidir; //Går Looper den fra 0 -> X - 0 eller fra 0 -> X -> 0
bool playing;
bool padding; //Bit of a nasty hack, but if a texture is padded with 1 pixel around each frame, this have to be set to 1
float pxw, pxh; //pixels width, and height
GLfloat glTexColorInfo[4];
GLfloat glParColorInfo[3]; //This and above replaced object::color and particle colors
string fileName; //Quite the fugly.. This will be set by readTexProps();
};
/* This function attempts to open path
It will first look for the file in ~/.config/sdl-ball/themes/theme/path
Then in DATADIR/themes/setting.theme/path
This way, each user can even override a part of a theme that exist both
in their own homedir and in the global themes dir.
If still no luck it will use the file from DATADIR/path
It will return the full qualified filename */
string useTheme(string path, string theme)
{
struct stat st;
string name;
if(theme.compare("default") != 0)
{
//Try in ~/.config/sdl-ball/themes/themename
name = privFile.programRoot+"/themes/"+ theme+"/"+path;
if( stat(name.data(), &st) == 0)
{
return(name);
}
//Try in DATADIR/themename/
name = DATADIR + theme+"/"+path;
if( stat(name.data(), &st) == 0)
{
return(name);
}
}
//Fall back on default file.
name = DATADIR"default/" + path;
if( stat(name.data(), &st) == 0)
{
return(name);
} else {
cout << "File Error: Could not find '" << path << "'" << endl;
return(name);
}
}
struct themeInfo {
string name;
bool snd,gfx,lvl,valid; //Valid means that there seems to be data of some kind (ie. not just an empty folder)
};
/* This function looks in ~/.config/sdl-ball/themes/
and in DATADIR/themes
for directories, it looks inside the dir
to decide if a theme contains:
gfx folder - this theme contains graphics
snd folder - this theme contains sound
level.txt - this theme contains levels.
It will return info even if the theme is not valid
It returns a vector of structs with info */
vector<struct themeInfo> getThemes() {
DIR *pdir;
struct dirent *pent;
struct stat st;
struct themeInfo ti;
string themeDir;
string temp;
vector<struct themeInfo> v;
for(int i=0; i < 2; i++)
{
if(i==0)
{
themeDir = privFile.programRoot + "/themes";
} else if(i==1)
{
themeDir = DATADIR;
}
pdir = opendir(themeDir.data());
if (pdir)
{
themeDir.append("/");
while ((pent=readdir(pdir))){
temp=pent->d_name;
//We're not going to read hidden files
if(temp[0] != '.')
{
temp= themeDir + pent->d_name;
//Check if file is a dir.
if(stat(temp.data(), &st) == 0)
{
ti.name = pent->d_name;
ti.valid = 0;
//Check if theme have graphics
temp=themeDir + pent->d_name +"/gfx";
if(stat(temp.data(), &st) == 0)
{
ti.gfx=1;
ti.valid=1;
} else {
ti.gfx=0;
}
//Check if theme have sound
temp=themeDir + pent->d_name +"/snd";
if(stat(temp.data(), &st) == 0)
{
ti.snd=1;
ti.valid=1;
} else {
ti.snd=0;
}
//Check if theme have levels
temp=themeDir + pent->d_name +"/levels.txt";
if(stat(temp.data(), &st) == 0)
{
ti.lvl=1;
ti.valid=1;
} else {
ti.lvl=0;
}
v.push_back(ti);
}
}
}
}
}
return(v);
}
#include "text.cpp"
glTextClass *glText; //Pointer to the object, since we can't init (load fonts) because the settings have not been read yet.
class textureClass {
private:
float age; //Hvor gammel er den frame vi er ved?
bool dir; //hvis dette er en animation der går frem og tilbage hvilken retning
uint lastframe; //check om det er den samme frame som sidst, så vi kan vide om vis skal opdatere cords
public:
uint frame; //hvilken frame er vi nået til i texturen (den er public så vi kan lave offset)
bool playing; //spiller vi?
bool firstFrame; //If this is the first frame
texPos pos; //Kordinater for den frame på texturen der er nu
texProp prop; //Properties for den textur som dette objekt har
textureClass() {
age=10000;
firstFrame=1;
lastframe=1000;
frame=1;
dir=0;
}
void play()
{
int col=0,row=0;
if(prop.playing)
{
//Skal vi skifte frame?
age += globalTicksSinceLastDraw;
if(age >= prop.ticks) //Denne frame har været vist længe nok
{
age=0.0;
if(!dir)
{
if(frame == prop.frames)
{
if(prop.bidir)
{
dir=1;
} else {
frame=1;
}
} else {
frame++;
}
}
if(dir) {
if(frame == 1)
{
dir=0;
frame=2;
} else {
frame--;
}
}
}
}
uint f=0;
if(frame != lastframe || firstFrame)
{
lastframe=frame;
firstFrame=0;
//hvor mange kolonner er der på en række
for(row=0; row < prop.rows; row++)
{
for(col=0; col < prop.cols; col ++)
{
f++;
if(f == frame)
{
//Øverst Venstre
pos[0] = (prop.xoffset*(float)col); //0.0;
pos[1] = (prop.yoffset*(float)row);//0.0;
//Øverst højre
pos[2] = (prop.xoffset*(float)col) + prop.xoffset;
pos[3] = (prop.yoffset*(float)row);//0.0;
//Nederst højre
pos[4] = (prop.xoffset*(float)col) + prop.xoffset; // 1
pos[5] = (prop.yoffset*(float)row) + prop.yoffset; // 1
//Nederst venstre
pos[6] = (prop.xoffset*(float)col);//0.0;
pos[7] = (prop.yoffset*(float)row) + prop.yoffset; //1
if(prop.padding)
{
pos[0] += 1.0 / prop.pxw;
pos[1] += 1.0 / prop.pxh;
pos[2] -= 1.0 / prop.pxw;
pos[3] += 1.0 / prop.pxh;
pos[4] -= 1.0 / prop.pxw;
pos[5] -= 1.0 / prop.pxh;
pos[6] += 1.0 / prop.pxw;
pos[7] -= 1.0 / prop.pxh;
}
}
}
}
}
}
};
/* This function reads textureProperties from fileName
and applies them to *tex */
class textureManager {
public:
bool load(string file, textureClass & tex)
{
SDL_Surface *temp = NULL;
GLint maxTexSize;
GLuint glFormat = GL_RGBA;
if(file.substr(file.length()-3,3).compare("jpg") == 0)
{
glFormat = GL_RGB;
}
glGetIntegerv(GL_MAX_TEXTURE_SIZE, &maxTexSize);
temp = IMG_Load(file.data());
if(temp == NULL)
{
cout << "Texture manager: " << file << " : "<< SDL_GetError() << endl;
SDL_FreeSurface( temp );
return(FALSE);
}
//Hvis større end tilladt:
if(temp->w > maxTexSize)
{
cout << "Texture manager: '" << file << "' texturesize too large." << endl;
SDL_FreeSurface( temp );
return(FALSE);
}
glGenTextures(1, &tex.prop.texture);
glBindTexture(GL_TEXTURE_2D, tex.prop.texture);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP );
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP );
glTexImage2D(GL_TEXTURE_2D, 0, glFormat, temp->w, temp->h, 0, glFormat, GL_UNSIGNED_BYTE, temp->pixels);
tex.prop.pxw = temp->w;
tex.prop.pxh = temp->h;
SDL_FreeSurface( temp );
return(TRUE);
}
void readTexProps(string fileName, textureClass & tex)
{
char rgba[4][5];
ifstream f;
string line,set,val;
f.open( fileName.data() );
if(f.is_open())
{
while(!f.eof())
{
getline(f, line);
if(line.find('=') != string::npos)
{
set=line.substr(0,line.find('='));
val=line.substr(line.find('=')+1);
if(set=="xoffset")
{
tex.prop.xoffset=atof(val.data());
} else if(set=="yoffset")
{
tex.prop.yoffset=atof(val.data());
} else if(set=="cols")
{
tex.prop.cols=atoi(val.data());
} else if(set=="rows")
{
tex.prop.rows=atoi(val.data());
} else if(set=="ticks")
{
tex.prop.ticks=atoi(val.data());
} else if(set=="frames")
{
tex.prop.frames=atoi(val.data());
} else if(set=="bidir")
{
tex.prop.bidir=atoi(val.data());
} else if(set=="playing")
{
tex.prop.playing=atoi(val.data());
} else if(set=="padding")
{
tex.prop.padding=atoi(val.data());
} else if(set=="texcolor")
{
//Color in hex RGBA
//Example:color=FFFFFFFF
sprintf(rgba[0], "0x%c%c", val[0], val[1]);
sprintf(rgba[1], "0x%c%c", val[2], val[3]);
sprintf(rgba[2], "0x%c%c", val[4], val[5]);
sprintf(rgba[3], "0x%c%c", val[6], val[7]);
tex.prop.glTexColorInfo[0] = 0.003921569 * strtol(rgba[0], NULL,16);
tex.prop.glTexColorInfo[1] = 0.003921569 * strtol(rgba[1], NULL,16);
tex.prop.glTexColorInfo[2] = 0.003921569 * strtol(rgba[2], NULL,16);
tex.prop.glTexColorInfo[3] = 0.003921569 * strtol(rgba[3], NULL,16);
} else if(set=="parcolor")
{
//Color in hex RGBA
//Example:color=FFFFFFFF
sprintf(rgba[0], "0x%c%c", val[0], val[1]);
sprintf(rgba[1], "0x%c%c", val[2], val[3]);
sprintf(rgba[2], "0x%c%c", val[4], val[5]);
tex.prop.glParColorInfo[0] = 0.003921569 * strtol(rgba[0], NULL,16);
tex.prop.glParColorInfo[1] = 0.003921569 * strtol(rgba[1], NULL,16);
tex.prop.glParColorInfo[2] = 0.003921569 * strtol(rgba[2], NULL,16);
} else if(set=="file")
{
tex.prop.fileName = val;
} else {
cout << "Error: '"<<fileName<<"'invalid setting '"<< set <<"' with value '" << val <<"'"<<endl;
}
}
}
//Load the texture if we have a filename.
if(tex.prop.fileName.length() > 1)
{
string name = "gfx/"+tex.prop.fileName;
load(useTheme(name,setting.gfxTheme), tex);
}
} else {
cout << "readTexProps: Cannot open '" << fileName << "'"<<endl;
}
}
};
#include "sound.cpp"
soundClass soundMan; //Public object so all objects can use it
#include "menu.cpp"
#include "scoreboard.cpp"
class object {
public:
// GLfloat color[3];
GLfloat opacity; //This is still used, because it can then be reset, and it's used for fading out bricks (i think)
GLfloat posx, posy;
GLfloat width,height;
GLuint dl; //opengl display list
bool active;
bool collide;
bool reflect; //NOTE: use this for bricks that are not going to reflect the ball? (trap brick? :D)
textureClass tex;
};
class paddle_class : public object {
private:
GLfloat growspeed;
GLfloat destwidth;
GLfloat aspect; //så meget stiger højden i forhold til bredden
bool growing;
public:
bool dead;
textureClass *layerTex;
paddle_class ()
{
init();
growing=0;
growspeed=0.05f;
aspect = 0.2f;
}
void init()
{
posy = -1.15;
width=0.1;
height=0.02;
dead=0;
}
void grow(GLfloat width)
{
destwidth = width;
growing = 1;
}
void draw()
{
if(!dead)
{
if(player.powerup[PO_DIE])
{
player.powerup[PO_DIE]=0;
dead=1;
width=0.0;
height=0.0;
}
if(growing)
{
GLfloat ix = growspeed * globalTicksSinceLastDraw;
width += ix;
if(width >= destwidth)
{
width = destwidth;
height = aspect*destwidth;
growing=0;
}
}
glLoadIdentity();
glTranslatef( posx, posy, -3.0 );
tex.play();
glBindTexture(GL_TEXTURE_2D, tex.prop.texture);
glColor4f( tex.prop.glTexColorInfo[0], tex.prop.glTexColorInfo[1], tex.prop.glTexColorInfo[2], tex.prop.glTexColorInfo[3] );
glBegin( GL_QUADS );
glTexCoord2f(tex.pos[0], tex.pos[1]); glVertex3f(-width,height, 0.0f );
glTexCoord2f(tex.pos[2], tex.pos[3]); glVertex3f( width,height, 0.0f );
glTexCoord2f(tex.pos[4], tex.pos[5]); glVertex3f( width,-height, 0.0f );
glTexCoord2f(tex.pos[6], tex.pos[7]); glVertex3f(-width,-height, 0.0f );
glEnd( );
//Hvis glue?
if(player.powerup[PO_GLUE])
{
glBindTexture(GL_TEXTURE_2D, layerTex[0].prop.texture);
glColor4f( layerTex[0].prop.glTexColorInfo[0], layerTex[0].prop.glTexColorInfo[1], layerTex[0].prop.glTexColorInfo[2], layerTex[0].prop.glTexColorInfo[3] );
glBegin( GL_QUADS );
glTexCoord2f(0.0f, 0.0f); glVertex3f(-width, height, 0.0f );
glTexCoord2f(1.0f, 0.0f); glVertex3f( width, height, 0.0f );
glTexCoord2f(1.0f, 0.99f); glVertex3f( width,-height, 0.0f );
glTexCoord2f(0.0f, 0.99f); glVertex3f(-width,-height, 0.0f );
glEnd( );
}
//Hvis gun
if(player.powerup[PO_GUN])
{
layerTex[1].play();
glBindTexture(GL_TEXTURE_2D, layerTex[1].prop.texture);
glColor4f( layerTex[1].prop.glTexColorInfo[0], layerTex[1].prop.glTexColorInfo[1], layerTex[1].prop.glTexColorInfo[2], layerTex[1].prop.glTexColorInfo[3] );
glBegin( GL_QUADS );
glTexCoord2f(layerTex[1].pos[0], layerTex[1].pos[1]); glVertex3f(-width, height*4, 0.0f );
glTexCoord2f(layerTex[1].pos[2], layerTex[1].pos[3]); glVertex3f( width, height*4, 0.0f );
glTexCoord2f(layerTex[1].pos[4], layerTex[1].pos[5]-0.01); glVertex3f( width,height, 0.0f );
glTexCoord2f(layerTex[1].pos[6], layerTex[1].pos[7]-0.01); glVertex3f(-width,height, 0.0f );
glEnd( );
}
}
}
};
//nasty fix to a problem
int nbrick[23][26];
int updated_nbrick[23][26];
class brick;
void makeExplosive(brick & b);
textureClass * texExplosiveBrick; //NOTE:Ugly
class brick : public object {
public:
int score; //Hvor meget gir den
bool destroytowin; // Skal den smadres for at man kan vinde?
char powerup;
char type;
GLfloat fade; //hvor meget brik
GLfloat fadespeed;
GLfloat zoomspeed;
GLfloat zoom;
bool isdyingnormally;
bool isexploding; //springer den i luften
int row; //what row is this brick in
int bricknum; //brick in this row
int hitsLeft; //Hvor mange gange skal denne brik rammes før den dør?
bool justBecomeExplosive; //If this brick just become a explosive one.
bool n(int dir)
{
switch(dir)
{
case 0: //Er der en brik til venstre for dig?
if(bricknum > 0)
{
if(nbrick[row][bricknum-1] != -1)
return(1);
}
break;
case 1: //Er der en brik til højre for dig?
if(bricknum < 25) //26
{
if(nbrick[row][bricknum+1] != -1)
return(1);
}
break;
case 2: //Er der en brik Ovenpå dig
if(row > 0)
{
if(nbrick[row-1][bricknum] != -1)
return(1);
}
break;
case 3: //Er der en brik nedenunder dig
if(row < 22) //23
{
if(nbrick[row+1][bricknum] != -1)
return(1);
}
break;
}
return(0);
}
void hit(effectManager & fxMan, pos poSpawnPos, pos poSpawnVel, bool ballHitMe);
void draw(brick bricks[], effectManager & fxMan)
{
if(isdyingnormally)
{
fade -= fadespeed * globalMilliTicksSinceLastDraw;
opacity = fade;
zoom -= zoomspeed * globalMilliTicksSinceLastDraw;
if(fade < 0.0)
active=0;
}
if(isexploding && !var.paused)
{
fade -= 7.0 * globalMilliTicksSinceLastDraw;
opacity = fade;
if(fade<0.0)
{
active=0;
pos spos,svel;
spos.x=posx;
spos.y=posy;
if(bricknum > 0)
{
if(nbrick[row][bricknum-1] != -1)
{
svel.x=rndflt(2,0)/3.0;
svel.y=rndflt(2,0)/3.0;
bricks[nbrick[row][bricknum-1]].hit(fxMan,spos,svel,0);
}
}
if(bricknum < 25)
{
if(nbrick[row][bricknum+1] != -1)
{
svel.x=rndflt(2,0)/3.0;
svel.y=rndflt(2,0)/3.0;
bricks[nbrick[row][bricknum+1]].hit(fxMan,spos,svel,0);
}
}
if(row > 0)
{
if(nbrick[row-1][bricknum] != -1)
{
svel.x=rndflt(2,0)/3.0;
svel.y=rndflt(2,0)/3.0;
bricks[nbrick[row-1][bricknum]].hit(fxMan,spos,svel,0);
}
}
if(row < 22)
{
if(nbrick[row+1][bricknum] != -1)
{
svel.x=rndflt(2,0)/3.0;
svel.y=rndflt(2,0)/3.0;
bricks[nbrick[row+1][bricknum]].hit(fxMan,spos,svel,0);
}
}
if(row > 0 && bricknum > 0)
{
if(nbrick[row-1][bricknum-1] != -1)
{
svel.x=rndflt(2,0)/3.0;
svel.y=rndflt(2,0)/3.0;
bricks[nbrick[row-1][bricknum-1]].hit(fxMan,spos,svel,0);
}
}
if(row > 0 && bricknum < 25)
{
if(nbrick[row-1][bricknum+1] != -1)
{
svel.x=rndflt(2,0)/3.0;
svel.y=rndflt(2,0)/3.0;
bricks[nbrick[row-1][bricknum+1]].hit(fxMan,spos,svel,0);
}
}
if(row < 22 && bricknum > 0)
{
if(nbrick[row+1][bricknum-1] != -1)
{
svel.x=rndflt(2,0)/3.0;
svel.y=rndflt(2,0)/3.0;
bricks[nbrick[row+1][bricknum-1]].hit(fxMan,spos,svel,0);
}
}
if(row < 22 && bricknum < 25)
{
if(nbrick[row+1][bricknum+1] != -1)
{
svel.x=rndflt(2,0)/3.0;
svel.y=rndflt(2,0)/3.0;
bricks[nbrick[row+1][bricknum+1]].hit(fxMan,spos,svel,0);
}
}
}
}