This repository has been archived by the owner on Jan 24, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
tedP.cpp
908 lines (789 loc) · 22.4 KB
/
tedP.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
//Program: Lab 9, Indivual Files, Editor Files
//Author: Ted Pascua
//Purpose: To Make it Easy to add any types of objects inside the game
// Run Executive ./tool
//
// //Instructions
// To Use Please, Enter Create Mode( press C and make blocks)
//
// Press S to save the files in. It will save as a test.ros in
// the same directory but will ask you to save a file in the
// terminal. That file will go into the data folder.
//
// Read the README.md for more instructions
//
// //Future Updates
// Easily Place Items
/*
======================+
Tool Editor |
======================+
Main_Center |
Platform_Editor |
Enemy_Editor |
Item_Editor |
Mouse_Check |
Key_Check |
Physics |
Drawing |
Storage_Editor |
Window_Setup |
======================+
*/
#define EDITOR_MODE
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <GL/glx.h>
#include <iomanip>
#include <iostream>
#include <sstream>
#include <string>
#include <sys/time.h>
#include <unistd.h>
#include <X11/Xlib.h>
#include <X11/keysym.h>
#include "Enemy.h"
#include "Item.h"
#include "Player.h"
#include "chadD.h" //#include "Platform.h"
#include "definitions.h"
#include "Object.h"
#include "sounds.cpp"
//#include "Attack.cpp"
#include "Storage.cpp"
#include "fmod.c"
//#include "AttackList.cpp"
#include "fastFont.cpp"
//#include "Storage.cpp"
using namespace std;
typedef double Vec[3];
//X Windows variables
Display *dpy;
Window win;
GLXContext glc;
//------------------------------
//Game Globals
//------------------------------
Player *hero;
Sprite currentTile;
Sprite ruler;
Enemy *enemies[MAX_ENEMIES];
Item *itemsHold[MAX_ITEMS];
int items_length = 0;
Platform *grounds[MAX_GROUNDS];
attack_list boxA;
int grounds_length = 0;
int enemies_length = 0;
int level = 0;
int i, j, bullets;
Bullet *bulletHead;
int roomX=WINDOW_HALF_WIDTH;
int roomY=WINDOW_HALF_HEIGHT;
int quit=0;
bool saving;
bool loading;
bool enemyEditor = 1;
bool itemEditor = 0;
bool create = 0;
bool tileMode = 0;
bool selecter = 0;
int holdID = -1;
int saveID = -1;
int enemyType = 0;
int creeperScore;
int fireUp = 0;
int fireDown = 0;
int pushingLaser = 0;
int fireShield = 0;
int speedArrow = 0;
int shield = 0;
int simpleBlast = 0;
int gravityBlast = 0;
//------------------------------
//Function Prototype
//------------------------------
int clickObject(int x, int y);
int clickEnemy(int x, int y);
void draging(int x, int y);
void initXWindows(void);
void init_opengl(void);
void cleanupXWindows(void);
void moveWindow(void);
void save();
void load();
#ifdef BACKUP
void copyToNew();
void convertSave();
void convertLoad();
#endif
void check_mouse(XEvent *e);
int check_keys (XEvent *e);
void makePlatform(int x, int y);
void setRow(int size);
void setColumn(int size);
void changeTileX();
void changeTileY();
void pickTile(int x, int y);
void renderHero(int x, int y);
void makeEnemy(int w, int h, Object *ground, int type);
void makeEnemy(int w, int h, int x, int y, int type);
Object createAI( int w, int h, Object *ground);
void deleteEnemy(int ind);
void makeItem(int w, int h, int x, int y);
void deleteItem(int id);
void render(void);
void renderEnemies(int x, int y);
void renderGrounds(int x, int y);
void renderSave();
void renderLoad();
void renderBox();
void renderRuler();
void movement(void);
bool detectCollide(Object *obj, Object *ground);
bool inWindow(Object &obj) {
return ((obj.getLeft() < (roomX+(WINDOW_HALF_WIDTH)) and
obj.getLeft() > (roomX-(WINDOW_HALF_WIDTH))) or
(obj.getRight() > (roomX-(WINDOW_HALF_WIDTH)) and
obj.getRight() < (roomX+(WINDOW_HALF_WIDTH))));
}
//====================================================================
// Main_Center
//====================================================================
int main(void) {
initXWindows(); init_opengl();
//declare hero object
//testHero = new Player();
currentTile.insert("./images/megaLevel.ppm", 1, 1);
currentTile.setSize(WINDOW_HALF_WIDTH/2, WINDOW_HALF_HEIGHT);
ruler.insert("./images/ruler.ppm", 1, 1);
ruler.setSize(WINDOW_HALF_WIDTH, WINDOW_HALF_HEIGHT);
//testHero->insert("./images/hero.ppm", 13, 1);
//testHero->setSize(44,48);
while (!quit) { //Staring Animation
while (XPending(dpy)) {
//Player User Interfaces
XEvent e; XNextEvent(dpy, &e);
check_mouse(&e);
quit = check_keys(&e);
}
movement(); render();
glXSwapBuffers(dpy, win);
}
cleanupXWindows(); return 0;
}
void init_opengl (void) {
//OpenGL initialization
glViewport(0, 0, WINDOW_WIDTH, WINDOW_HEIGHT);
//Initialize matrices
glMatrixMode(GL_PROJECTION); glLoadIdentity();
glMatrixMode(GL_MODELVIEW); glLoadIdentity();
//Set 2D mode (no perspective)
glOrtho(0, WINDOW_WIDTH, 0, WINDOW_HEIGHT, -1, 1);
glDisable(GL_LIGHTING);
glDisable(GL_DEPTH_TEST);
glDisable(GL_FOG);
glDisable(GL_CULL_FACE);
//Set the screen background color
glClearColor(0.0, 0.0, 0.0, 1.0);
glEnable(GL_TEXTURE_2D);
initFastFont();
}
//=====================================================================
// Platform_Editor
//=====================================================================
void makePlatform(int x, int y) {
cout << "Make Ground \n";
//storeIn.grounds[storeIn.grounds_length] = new Platform();
grounds[grounds_length] = new Platform();
grounds[grounds_length]->insert("./images/megaLevel.ppm", 10, 36);
int width = grounds[grounds_length]->getClipWidth();
int height = grounds[grounds_length]->getClipHeight();
grounds[grounds_length]->init(width, height, x, y);
grounds[grounds_length]->setupTile();
grounds[grounds_length]->setID(grounds_length);
cout << "What is " << grounds[grounds_length]->getID() << endl;
grounds[grounds_length]->setIndexXY(0, 0);
grounds[grounds_length]->setBackground(1);
grounds_length++;
}
void setRow(int size){
if(saveID < 0)
return;
int changeBy = 1;
if(size < 0)
changeBy = -1;
int spriteWidth = grounds[saveID]->getClipWidth() * changeBy;
int currentWidth = grounds[saveID]->getWidth();
if(changeBy == -1 && currentWidth <= -(spriteWidth))
return;
grounds[saveID]->setWidth(currentWidth + spriteWidth);
grounds[saveID]->setupTile();
}
void setColumn(int size){
if(saveID < 0)
return;
int changeBy = 1;
if(size < 0)
changeBy = -1;
int spriteHeight = grounds[saveID]->getClipHeight() * changeBy;
int currentHeight = grounds[saveID]->getHeight();
if(changeBy == -1 && currentHeight <= -(spriteHeight))
return;
grounds[saveID]->setHeight(spriteHeight + currentHeight);
grounds[saveID]->setupTile();
}
void changeTileX(){
if(saveID < 0)
return;
int x = grounds[saveID]->getIndexX();
int y = grounds[saveID]->getIndexY();
grounds[saveID]->setIndexXY(x+1,y);
}
void changeTileY(){
if(saveID < 0)
return;
int x = grounds[saveID]->getIndexX();
int y = grounds[saveID]->getIndexY();
grounds[saveID]->setIndexXY(x,y+1);
}
void pickTile(int x, int y){
if(saveID < 0)
return;
if(!tileMode)
return;
cout << "What is Point X " << x << endl;
cout << "What is Point Y " << y << endl;
int tileWidth = int(WINDOW_HALF_WIDTH/10);
//int amountY = currentTile.getRow();
int tileHeight = int(WINDOW_HEIGHT/36);
int tileX = int(ceil(x/tileWidth)) % 10 ;
int tileY = int(ceil(y/tileHeight)) % 36;
tileY = 36 - tileY;
cout << "What is TileX " << tileX << endl;
cout << "What is TileY " << tileY << endl;
grounds[saveID]->setIndexXY(tileX, tileY);
}
void deleteLastPlatform(){
if(grounds_length <= 0)
return;
grounds[grounds_length-1] = new Platform();
delete grounds[grounds_length-1];
grounds_length--;
cout << "What is Grounds Length " << grounds_length << endl;
}
void deletePlatform(){
if(grounds_length <= 0)
return;
if(saveID < 0)
return;
grounds[saveID] = new Platform();
delete grounds[saveID];
for(int i = saveID; i < grounds_length-1; i++){
grounds[i] = grounds[i + 1];
grounds[i]->setID(grounds[i]->getID()-1);
}
grounds[grounds_length-1] = new Platform();
delete grounds[grounds_length-1];
grounds_length--;
cout << "What is Grounds Length " << grounds_length << endl;
}
//=====================================================================
// Enemy_Editor
//=====================================================================
void makeEnemy(int w, int h, int x, int y, int type) {
if (enemies_length<MAX_ENEMIES){
enemies[enemies_length] = new Enemy(w, h, x, y, type);
switch (type){
case 1:
enemies[enemies_length]->insert("./images/enemy1.ppm", 26, 1);
enemies[enemies_length]->setBottom(-44);
enemies[enemies_length]->setLeft(-24);
enemies[enemies_length]->setRight(24);
enemies[enemies_length]->setTop(24);
enemies[enemies_length]->setHeight(25);
break;
case 2:
enemies[enemies_length]->insert("./images/enemy2_1.ppm", 26, 1);
/*enemies[enemies_length]->setBottom(-44);
enemies[enemies_length]->setLeft(-24);
enemies[enemies_length]->setRight(24);
enemies[enemies_length]->setTop(24);
enemies[enemies_length]->setHeight(25);
*/
break;
case 3:
enemies[enemies_length]->insert("./images/boss.ppm", 1, 1);
break;
}
enemies[enemies_length]->setID(enemies_length);
enemies_length++;
}
else{
cout << "Enemies array full!" << endl;
}
}
void deleteEnemy(){
if(enemies_length <= 0) return;
if(saveID < 0) return;
enemies[saveID] = new Enemy();
delete enemies[saveID];
for(int i = saveID; i < enemies_length-1; i++){
enemies[i] = enemies[i + 1];
enemies[i]->setID(enemies[i]->getID()-1);
}
enemies[enemies_length-1] = new Enemy();
delete enemies[enemies_length-1];
enemies_length--;
cout << "What is Enemies Length" << enemies_length << endl;
}
void enemySetWidth(){
}
void enemySetHeight(){
}
//=====================================================================
// Items Editor
//=====================================================================
void makeItem(int w, int h, int x, int y){
itemsHold[items_length] = new Item();
itemsHold[items_length]->setID(items_length);
itemsHold[items_length]->insert("./images/firemon.ppm", 1, 1);
itemsHold[items_length]->init(16,20,x,y);
items_length++;
}
void deleteItem(int id){
if (items_length <= 0) return;
items_length--;
delete itemsHold[id];
itemsHold[id] = itemsHold[items_length];
itemsHold[items_length]=NULL;
}
//=====================================================================
// Mouse_Check
//=====================================================================
static int savex = 0, savey = 0;
void check_mouse (XEvent *e) {
//static int n = 0;
if (e->type == ButtonRelease) {
cout << " Release\n";
holdID = -1;
return;
}
int take;
if (e->type == ButtonPress) {
//Left button was pressed
if (e->xbutton.button==1) {
//Enemy Editor Stuff
if(enemyEditor){
if(selecter == 1){
take = clickEnemy(savex, savey);
cout << "The id is: " << take << "\n";
saveID = holdID = take;
}
else
switch(enemyType){
case 0: makeEnemy(37, 80, savex, savey, 1); break;
case 1: makeEnemy(38, 37, savex, savey, 2); break;
case 2: makeEnemy(100, 100, savex, savey, 3); break;
}
}
//Platform Editor Stuff
else if(create == 1){
cout << " x " << savex << ", y " << savey << "\n";
makePlatform(savex, savey);
return;
}
else if(selecter == 1){
take = clickObject(savex, savey);
cout << "The Id is: " << take << "\n";
cout << "Platform ID X=" << grounds[take]->getCenterX() << "\n";
cout << "Platform ID Y=" << grounds[take]->getCenterY() << "\n";
saveID = holdID = take;
}
}
//Right Button was Pressed
if (e->xbutton.button==2) {
pickTile(e->xbutton.x, WINDOW_HEIGHT - e->xbutton.y);
return;
}
if (e->xbutton.button==3) {
pickTile(e->xbutton.x, WINDOW_HEIGHT - e->xbutton.y);
return;
}
}
if (e->xbutton.button==3) {
return;
}
//Did the mouse move?
if (savex != e->xbutton.x || savey != e->xbutton.y) {
int x = roomX - WINDOW_HALF_WIDTH;
int y = roomY - WINDOW_HALF_HEIGHT;
//int y = WINDOW_HEIGHT - e->xbutton.y;
savex = e->xbutton.x + x; //xpast = savex;
savey = WINDOW_HEIGHT - e->xbutton.y + y;
}
}
int clickObject(int x, int y){
for(int i = 0; i < grounds_length; i++){
if(grounds[i]->getRight() > x &&
grounds[i]->getLeft() < x &&
grounds[i]->getBottom() < y &&
grounds[i]->getTop() > y){
return grounds[i]->getID();
}
}
return -1;
}
int clickEnemy(int x, int y){
for(int i =0; i < enemies_length; i++){
if(enemies[i]->getRight() > x &&
enemies[i]->getLeft() < x &&
enemies[i]->getBottom() < y &&
enemies[i]->getTop() > y){
return i;
}
}
return -1;
}
void draging(int x, int y){
if(holdID < 0)
return;
if(enemyEditor) enemies[holdID]->setCenter(x, y);
else grounds[holdID]->setCenter(x, y);
}
//=====================================================================
// Key_Check
//=====================================================================
int check_keys (XEvent *e) {
//handle input from the keyboard
int key = XLookupKeysym(&e->xkey, 0);
if (e->type == KeyPress) {
if(key == XK_Escape or key == XK_q){
return 1;
}
if(key == XK_s){
save();
}
if(key == XK_l){
load();
}
if(key == XK_r){
if(enemyEditor){
enemyType++;
if(enemyType > 3) enemyType = 0;
}
else setRow(1);
}
if(key == XK_t){
setColumn(1);
}
if(key == XK_y){
setRow(-1);
}
if(key == XK_u){
setColumn(-1);
}
if(key == XK_j){
changeTileX();
}
if(key == XK_k){
changeTileY();
}
if(key == XK_b){
deleteLastPlatform();
}
if(key == XK_n){
if(enemyEditor) deleteEnemy();
else deletePlatform();
}
#ifdef BACKUP
if(key == XK_p){
copyToNew();
}
if(key == XK_o){
convertSave();
}
if(key == XK_i){
convertLoad();
}
#endif
if(key == XK_f ){
saveID = 0;
enemyEditor = !enemyEditor;
}
if(key == XK_a){
roomX -= 50;
}
if(key == XK_d){
roomX += 50;
}
if(key == XK_2){
roomX += 900;
}
if(key == XK_0){
roomX = 0+WINDOW_HALF_WIDTH;
roomY = 0+WINDOW_HALF_HEIGHT;
}
if(key == XK_1){
roomX -= 900;
}
if(key == XK_4){
roomY += 600;
}
if(key == XK_3){
roomY -= 600;
}
if(key == XK_Up){
roomY += 50;
}
if(key == XK_Down){
roomY -= 50;
}
if(key == XK_Left){
roomX -=50;
}
if(key == XK_Right){
roomX +=50;
}
if(key == XK_c){
create = 1; selecter = 0;
}
if(key == XK_x){
tileMode = !tileMode;
}
if(key == XK_v){
create = 0; selecter = 1;
}
}
else if (e->type == KeyRelease) {
}
return 0;
}
//=====================================================================
// Physics
//=====================================================================
void movement() {
draging(savex, savey);
}
bool detectCollide (Object *obj, Object *ground) {
//Gets (Moving Object, Static Object)
//Reture True if Moving Object Collides with Static Object
return (obj->getRight() > ground->getLeft() &&
obj->getLeft() < ground->getRight() &&
obj->getBottom() < ground->getTop() &&
obj->getTop() > ground->getBottom());
}
//=====================================================================
// Drawing
//=====================================================================
void renderOptions(){
if(enemyEditor == 1){
writeWords("Enemy Editor Mode", 25, 55);
if(enemyType == 0) writeWords("Enemy 0", 40, 80);
if(enemyType == 1) writeWords("Enemy 1", 40, 80);
if(enemyType == 2) writeWords("Enemy 2", 40, 80);
}
else writeWords("Platform Editor Mode", 25, 55);
if(create == 1) writeWords("Create Mode", 25, 25);
if(selecter == 1) writeWords("Select Mode", 25, 25);
if(tileMode == 1){
glPushMatrix(); glTranslatef(WINDOW_HALF_WIDTH/2, WINDOW_HALF_HEIGHT, 0);
currentTile.drawTile(0,0);
glPopMatrix();
}
}
void renderBox(){
glPushMatrix();
glColor3f(0,0,0);
glTranslatef(50, 275, 0); glBegin(GL_QUADS);
glVertex2i(-500,-100); glVertex2i(-500, 100);
glVertex2i(700, 100); glVertex2i(700, -100);
glEnd();
glPopMatrix();
}
void renderRuler(){
glPushMatrix();
glTranslatef(WINDOW_HALF_WIDTH, WINDOW_HALF_HEIGHT, 0);
ruler.drawTile(0,0);
glPopMatrix();
}
void renderSave(){
renderBox();
writeWords("Please Check Your Terminal", 50, 275);
writeWords("And Write Name of Saved File", 50, 250);
glXSwapBuffers(dpy, win);
}
void renderLoad(){
renderBox();
writeWords("Please Check Your Terminal", 50, 275);
writeWords("And Write Name Loaded File", 50, 250);
glXSwapBuffers(dpy, win);
}
void renderGrounds (int x, int y) {
// render grounds
for (i=0;i<grounds_length;i++) {
//if (inWindow(*(storeIn.grounds[i]))) {
//Platform
glPushMatrix();
glTranslatef(- x, - y, 0);
grounds[i]->drawRow(0,0);
glEnd(); glPopMatrix();
//}
}
}
void renderEnemies (int x, int y) {
for (int i=0;i<enemies_length;i++) {
//if (inWindow(*(enemies[i]))){
glPushMatrix();
glTranslatef(- x, - y, 0);
enemies[i]->draw();
glEnd(); glPopMatrix();
}
}
void renderHero (int x, int y) {
//Easy Drawing
glPushMatrix();
glTranslatef(-x, -y, 0);
//testHero->drawBox();
glPopMatrix();
}
void render () {
int x = roomX - WINDOW_HALF_WIDTH;
int y = roomY - WINDOW_HALF_HEIGHT;
glClear(GL_COLOR_BUFFER_BIT);
// Draw Background Falling Bits
renderRuler();
renderGrounds(x, y);
renderEnemies(x, y);
renderHero(x, y);
renderOptions();
}
//=====================================================================
// Storage Editor
//=====================================================================
#ifdef BACKUP
void convertSave(){
copyToNew();
cout << "Convert Saving \n";
ofstream dfs("backup.ros", ios::binary);
dfs.write((char *)&futureBox, sizeof(futureBox));
}
void convertLoad(){
ifstream dfs("backup.ros", ios::binary);
dfs.read((char *)&futureBox, sizeof(futureBox));
cout << "Convert Loading \n";
for(int i = 0; i < futureBox.grounds_length; i++){
grounds[i] = &futureBox.grounds[i];
grounds[i]->reInitSprite();
grounds_length++;
}
}
void copyToNew(){
futureBox.grounds_length = grounds_length;
for(int i = 0; i < grounds_length; i++){
futureBox.grounds[i] = *grounds[i];
}
}
#endif
void save(){
for(int i = 0; i < grounds_length; i++){
storeIn.grounds[i] = *grounds[i];
}
for(int i =0; i < enemies_length; i++){
storeIn.enemies[i] = *enemies[i];
}
storeIn.grounds_length = grounds_length;
storeIn.enemies_length = enemies_length;
cout << "Saving \n";
ofstream dfs("test.ros", ios::binary);
dfs.write((char *)&storeIn, sizeof(storeIn));
//convertSave();
if(OPTIONAL_STORAGE != 1) return;
renderSave();
cout << "Save File As: ";
string fileName; cin >> fileName; fileName.append(".ros");
string folder = "./data/"; folder.append(fileName);
char charFileName[50]; strcpy(charFileName, folder.c_str());
ofstream saveFileAs(charFileName, ios::binary);
saveFileAs.write((char *)&storeIn, sizeof(storeIn));
}
void quickSave(){
cout << "Saving \n";
ofstream dfs("test.ros", ios::binary);
dfs.write((char *)&storeIn, sizeof(storeIn));
}
void load(){
renderLoad();
string fileName;
cout << "Load in: ";
cin >> fileName;
string folder = "./data/"; folder.append(fileName);
if (folder.find(".ros") != string::npos) {
cout << "File Exist, Will Load\n";
}else{
cout << "! Will Only take .ros files !\n"; return;
}
char charFileName[50];
strcpy(charFileName, folder.c_str());
ifstream dfs(charFileName, ios::binary);
cout << "what is the sizeOf(storeIn)" << sizeof(storeIn) << "\n";
dfs.read((char *)&storeIn, sizeof(storeIn));
cout << "Loading \n";
for(int i = 0; i < storeIn.grounds_length; i++){
grounds[i] = &storeIn.grounds[i];
grounds[i]->reInitSprite();
grounds_length++;
}
enemies_length = 0;
for(int i = 0; i < storeIn.enemies_length; i++){
enemies[i] = &storeIn.enemies[i];
enemies[i]->reInitSprite();
enemies_length++;
}
cout << "Loading Finished \n";
}
void quickLoad(){
cout << "Load in \n";
ifstream dfs("test.ros", ios::binary);
cout << "what is the sizeOf(storeIn)" << sizeof(storeIn) << "\n";
dfs.read((char *)&storeIn, sizeof(storeIn));
}
//=====================================================================
// Window Setup
//=====================================================================
void set_title (void) { //Set the window title bar.
XMapWindow(dpy, win); XStoreName(dpy, win, "Revenge of the Code");
}
void cleanupXWindows (void) { //do not change
XDestroyWindow(dpy, win); XCloseDisplay(dpy);
}
void initXWindows (void) { //do not change
GLint att[] = { GLX_RGBA, GLX_DEPTH_SIZE, 24, GLX_DOUBLEBUFFER, None };
int w=WINDOW_WIDTH, h=WINDOW_HEIGHT;
dpy = XOpenDisplay(NULL);
if (dpy == NULL) {
cout << "\n\tcannot connect to X server\n" << endl;
exit(EXIT_FAILURE);
}
Window root = DefaultRootWindow(dpy);
XVisualInfo *vi = glXChooseVisual(dpy, 0, att);
if (vi == NULL) {
cout << "\n\tno appropriate visual found\n" << endl;
exit(EXIT_FAILURE);
}
Colormap cmap = XCreateColormap(dpy, root, vi->visual, AllocNone);
XSetWindowAttributes swa;
swa.colormap = cmap;
swa.event_mask = ExposureMask | KeyPressMask | KeyReleaseMask |
ButtonPress | ButtonReleaseMask |
PointerMotionMask |
StructureNotifyMask | SubstructureNotifyMask;
win = XCreateWindow(dpy, root, 0, 0, w, h, 0, vi->depth,
InputOutput, vi->visual, CWColormap | CWEventMask, &swa);
set_title();
glc = glXCreateContext(dpy, vi, NULL, GL_TRUE);
glXMakeCurrent(dpy, win, glc);
}