add code to debug collision rectangles
[supertux.git] / src / game_session.cpp
1 //  $Id$
2 // 
3 //  SuperTux
4 //  Copyright (C) 2000 Bill Kendrick <bill@newbreedsoftware.com>
5 //  Copyright (C) 2004 Tobias Glaesser <tobi.web@gmx.de>
6 //  Copyright (C) 2004 Ingo Ruhnke <grumbel@gmx.de>
7 //
8 //  This program is free software; you can redistribute it and/or
9 //  modify it under the terms of the GNU General Public License
10 //  as published by the Free Software Foundation; either version 2
11 //  of the License, or (at your option) any later version.
12 //
13 //  This program is distributed in the hope that it will be useful,
14 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
15 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 //  GNU General Public License for more details.
17 // 
18 //  You should have received a copy of the GNU General Public License
19 //  along with this program; if not, write to the Free Software
20 //  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
21 #include <config.h>
22
23 #include <fstream>
24 #include <sstream>
25 #include <cassert>
26 #include <cstdio>
27 #include <cstdlib>
28 #include <cmath>
29 #include <cstring>
30 #include <cerrno>
31 #include <unistd.h>
32 #include <ctime>
33 #include <stdexcept>
34
35 #include <SDL.h>
36
37 #include "game_session.hpp"
38 #include "log.hpp"
39 #include "worldmap.hpp"
40 #include "mainloop.hpp"
41 #include "video/screen.hpp"
42 #include "audio/sound_manager.hpp"
43 #include "gui/menu.hpp"
44 #include "sector.hpp"
45 #include "level.hpp"
46 #include "tile.hpp"
47 #include "player_status.hpp"
48 #include "object/particlesystem.hpp"
49 #include "object/background.hpp"
50 #include "object/gradient.hpp"
51 #include "object/tilemap.hpp"
52 #include "object/camera.hpp"
53 #include "object/player.hpp"
54 #include "object/level_time.hpp"
55 #include "lisp/lisp.hpp"
56 #include "lisp/parser.hpp"
57 #include "resources.hpp"
58 #include "misc.hpp"
59 #include "statistics.hpp"
60 #include "timer.hpp"
61 #include "object/fireworks.hpp"
62 #include "textscroller.hpp"
63 #include "control/codecontroller.hpp"
64 #include "control/joystickkeyboardcontroller.hpp"
65 #include "main.hpp"
66 #include "file_system.hpp"
67 #include "gameconfig.hpp"
68 #include "gettext.hpp"
69 #include "console.hpp"
70 #include "flip_level_transformer.hpp"
71
72 // the engine will be run with a logical framerate of 64fps.
73 // We chose 64fps here because it is a power of 2, so 1/64 gives an "even"
74 // binary fraction...
75 static const float LOGICAL_FPS = 64.0;
76
77 namespace {
78   const char* consoleCommands[] = {
79           "foo",
80           "whereami",
81           "camera",
82           "grease",
83           "invincible",
84           "mortal",
85           "shrink", 
86           "kill",
87           "gotoend",
88           "flip",
89           "finish",
90           "restart",
91           "quit"
92   };
93 }
94
95 using namespace WorldMapNS;
96
97 GameSession* GameSession::current_ = 0;
98
99 GameSession::GameSession(const std::string& levelfile_, GameSessionMode mode,
100     Statistics* statistics)
101   : level(0), currentsector(0), mode(mode),
102     end_sequence(NO_ENDSEQUENCE), end_sequence_controller(0),
103     levelfile(levelfile_), best_level_statistics(statistics),
104     capture_demo_stream(0), playback_demo_stream(0), demo_controller(0)
105 {
106   current_ = this;
107   currentsector = 0;
108   
109   game_pause = false;
110   fps_fps = 0;
111
112   for (uint16_t i=0; i < sizeof(::consoleCommands)/sizeof(typeof(consoleCommands[0])); i++) {
113     Console::instance->registerCommand(consoleCommands[i], this);
114   }
115
116   statistics_backdrop.reset(new Surface("images/engine/menu/score-backdrop.png"));
117
118   restart_level(true);
119 }
120
121 void
122 GameSession::restart_level(bool fromBeginning)
123 {
124   game_pause   = false;
125   end_sequence = NO_ENDSEQUENCE;
126
127   main_controller->reset();
128
129   currentsector = 0;
130
131   level.reset(new Level);
132   level->load(levelfile);
133
134   global_stats.reset();
135   global_stats.set_total_points(COINS_COLLECTED_STAT, level->get_total_coins());
136   global_stats.set_total_points(BADGUYS_KILLED_STAT, level->get_total_badguys());
137   
138   // get time
139   int time = 0;
140   for(std::vector<Sector*>::iterator i = level->sectors.begin(); i != level->sectors.end(); ++i)
141   {
142     Sector* sec = *i;
143
144     for(std::vector<GameObject*>::iterator j = sec->gameobjects.begin();
145         j != sec->gameobjects.end(); ++j)
146     {
147       GameObject* obj = *j;
148       
149       LevelTime* lt = dynamic_cast<LevelTime*> (obj);
150       if(lt)
151         time += int(lt->get_level_time());
152     }
153   }
154   global_stats.set_total_points(TIME_NEEDED_STAT, (time == 0) ? -1 : time);
155
156   if (fromBeginning) reset_sector="";
157   if(reset_sector != "") {
158     currentsector = level->get_sector(reset_sector);
159     if(!currentsector) {
160       std::stringstream msg;
161       msg << "Couldn't find sector '" << reset_sector << "' for resetting tux.";
162       throw std::runtime_error(msg.str());
163     }
164     currentsector->activate(reset_pos);
165   } else {
166     currentsector = level->get_sector("main");
167     if(!currentsector)
168       throw std::runtime_error("Couldn't find main sector");
169     currentsector->activate("main");
170   }
171   
172   if(mode == ST_GL_PLAY || mode == ST_GL_LOAD_LEVEL_FILE)
173     levelintro();
174
175   currentsector->play_music(LEVEL_MUSIC);
176
177   if(capture_file != "")
178     record_demo(capture_file);
179 }
180
181 GameSession::~GameSession()
182 {
183   delete capture_demo_stream;
184   delete playback_demo_stream;
185   delete demo_controller;
186
187   delete end_sequence_controller;
188
189   current_ = NULL;
190 }
191
192 void
193 GameSession::record_demo(const std::string& filename)
194 {
195   delete capture_demo_stream;
196   
197   capture_demo_stream = new std::ofstream(filename.c_str()); 
198   if(!capture_demo_stream->good()) {
199     std::stringstream msg;
200     msg << "Couldn't open demo file '" << filename << "' for writing.";
201     throw std::runtime_error(msg.str());
202   }
203   capture_file = filename;
204 }
205
206 void
207 GameSession::play_demo(const std::string& filename)
208 {
209   delete playback_demo_stream;
210   delete demo_controller;
211   
212   playback_demo_stream = new std::ifstream(filename.c_str());
213   if(!playback_demo_stream->good()) {
214     std::stringstream msg;
215     msg << "Couldn't open demo file '" << filename << "' for reading.";
216     throw std::runtime_error(msg.str());
217   }
218
219   Player& tux = *currentsector->player;
220   demo_controller = new CodeController();
221   tux.set_controller(demo_controller);
222 }
223
224 void
225 GameSession::levelintro()
226 {
227   char str[60];
228
229   sound_manager->stop_music();
230
231   DrawingContext context;
232   for(Sector::GameObjects::iterator i = currentsector->gameobjects.begin();
233       i != currentsector->gameobjects.end(); ++i) {
234     Background* background = dynamic_cast<Background*> (*i);
235     if(background) {
236       background->draw(context);
237     }
238     Gradient* gradient = dynamic_cast<Gradient*> (*i);
239     if(gradient) {
240       gradient->draw(context);
241     }
242   }
243
244 //  context.draw_text(gold_text, level->get_name(), Vector(SCREEN_WIDTH/2, 160),
245 //      CENTER_ALLIGN, LAYER_FOREGROUND1);
246   context.draw_center_text(gold_text, level->get_name(), Vector(0, 160),
247       LAYER_FOREGROUND1);
248
249   sprintf(str, "Coins: %d", player_status->coins);
250   context.draw_text(white_text, str, Vector(SCREEN_WIDTH/2, 210),
251       CENTER_ALLIGN, LAYER_FOREGROUND1);
252
253   if((level->get_author().size()) && (level->get_author() != "SuperTux Team"))
254     //TODO make author check case/blank-insensitive
255     context.draw_text(white_small_text,
256       std::string(_("contributed by ")) + level->get_author(), 
257       Vector(SCREEN_WIDTH/2, 350), CENTER_ALLIGN, LAYER_FOREGROUND1);
258
259
260   if(best_level_statistics != NULL)
261     best_level_statistics->draw_message_info(context, _("Best Level Statistics"));
262
263   wait_for_event(1.0, 3.0);
264 }
265
266 void
267 GameSession::on_escape_press()
268 {
269   if(currentsector->player->is_dying() || end_sequence != NO_ENDSEQUENCE)
270     return;   // don't let the player open the menu, when he is dying
271   
272   if(mode == ST_GL_TEST) {
273     main_loop->exit_screen();
274   } else if (!Menu::current()) {
275     Menu::set_current(game_menu);
276     game_menu->set_active_item(MNID_CONTINUE);
277     game_pause = true;
278   } else {
279     game_pause = false;
280   }
281 }
282
283 void
284 GameSession::process_events()
285 {
286   Player& tux = *currentsector->player;
287
288   // end of pause mode?
289   if(!Menu::current() && game_pause) {
290     game_pause = false;
291   }
292
293   if (end_sequence != NO_ENDSEQUENCE) {
294     if(end_sequence_controller == 0) {
295       end_sequence_controller = new CodeController();
296       tux.set_controller(end_sequence_controller);
297     }
298
299     end_sequence_controller->press(Controller::RIGHT);
300     
301     if (int(last_x_pos) == int(tux.get_pos().x))
302       end_sequence_controller->press(Controller::JUMP);    
303     last_x_pos = tux.get_pos().x;
304   }
305
306   // playback a demo?
307   if(playback_demo_stream != 0) {
308     demo_controller->update();
309     char left = false;
310     char right = false;
311     char up = false;
312     char down = false;
313     char jump = false;
314     char action = false;
315     playback_demo_stream->get(left);
316     playback_demo_stream->get(right);
317     playback_demo_stream->get(up);
318     playback_demo_stream->get(down);
319     playback_demo_stream->get(jump);
320     playback_demo_stream->get(action);
321     demo_controller->press(Controller::LEFT, left);
322     demo_controller->press(Controller::RIGHT, right);
323     demo_controller->press(Controller::UP, up);
324     demo_controller->press(Controller::DOWN, down);
325     demo_controller->press(Controller::JUMP, jump);
326     demo_controller->press(Controller::ACTION, action);
327   }
328
329   // save input for demo?
330   if(capture_demo_stream != 0) {
331     capture_demo_stream ->put(main_controller->hold(Controller::LEFT));
332     capture_demo_stream ->put(main_controller->hold(Controller::RIGHT));
333     capture_demo_stream ->put(main_controller->hold(Controller::UP));
334     capture_demo_stream ->put(main_controller->hold(Controller::DOWN));
335     capture_demo_stream ->put(main_controller->hold(Controller::JUMP));   
336     capture_demo_stream ->put(main_controller->hold(Controller::ACTION));
337   }
338 }
339
340 bool
341 GameSession::consoleCommand(std::string command, std::vector<std::string>)
342 {
343   if (command == "foo") {
344     log_info << "bar" << std::endl;
345     return true;
346   }
347
348   if (currentsector == 0) return false;
349   Player& tux = *currentsector->player;
350   
351   // Cheating words (the goal of this is really for debugging,
352   // but could be used for some cheating, nothing wrong with that)
353   if (command == "grease") {
354     tux.physic.set_velocity_x(tux.physic.get_velocity_x()*3);
355     return true;
356   }
357   if (command == "invincible") {
358     // be invincle for the rest of the level
359     tux.invincible_timer.start(10000);
360     return true;
361   }
362   if (command == "mortal") {
363     // give up invincibility
364     tux.invincible_timer.stop();
365     return true;
366   }
367   if (command == "shrink") {
368     // remove powerups
369     tux.kill(tux.SHRINK);
370     return true;
371   }
372   if (command == "kill") {
373     tux.kill(tux.KILL);
374     return true;
375   }
376   if (command == "restart") {
377     restart_level(true);
378     return true;
379   }
380   if (command == "whereami") {
381     log_info << "You are at x " << tux.get_pos().x << ", y " << tux.get_pos().y << std::endl;
382     return true;
383   }
384   if (command == "gotoend") {
385     // goes to the end of the level
386     tux.move(Vector(
387           (currentsector->solids->get_width()*32) - (SCREEN_WIDTH*2), 0));
388     currentsector->camera->reset(
389         Vector(tux.get_pos().x, tux.get_pos().y));
390     return true;
391   }
392   if (command == "flip") {
393     FlipLevelTransformer flip_transformer;
394     flip_transformer.transform(GameSession::current()->get_current_level());
395     return true;
396   }
397   if (command == "finish") {
398     finish(true);
399     return true;
400   }
401   if (command == "camera") {
402     log_info << "Camera is at " << Sector::current()->camera->get_translation().x << "," << Sector::current()->camera->get_translation().y << std::endl;
403     return true;
404   }
405   if (command == "quit") {
406     main_loop->quit();
407     return true;
408   }
409
410   return false;
411 }
412
413 void
414 GameSession::check_end_conditions()
415 {
416   Player* tux = currentsector->player;
417
418   /* End of level? */
419   if(end_sequence && endsequence_timer.check()) {
420     finish(true);
421     return;
422   } else if (!end_sequence && tux->is_dead()) {
423     if (player_status->coins < 0) { 
424       // No more coins: restart level from beginning
425       player_status->coins = 0;
426       restart_level(true);
427     } else { 
428       // Still has coins: restart level from last reset point
429       restart_level(false);
430     }
431     
432     return;
433   }
434 }
435
436 void 
437 GameSession::draw(DrawingContext& context)
438 {
439   currentsector->draw(context);
440   drawstatus(context);
441
442   if(game_pause)
443     draw_pause(context);
444 }
445
446 void
447 GameSession::draw_pause(DrawingContext& context)
448 {
449   context.draw_filled_rect(
450       Vector(0,0), Vector(SCREEN_WIDTH, SCREEN_HEIGHT),
451       Color(.2, .2, .2, .5), LAYER_FOREGROUND1);
452 }
453   
454 void
455 GameSession::process_menu()
456 {
457   Menu* menu = Menu::current();
458   if(menu) {
459     menu->update();
460
461     if(menu == game_menu) {
462       switch (game_menu->check()) {
463         case MNID_CONTINUE:
464           Menu::set_current(0);
465           break;
466         case MNID_ABORTLEVEL:
467           Menu::set_current(0);
468           main_loop->exit_screen();
469           break;
470       }
471     }
472   }
473 }
474
475 void
476 GameSession::setup()
477 {
478   Menu::set_current(NULL);
479   current_ = this;
480
481   // Eat unneeded events
482   SDL_Event event;
483   while(SDL_PollEvent(&event))
484   {}
485 }
486
487 void
488 GameSession::update(float elapsed_time)
489 {
490   process_events();
491   process_menu();
492
493   check_end_conditions();
494
495   // handle controller
496   if(main_controller->pressed(Controller::PAUSE_MENU))
497     on_escape_press();
498   
499   // respawning in new sector?
500   if(newsector != "" && newspawnpoint != "") {
501     Sector* sector = level->get_sector(newsector);
502     if(sector == 0) {
503       log_warning << "Sector '" << newsector << "' not found" << std::endl;
504     }
505     sector->activate(newspawnpoint);
506     sector->play_music(LEVEL_MUSIC);
507     currentsector = sector;
508     newsector = "";
509     newspawnpoint = "";
510   }
511
512   // Update the world state and all objects in the world
513   if(!game_pause) {
514     // Update the world
515     if (end_sequence == ENDSEQUENCE_RUNNING) {
516       currentsector->update(elapsed_time/2);
517     } else if(end_sequence == NO_ENDSEQUENCE) {
518       if(!currentsector->player->growing_timer.started())
519         currentsector->update(elapsed_time);
520     } 
521   }
522
523   // update sounds
524   sound_manager->set_listener_position(currentsector->player->get_pos());
525
526   /* Handle music: */
527   if (end_sequence)
528     return;
529   
530   if(currentsector->player->invincible_timer.started()) {
531     if(currentsector->player->invincible_timer.get_timeleft() <=
532        TUX_INVINCIBLE_TIME_WARNING) {
533       currentsector->play_music(HERRING_WARNING_MUSIC);
534     } else {
535       currentsector->play_music(HERRING_MUSIC);
536     }
537   } else if(currentsector->get_music_type() != LEVEL_MUSIC) {
538     currentsector->play_music(LEVEL_MUSIC);
539   }
540 }
541
542 #if 0
543 GameSession::ExitStatus
544 GameSession::run()
545 {
546   Menu::set_current(0);
547   current_ = this;
548   
549   int fps_cnt = 0;
550
551   // Eat unneeded events
552   SDL_Event event;
553   while(SDL_PollEvent(&event))
554   {}
555
556   draw();
557
558   Uint32 fps_ticks = SDL_GetTicks();
559   Uint32 fps_nextframe_ticks = SDL_GetTicks();
560   Uint32 ticks;
561   bool skipdraw = false;
562
563   while (exit_status == ES_NONE) {
564     // we run in a logical framerate so elapsed time is a constant
565     // This will make the game run determistic and not different on different
566     // machines
567     static const float elapsed_time = 1.0 / LOGICAL_FPS;
568     // old code... float elapsed_time = float(ticks - lastticks) / 1000.;
569     if(!game_pause)
570       game_time += elapsed_time;
571
572     // regulate fps
573     ticks = SDL_GetTicks();
574     if(ticks > fps_nextframe_ticks) {
575       if(skipdraw == true) {
576         // already skipped last frame? we have to slow down the game then...
577         skipdraw = false;
578         fps_nextframe_ticks -= (Uint32) (1000.0 / LOGICAL_FPS);
579       } else {
580         // don't draw all frames when we're getting too slow
581         skipdraw = true;
582       }
583     } else {
584       skipdraw = false;
585       while(fps_nextframe_ticks > ticks) {
586         /* just wait */
587         // If we really have to wait long, then do an imprecise SDL_Delay()
588         Uint32 diff = fps_nextframe_ticks - ticks;
589         if(diff > 15) {
590           SDL_Delay(diff - 10);
591         } 
592         ticks = SDL_GetTicks();
593       }
594     }
595     fps_nextframe_ticks = ticks + (Uint32) (1000.0 / LOGICAL_FPS);
596
597     process_events();
598     process_menu();
599
600     // Update the world state and all objects in the world
601     if(!game_pause)
602     {
603       // Update the world
604       check_end_conditions();
605       if (end_sequence == ENDSEQUENCE_RUNNING)
606         update(elapsed_time/2);
607       else if(end_sequence == NO_ENDSEQUENCE)
608         update(elapsed_time);
609     }
610
611     if(!skipdraw)
612       draw();
613
614     // update sounds
615     sound_manager->update();
616
617     /* Time stops in pause mode */
618     if(game_pause || Menu::current())
619     {
620       continue;
621     }
622
623     /* Handle music: */
624     if (currentsector->player->invincible_timer.started() && 
625             currentsector->player->invincible_timer.get_timeleft() 
626             > TUX_INVINCIBLE_TIME_WARNING && !end_sequence)
627     {
628       currentsector->play_music(HERRING_MUSIC);
629     }
630     /* or just normal music? */
631     else if(currentsector->get_music_type() != LEVEL_MUSIC && !end_sequence)
632     {
633       currentsector->play_music(LEVEL_MUSIC);
634     }
635
636     /* Calculate frames per second */
637     if(config->show_fps)
638     {
639       ++fps_cnt;
640       
641       if(SDL_GetTicks() - fps_ticks >= 500)
642       {
643         fps_fps = (float) fps_cnt / .5;
644         fps_cnt = 0;
645         fps_ticks = SDL_GetTicks();
646       }
647     }
648   }
649  
650   // just in case
651   currentsector = 0;
652   main_controller->reset();
653   return exit_status;
654 }
655 #endif
656
657 void
658 GameSession::finish(bool win)
659 {
660   if(win) {
661     if(WorldMap::current())
662       WorldMap::current()->finished_level(levelfile);
663   }
664   
665   main_loop->exit_screen();
666 }
667
668 void
669 GameSession::respawn(const std::string& sector, const std::string& spawnpoint)
670 {
671   newsector = sector;
672   newspawnpoint = spawnpoint;
673 }
674
675 void
676 GameSession::set_reset_point(const std::string& sector, const Vector& pos)
677 {
678   reset_sector = sector;
679   reset_pos = pos;
680 }
681
682 std::string
683 GameSession::get_working_directory()
684 {
685   return FileSystem::dirname(levelfile);
686 }
687
688 void
689 GameSession::display_info_box(const std::string& text)
690 {
691   InfoBox* box = new InfoBox(text);
692
693   bool running = true;
694   DrawingContext context;
695   
696   while(running)  {
697
698     // TODO make a screen out of this, another mainloop is ugly
699     main_controller->update();
700     SDL_Event event;
701     while (SDL_PollEvent(&event)) {
702       main_controller->process_event(event);
703       if(event.type == SDL_QUIT)
704         main_loop->quit();
705     }
706
707     if(main_controller->pressed(Controller::JUMP)
708         || main_controller->pressed(Controller::ACTION)
709         || main_controller->pressed(Controller::PAUSE_MENU)
710         || main_controller->pressed(Controller::MENU_SELECT))
711       running = false;
712     else if(main_controller->pressed(Controller::DOWN))
713       box->scrolldown();
714     else if(main_controller->pressed(Controller::UP))
715       box->scrollup();
716     box->draw(context);
717     draw(context);
718     context.do_drawing();
719     sound_manager->update();
720   }
721
722   delete box;
723 }
724
725 void
726 GameSession::start_sequence(const std::string& sequencename)
727 {
728   if(sequencename == "endsequence" || sequencename == "fireworks") {
729     if(end_sequence)
730       return;
731
732     end_sequence = ENDSEQUENCE_RUNNING;
733     endsequence_timer.start(7.3);
734     last_x_pos = -1;
735     sound_manager->play_music("music/leveldone.ogg", false);
736     currentsector->player->invincible_timer.start(7.3);
737
738     // Stop all clocks.
739     for(std::vector<GameObject*>::iterator i = currentsector->gameobjects.begin();
740         i != currentsector->gameobjects.end(); ++i)
741     {
742       GameObject* obj = *i;
743
744       LevelTime* lt = dynamic_cast<LevelTime*> (obj);
745       if(lt)
746         lt->stop();
747     }
748
749     // add time spent to statistics
750     int tottime = 0, remtime = 0;
751     for(std::vector<Sector*>::iterator i = level->sectors.begin(); i != level->sectors.end(); ++i)
752     {
753       Sector* sec = *i;
754
755       for(std::vector<GameObject*>::iterator j = sec->gameobjects.begin();
756           j != sec->gameobjects.end(); ++j)
757       {
758         GameObject* obj = *j;
759
760         LevelTime* lt = dynamic_cast<LevelTime*> (obj);
761         if(lt)
762         {
763           tottime += int(lt->get_level_time());
764           remtime += int(lt->get_remaining_time());
765         }
766       }
767     }
768     global_stats.set_points(TIME_NEEDED_STAT, (tottime == 0 ? -1 : (tottime-remtime)));
769
770     if(sequencename == "fireworks") {
771       currentsector->add_object(new Fireworks());
772     }
773   } else if(sequencename == "stoptux") {
774     if(!end_sequence) {
775       log_warning << "Final target reached without an active end sequence" << std::endl;
776       this->start_sequence("endsequence");
777     }
778     end_sequence =  ENDSEQUENCE_WAITING;
779   } else {
780     log_warning << "Unknown sequence '" << sequencename << "'" << std::endl;
781   }
782 }
783
784 /* (Status): */
785 void
786 GameSession::drawstatus(DrawingContext& context)
787 {
788   player_status->draw(context);
789
790   if(config->show_fps) {
791     char str[60];
792     snprintf(str, sizeof(str), "%3.1f", fps_fps);
793     const char* fpstext = "FPS";
794     context.draw_text(white_text, fpstext, Vector(SCREEN_WIDTH - white_text->get_text_width(fpstext) - gold_text->get_text_width(" 99999") - BORDER_X, BORDER_Y + 20), LEFT_ALLIGN, LAYER_FOREGROUND1);
795     context.draw_text(gold_text, str, Vector(SCREEN_WIDTH - BORDER_X, BORDER_Y + 20), RIGHT_ALLIGN, LAYER_FOREGROUND1);
796   }
797
798   // draw level stats while end_sequence is running
799   if (end_sequence) {
800     global_stats.draw_endseq_panel(context, best_level_statistics, statistics_backdrop.get());
801   }
802 }
803