-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
865 lines (578 loc) · 27.1 KB
/
Copy pathmain.cpp
File metadata and controls
865 lines (578 loc) · 27.1 KB
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
//default cpp libraries
#include <unistd.h> //to get the current working directory
#include <cmath>
#include <iostream>
#include <fstream>
#include <string>
//simple and fast multimedia library
#include <SFML/Graphics.hpp>
//my own classes
#include "star_cluster.h"
#include "level.h"
#include "button.h"
//GLOBAL VARIABLES
//path of the current working directory
std::string currentworkingdirectory = get_current_dir_name();
//window size
float stretch = 0.9;
float width = 2560*stretch;
float height = 1440*stretch;
//math
double pi = 3.141592653589793;
//END OF GLOBAL VARIABLES
//AUXILIARY FUNCTIONS
//returns x as a string up to custom digits after the comma
std::string rounded(double x, int digits) {
//take the part in front of the comma, if x = X2X1.x1x2x3 then only take X1X2 to the string for now
std::string result = std::to_string((int)(x)) + ".";
//cutoff the part in front of the comma, such that y = 0.x1x2x3 instead of X2X1.x1x2x3
double y = x- (int)(x);
for (int i = 1; i <= digits; i++) {
//add the next digit after the comma. if y = 0.y1y2y3 this adds y1
result = result + std::to_string((int)(10*y));
//create y1.y2y3 and subtract y1.0 in order to be able to do the next iteration analogously
y = 10*y - (int)(10*y);
}
return result;
}
//setup a sprite based on a png. the given position is in screen coordinates in percent (values between 0 and 1).
//scaling works thus: : all textures are designed as if the window was 2560x1440. But it is stretch*2560 x stretch*1440.
void setup_sprite(sf::Sprite& sprite, sf::Texture& texture, std::string png, float x, float y, bool centered_origin = false, bool centered_bottom = false) {
//load png
texture.loadFromFile(currentworkingdirectory + "/Textures/T_" + png);
//make it look smooth
texture.setSmooth(true);
//assign the texture
sprite.setTexture(texture);
if (centered_origin) {
//change the sprite origin to the center
sprite.setOrigin(texture.getSize().x/2, texture.getSize().y/2);
}
if (centered_bottom) {
//change the sprite origin to the center
sprite.setOrigin(sprite.getOrigin().x, texture.getSize().y);
}
//set the position
sprite.setPosition(x*width,y*height);
//set scale according to the window size
sprite.setScale(stretch, stretch);
}
void setup_text(sf::Text& text, sf::Font& font, int size, sf::Color color, float x, float y, bool center_origin = false) {
//choose the font
text.setFont(font);
//set the character size
text.setCharacterSize(size*stretch); // in pixels, not points!
//set the color
text.setFillColor(color);
//center, if so desired
if (center_origin) {
text.setOrigin(text.getLocalBounds().width/2,text.getLocalBounds().height/2);
}
//set the position
text.setPosition(x*width, y*height);
}
//END OF AUXILIARY FUNCTIONS
//MAIN PROGRAM
int main()
{
//RENDERING BUISNESS
sf::ContextSettings settings;
settings.antialiasingLevel = 8;
//create the render window
sf::RenderWindow window(sf::VideoMode(width, height), "Space Monkeys", sf::Style::Default, settings);
//the game view, this is the game world. this view should be used per default
sf::View gameview(sf::FloatRect(0.f, 0.f, width, height));
//gui view, this is the user interface world and never moves or scales. gui elements should only be drawn when this view is active
sf::View guiview(sf::FloatRect(0.f, 0.f, width, height));
//font for all sorts of texts
sf::Font font;
font.loadFromFile(currentworkingdirectory + "/Fonts/Capsule.ttf");
//END OF RENDERING BUISNESS
//GUI ELEMENTS
//TITLEPAGE
sf::Sprite gui_titlepage;
sf::Texture gui_titlepage_tex;
setup_sprite(gui_titlepage,gui_titlepage_tex,"Titlepage.png",0,0);
button button_play(0,"Play",0.05,0.95,width,height,stretch,false);
button button_show_controls(1, "Controls",0.25,0.95,width,height,stretch,false);
sf::Text text_title;
setup_text(text_title, font, 200, sf::Color::White, 0.05, 0.05);
text_title.setString("Space\nMonkeys");
text_title.setStyle(sf::Text::Bold);
sf::Text text_tutorial;
setup_text(text_tutorial, font, 35, sf::Color::White, 0.6, 0.4);
text_tutorial.setString("Space ship controls:\n\nLaunch Spacebar\nRotate launch velocity A and D\nScale launch velocity W and S\nFine Adjustments Hold Shift\n\n\n\n\nLevel Controls:\n\nReset Level R\nChange play rate Q and E\n\nZoom Scroll\nReset Zoom Middle Mouse\n\nGo to menu Escape");
//END OF TITLEPAGE
//LEVEL MENU
//not used
sf::Sprite objective;
sf::Texture objective_tex;
setup_sprite(objective, objective_tex, "Objective.png", 0.05, 0.5);
//END OF LEVEL MENU
//HUD
//general
sf::Sprite hud;
sf::Texture hud_tex;
setup_sprite(hud,hud_tex,"HUD.png",0,0);
sf::Text text_time_factor;
setup_text(text_time_factor, font, 47, sf::Color(255,255,255), 0.055, 0.017);
//physical stats
sf::Text text_time_dilation;
setup_text(text_time_dilation, font, 47, sf::Color(255,255,255), 0.58, 0.898);
sf::Text text_speed;
setup_text(text_speed, font, 47, sf::Color(255,255,255), 0.32, 0.898);
//maximal dilation indicator
sf::RectangleShape box_max_dilation(sf::Vector2f(180.f*stretch, 300.f*stretch));
box_max_dilation.setOrigin(0,box_max_dilation.getSize().y);
box_max_dilation.setPosition(0.9*width,0.96*height);
box_max_dilation.setFillColor(sf::Color(2.4*44,2.4*100,2.4*14));
sf::Text text_maximal_time_dilation;
setup_text(text_maximal_time_dilation, font, 47, sf::Color(2.4*44,2.4*100,2.4*14), 0.9, 0.96);
//velocity arrow
sf::Sprite velocity_arrow;
sf::Texture velocity_arrow_tex;
setup_sprite(velocity_arrow,velocity_arrow_tex,"Arrow.png",0,0);
velocity_arrow.setOrigin(velocity_arrow_tex.getSize().x/2, velocity_arrow_tex.getSize().y);
//goal reached screen
sf::Text text_banana_delivered;
sf::Text text_max_dilation_delivered;
setup_text(text_banana_delivered, font, 60, sf::Color::White, 0.5, 0.05);
setup_text(text_max_dilation_delivered, font, 35, sf::Color(2.4*44,2.4*100,2.4*14), 0.5, 0.1);
text_banana_delivered.setString("Bananas delivered");
text_banana_delivered.setPosition(text_banana_delivered.getPosition().x-text_banana_delivered.getLocalBounds().width/2,text_banana_delivered.getPosition().y);
text_max_dilation_delivered.setPosition(text_banana_delivered.getPosition().x,text_max_dilation_delivered.getPosition().y);
//END OF HUD
//END OF GUI ELEMENTS
//ADMIN VARIABLES
std::string active_star_cluster_name = "Alphani";
star_cluster active_star_cluster(active_star_cluster_name, width, height, stretch);
int amount_levels = active_star_cluster.getAmountStars();
level active_level;
int active_level_number = 1;
bool on_titlepage = true;
bool in_level_menu = false;
bool in_level = false;
bool show_controls = false;
//END OF ADMIN VARIABLES
//GAMEPLAY VARIABLES
//world time
double t = 0;
//world delta time, later it will be determined by the frametime to guarante that the simulation runs in real time
double dt = 0;
//clocks
//start a clock to measure the time that passed in the last frame
sf::Clock clock;
//a clock to measure the time between reaching the goal or crashing and automatic restaring of the level
sf::Clock clock_time_since_end;
//the current zoom factor. can be adjusted by player input and automatically if the player ship leaves the view.
float zoom = 1;
//to adjust how fast the simulation goes, and what the default should be
double default_time_factor = 24;
double time_factor = default_time_factor;
//current and biggest achieved time dilation
double Lorentzfactor = 1;
double maximal_Lorentzfactor = 1;
//booleans
bool launched = false;
bool reached_goal = false;
bool crashed = false;
//END OF GAMEPLAY VARIABLES
//INPUT VARIABLES
//deltas to adjust initial speed
double delta_modulus = 0.0005;
double delta_angle = 0.002;
//chosen angles. these are used to restart with the same settings you launched it.
double modulus;
double angle;
//END OF INPUT VARIABLES
//set the default star_cluster active
active_star_cluster.change_star_cluster(active_star_cluster_name, width, height, stretch);
//for safety, set level 1 as active.
active_level.change_level(active_level_number, width, height, stretch);
//GAME LOOP
while (window.isOpen())
{
//measure the time that passed in the last loopiteration and use it here as dt (so we are one behind). the timefactor is used to run the time at a higher rate, say at 5x
dt = clock.restart().asSeconds();
//EVENT POLLING
sf::Event event;
while (window.pollEvent(event)) {
//SWITCH BETWEEN DIFFERENT EVENT TYPES
switch (event.type) {
// window closed
case sf::Event::Closed:
window.close();
break;
//All keyboard events
case sf::Event::KeyPressed:
//close the game
if (event.key.code == sf::Keyboard::Escape) {
if (on_titlepage) {
window.close();
}
else if (in_level_menu) {
show_controls = false;
on_titlepage = true;
in_level_menu = false;
}
else if (in_level) {
in_level_menu = true;
in_level = false;
//reset the zoom
gameview.zoom(1/zoom);
zoom = 1;
}
}
//launching the player
if (event.key.code == sf::Keyboard::Space) {
if (in_level && !launched && !reached_goal && !crashed) {
launched = true;
modulus = active_level.getPlayer().get_chart_velocity_modulus();
angle = active_level.getPlayer().get_chart_velocity_angle();
}
}
//reset the level
if (event.key.code == sf::Keyboard::R) {
if (in_level) {
//reset the gameplay variables to default
launched = false;
reached_goal = false;
crashed = false;
Lorentzfactor = 1;
maximal_Lorentzfactor = 1;
t = 0;
//reset the level by forcing it to reload its data from the input file (we change the level to itself).
active_level.change_level(active_level_number, width, height, stretch);
//set initial speed to what we had previously
active_level.getPlayer().set_chart_velocity(modulus, angle, true);
}
}
//increase and decrease the time factor
if (in_level && event.key.code == sf::Keyboard::Q) {
if (time_factor == 12) {
time_factor = 1;
}
else if (time_factor == 24) {
time_factor = 12;
}
else if (time_factor > 24) {
time_factor = time_factor / 4;
}
}
if (in_level && event.key.code == sf::Keyboard::E) {
if (time_factor == 1) {
time_factor = 12;
}
else if (time_factor == 12) {
time_factor = 24;
}
else if (time_factor < 384) {
time_factor = time_factor * 4;
}
}
//for people who dont have a mouse: zooming with keyboard
if (event.key.code == sf::Keyboard::Up && in_level) {
//apply the zoom
gameview.zoom(1/1.05);
//update what zoom factor we have
zoom = zoom/1.05;
}
if (event.key.code == sf::Keyboard::Down && in_level) {
//apply the zoom
gameview.zoom(1.05);
//update what zoom factor we have
zoom = zoom*1.05;
}
if (event.key.code == sf::Keyboard::Z && in_level) {
//reset the zoom
gameview.zoom(1/zoom);
zoom = 1;
}
break; //end of keyboard events
//mouse click events
case sf::Event::MouseButtonPressed:
if (event.mouseButton.button == sf::Mouse::Left) {
//on the title page, check if we pressed the play button
if (on_titlepage) {
if (button_play.pressed(event.mouseButton.x, event.mouseButton.y) == 0) {
//set the game in the correct state
on_titlepage = false;
in_level_menu = true;
}
if (button_show_controls.pressed(event.mouseButton.x, event.mouseButton.y) == 1) {
if (show_controls) {
show_controls = false;
}
else {
show_controls = true;
}
}
}
//in the level menu, loop through all level buttons and see if any was clicked. if so make this the active level
else if (in_level_menu) {
for (int i = 0; i < amount_levels; i++) {
//take into account the zoom of the gameview by converting to world coordinates (where the world is the gameview).
float x_mouse = window.mapPixelToCoords(sf::Vector2i(event.mouseButton.x, event.mouseButton.y), gameview).x;
float y_mouse = window.mapPixelToCoords(sf::Vector2i(event.mouseButton.x, event.mouseButton.y), gameview).y;
//check if the i-th star sytem was pressed (by returning not -1) and if so set it's id as the active_level_number
int id_clicked = active_star_cluster.getStar(i).pressed(x_mouse,y_mouse);
if (id_clicked != -1) {
//select the clicked level id as the active one
active_level_number = id_clicked;
//set correct game state
in_level_menu = false;
in_level = true;
//reset the zoom
gameview.zoom(1/zoom);
zoom = 1;
//reset the timefactor
time_factor = default_time_factor;
//reset gameplay variables to default
launched = false;
reached_goal = false;
crashed = false;
Lorentzfactor = 1;
maximal_Lorentzfactor = 1;
t = 0;
//actually change to the desired level
active_level.change_level(active_level_number, width, height, stretch);
modulus = active_level.getPlayer().get_chart_velocity_modulus();
angle = active_level.getPlayer().get_chart_velocity_angle();
} //endif
} //end loop
} //end of left click
}
if (event.mouseButton.button == sf::Mouse::Middle && (in_level || in_level_menu)) {
//reset the zoom
gameview.zoom(1/zoom);
zoom = 1;
}
break; //end of mouse click events
//mouse scroll events
case sf::Event::MouseWheelScrolled:
//only catch the normal scrolling (not sideways), and only if we are actually in the level
if (event.mouseWheelScroll.wheel == sf::Mouse::VerticalWheel && (in_level || in_level_menu)) {
//scroll up = zoom in
if (event.mouseWheelScroll.delta == -1) {
//apply the zoom
gameview.zoom(1.05);
//update what zoom factor we have
zoom = zoom*1.05;
}
//scroll down = zoom out
else if (event.mouseWheelScroll.delta == 1) {
//apply the zoom
gameview.zoom(1/1.05);
//update what zoom factor we have
zoom = zoom/1.05;
}
}
break; //end of mouse scroll events
// we don't process other types of events
default:
break;
} //END OF SWITCH OF EVENT TYPES
}//END OF EVENT POLLING
//GLOBAL INPUTS
//increase the initial speed before launch
if (in_level && !launched && !reached_goal && !crashed && sf::Keyboard::isKeyPressed(sf::Keyboard::W)) {
if (sf::Keyboard::isKeyPressed(sf::Keyboard::LShift)) {
active_level.getPlayer().stretch_chart_velocity(delta_modulus/10,true);
}
else {
active_level.getPlayer().stretch_chart_velocity(delta_modulus,true);
}
modulus = active_level.getPlayer().get_chart_velocity_modulus();
angle = active_level.getPlayer().get_chart_velocity_angle();
}
if (in_level && !launched && !reached_goal && !crashed && sf::Keyboard::isKeyPressed(sf::Keyboard::S)) {
if (sf::Keyboard::isKeyPressed(sf::Keyboard::LShift)) {
active_level.getPlayer().stretch_chart_velocity(-delta_modulus/10,true);
}
else {
active_level.getPlayer().stretch_chart_velocity(-delta_modulus,true);
}
modulus = active_level.getPlayer().get_chart_velocity_modulus();
angle = active_level.getPlayer().get_chart_velocity_angle();
}
//turn the initial velocity before launch
if (in_level && !launched && !reached_goal && !crashed && sf::Keyboard::isKeyPressed(sf::Keyboard::A)) {
if (sf::Keyboard::isKeyPressed(sf::Keyboard::LShift)) {
active_level.getPlayer().rotate_chart_velocity(delta_angle/10, true);
}
else {
active_level.getPlayer().rotate_chart_velocity(delta_angle, true);
}
modulus = active_level.getPlayer().get_chart_velocity_modulus();
angle = active_level.getPlayer().get_chart_velocity_angle();
}
if (in_level && !launched && !reached_goal && !crashed && sf::Keyboard::isKeyPressed(sf::Keyboard::D)) {
if (sf::Keyboard::isKeyPressed(sf::Keyboard::LShift)) {
active_level.getPlayer().rotate_chart_velocity(-delta_angle/10, true);
}
else {
active_level.getPlayer().rotate_chart_velocity(-delta_angle, true);
}
modulus = active_level.getPlayer().get_chart_velocity_modulus();
angle = active_level.getPlayer().get_chart_velocity_angle();
}
//END OF GLOBAL INPUTS
//LEVEL MENU SIMULATION PART
//do this in titlepage, level menu and level on purpose, for immersion the cluster should always run
active_star_cluster.simulate(dt,4);
//END OF LEVEL MENU SIMULATION PART
//GAMEPLAY
//IN LEVEL: main purpose is to simulate the player within the active_level
if (in_level) {
if (!launched && !crashed && !reached_goal) {
//put the velocity arrow to the player
velocity_arrow.setPosition(active_level.getPlayer().getSprite().getPosition());
velocity_arrow.setRotation(active_level.getPlayer().getSprite().getRotation());
velocity_arrow.setScale(1,1+2*active_level.getPlayer().get_chart_velocity_modulus());
}
//do the physics simulation
active_level.simulate(time_factor*dt, time_factor, launched, reached_goal);
if (launched) {
//retrieve the current time dilation
Lorentzfactor = active_level.getPlayer().getLorentzfactor();
}
//if the current time dilation exceeds the biggest one so far, replace that one
if (!launched && !reached_goal && !crashed) {
//to update ui with initial Lorentzfactor
Lorentzfactor = active_level.getPlayer().calcgetLorentzfactor(dt);
//to scale the box correctly
maximal_Lorentzfactor = active_level.getPlayer().calcgetLorentzfactor(dt);
}
else if (Lorentzfactor > maximal_Lorentzfactor) {
maximal_Lorentzfactor = Lorentzfactor;
}
//update the gui texts
text_time_dilation.setString(rounded(Lorentzfactor,3));
text_maximal_time_dilation.setString(rounded(maximal_Lorentzfactor,3));
text_speed.setString(rounded(active_level.getPlayer().spatial_speed(),3) + "c");
text_time_factor.setString(std::to_string((int)(time_factor)));
text_max_dilation_delivered.setString("with top dilation "+rounded(maximal_Lorentzfactor,3));
//stretch the box of the maximal time dilation
box_max_dilation.setScale(1,1+2/pi*atan(0.1*(maximal_Lorentzfactor-1))*3);
text_maximal_time_dilation.setPosition(box_max_dilation.getPosition().x,box_max_dilation.getPosition().y-(1+2/pi*atan(0.1*(maximal_Lorentzfactor-1))*3)*box_max_dilation.getSize().y-1.2*text_maximal_time_dilation.getCharacterSize());
//check for collision with the goal, but only if we are not currently in a state of having hit the goal and waiting for the next thing to happen.
if (active_level.player_hit_goal() && !reached_goal && !crashed) {
launched = false;
reached_goal = true;
clock_time_since_end.restart();
}
//check for collision with another station but only if we are not currently crashed already. if it hits, the checker function automatically explodes the player and make the other station invisible
if (active_level.player_hit_obstacle() && !crashed) {
launched = false;
crashed = true;
clock_time_since_end.restart();
}
//check if the player has been swallowed by the blackhole
if (active_level.getPlayer().getSwallowed() && !crashed) {
launched = false;
crashed = true;
clock_time_since_end.restart();
}
/*
//if we have reached the end by reaching the goal, automatically load the next level after 5 seconds
if (reached_goal && clock_time_since_end.getElapsedTime().asSeconds() > 5 && active_level_number < amount_levels) {
//reset gameplay variables to default
launched = false;
reached_goal = false;
crashed = false;
Lorentzfactor = 1;
maximal_Lorentzfactor = 1;
t = 0;
//make the next level the current level
active_level_number += 1;
//reload the level
active_level.change_level(active_level_number, width, height, stretch);
}
*/
//if we have reached the end by reaching the goal, automatically go back to the level menu after 5 seconds
if (reached_goal && clock_time_since_end.getElapsedTime().asSeconds() > 5) {
//reset gameplay variables to default
launched = false;
reached_goal = false;
crashed = false;
in_level_menu = true;
in_level = false;
//reset the zoom
gameview.zoom(1/zoom);
zoom = 1;
}
//if we have reached the end by crashing, automatically restart after 2.5 seconds
if (crashed && clock_time_since_end.getElapsedTime().asSeconds() > 2.5) {
//reset gameplay variables to default
launched = false;
reached_goal = false;
crashed = false;
Lorentzfactor = 1;
maximal_Lorentzfactor = 1;
t = 0;
//reload the level
active_level.change_level(active_level_number, width, height, stretch);
//set initial speed to what we had previously
active_level.getPlayer().set_chart_velocity(modulus, angle, true);
}
}
//END OF IN LEVEL
//END OF GAMEPLAY
//DRAWING: first use the the game view to draw game elements, then switch to the gui view and draw the gui elements
window.clear();
//GAME VIEW
window.setView(gameview);
if (in_level_menu) {
window.draw(active_star_cluster.getCentralBody());
for (int i = 0; i < active_star_cluster.getAmountStars(); i++) {
window.draw(active_star_cluster.getStar(i).getSprite());
window.draw(active_star_cluster.getStar(i).getText());
}
}
if (in_level) {
window.draw(active_level.getCentralBody());
for (int i = 0; i < active_level.getAmountStations(); i++) {
window.draw(active_level.getStation(i).getTrail());
window.draw(active_level.getStation(i).getSprite());
}
if (!launched && !crashed && !reached_goal && active_level.getPlayer().spatial_speed() > 0) {
window.draw(velocity_arrow);
}
window.draw(active_level.getPlayer().getTrail());
window.draw(active_level.getPlayer().getSprite());
}
//GUI VIEW
window.setView(guiview);
if (on_titlepage) {
window.draw(gui_titlepage);
window.draw(button_play.getSprite());
window.draw(button_play.getText());
window.draw(button_show_controls.getSprite());
window.draw(button_show_controls.getText());
window.draw(text_title);
if (show_controls) {
window.draw(text_tutorial);
}
}
else if (in_level_menu) {
}
else if (in_level) {
window.draw(hud);
window.draw(text_time_dilation);
window.draw(box_max_dilation);
window.draw(text_maximal_time_dilation);
window.draw(text_speed);
window.draw(text_time_factor);
if (reached_goal) {
window.draw(text_banana_delivered);
window.draw(text_max_dilation_delivered);
}
}
//display everything
window.display();
//END OF DRAWING
}
//END OF GAME LOOP
return 0;
}
//END OF MAIN PROGRAM