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