home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2009 February / maximum-cd-2009-02.iso / DiscContents / SMC_1.6_win32.exe / src / gui / hud.cpp next >
Encoding:
C/C++ Source or Header  |  2008-06-27  |  33.7 KB  |  1,322 lines

  1. /***************************************************************************
  2.  * hud.cpp  -  human user interfaces in the game
  3.  *
  4.  * Copyright (C) 2003 - 2008 Florian Richter
  5.  ***************************************************************************/
  6. /*
  7.    This program is free software; you can redistribute it and/or modify
  8.    it under the terms of the GNU General Public License as published by
  9.    the Free Software Foundation; either version 3 of the License, or
  10.    (at your option) any later version.
  11.    
  12.    You should have received a copy of the GNU General Public License
  13.    along with this program.  If not, see <http://www.gnu.org/licenses/>.
  14. */
  15.  
  16. #include "../gui/hud.h"
  17. #include "../core/game_core.h"
  18. #include "../player/player.h"
  19. #include "../audio/audio.h"
  20. #include "../core/camera.h"
  21. #include "../video/font.h"
  22. #include "../core/framerate.h"
  23. #include "../level/level.h"
  24. #include "../core/sprite_manager.h"
  25. #include "../objects/bonusbox.h"
  26. #include "../video/gl_surface.h"
  27. #include "../video/renderer.h"
  28. #include "../core/i18n.h"
  29.  
  30. /* *** *** *** *** *** *** *** cHudSprite *** *** *** *** *** *** *** *** *** *** */
  31.  
  32. cHudSprite :: cHudSprite( GL_Surface *new_image /* = NULL */, float x /* = 0 */, float y /* = 0 */, bool del_img /* = 0 */ )
  33. : cSprite( new_image, x, y, del_img )
  34. {
  35.     player_range = 0;
  36.     posz = 0.13f;
  37.  
  38.     Set_Ignore_Camera( 1 );
  39. }
  40.  
  41. cHudSprite :: ~cHudSprite( void )
  42. {
  43.  
  44. }
  45.  
  46. cHudSprite *cHudSprite :: Copy( void )
  47. {
  48.     cHudSprite *hud_sprite = new cHudSprite( start_image, posx, posy );
  49.  
  50.     hud_sprite->type = type;
  51.     hud_sprite->sprite_array = sprite_array;
  52.     hud_sprite->massivetype = massivetype;
  53.     hud_sprite->Set_Ignore_Camera( no_camera );
  54.     hud_sprite->Set_Shadow_Pos( shadow_pos );
  55.     hud_sprite->Set_Shadow_Color( shadow_color );
  56.  
  57.     return hud_sprite;
  58. }
  59.  
  60. /* *** *** *** *** *** *** *** cHud_Manager *** *** *** *** *** *** *** *** *** *** */
  61.  
  62. cHud_Manager :: cHud_Manager( void )
  63. : cObject_Manager<cHudSprite>()
  64. {
  65.     loaded = 0;
  66.  
  67.     Load();
  68. }
  69.  
  70. cHud_Manager :: ~cHud_Manager( void )
  71. {
  72.     Unload();
  73. }
  74.  
  75. void cHud_Manager :: Load( void )
  76. {
  77.     if( !loaded && objects.size() )
  78.     {
  79.         Unload();
  80.     }
  81.     else if( loaded )
  82.     {
  83.         Update_Text();
  84.         return;
  85.     }
  86.  
  87.     // Menu Background ( Maryo head and the Goldpiece )
  88.     Add( static_cast<cHudSprite *>(new cMenuBackground()) );
  89.     // Point Display
  90.     pointsdisplay = new cPlayerPoints();
  91.     Add( static_cast<cHudSprite *>(pointsdisplay) );
  92.     // Time Display
  93.     timedisplay = new cTimeDisplay();
  94.     Add( static_cast<cHudSprite *>(timedisplay) );
  95.     // Live Display
  96.     livedisplay = new cLiveDisplay();
  97.     Add( static_cast<cHudSprite *>(livedisplay) );
  98.     // Gold Display
  99.     golddisplay = new cGoldDisplay();
  100.     Add( static_cast<cHudSprite *>(golddisplay) );
  101.     // Itembox
  102.     Itembox = new cItemBox();
  103.     Add( static_cast<cHudSprite *>(Itembox) );
  104.     // Debug Display
  105.     debugdisplay = new cDebugDisplay();
  106.     Add( static_cast<cHudSprite *>(debugdisplay) );
  107.  
  108.     loaded = 1;
  109. }
  110.  
  111. void cHud_Manager :: Unload( void )
  112. {
  113.     if( !objects.size() )
  114.     {
  115.         return;
  116.     }
  117.     
  118.     Delete_All();
  119.  
  120.     livedisplay = NULL;
  121.     golddisplay = NULL;
  122.     pointsdisplay = NULL;
  123.     timedisplay = NULL;
  124.     debugdisplay = NULL;
  125.     Itembox = NULL;
  126.     
  127.     loaded = 0;
  128. }
  129.  
  130. void cHud_Manager :: Update_Text( void )
  131. {
  132.     // note : update the life display before you update the timedisplay
  133.     
  134.     if( objects.size() > 0 )
  135.     {
  136.         cMenuBackground *item = static_cast<cMenuBackground *>(objects[0]);
  137.  
  138.         if( Game_Mode != MODE_OVERWORLD )
  139.         {
  140.             // goldpiece
  141.             item->rect_goldpiece.y = item->rect_maryo_head.y + 6;
  142.         }
  143.         else
  144.         {
  145.             // goldpiece
  146.             item->rect_goldpiece.y = 7;
  147.         }
  148.     }
  149.  
  150.     if( livedisplay )
  151.     {
  152.         if( Game_Mode != MODE_OVERWORLD )
  153.         {
  154.             livedisplay->Set_Pos( game_res_w - game_res_w * 0.1f, 18 );
  155.         }
  156.         else
  157.         {
  158.             livedisplay->Set_Pos( game_res_w - game_res_w / 7.5f, 4 );
  159.         }
  160.  
  161.         livedisplay->Add_Lives( 0 );
  162.     }
  163.  
  164.     if( golddisplay )
  165.     {
  166.         if( Game_Mode != MODE_OVERWORLD )
  167.         {
  168.             golddisplay->Set_Pos( 280, 18 );
  169.         }
  170.         else
  171.         {
  172.             golddisplay->Set_Pos( 280, 4 );
  173.         }
  174.  
  175.         golddisplay->Add_Gold( 0 );
  176.     }
  177.  
  178.     if( pointsdisplay )
  179.     {
  180.         if( Game_Mode != MODE_OVERWORLD )
  181.         {
  182.             pointsdisplay->Set_Pos( 50, 18 );
  183.         }
  184.         else
  185.         {
  186.             pointsdisplay->Set_Pos( 50, 4 );
  187.         }
  188.  
  189.         pointsdisplay->Add_Points( 0 );
  190.     }
  191.  
  192.     if( timedisplay )
  193.     {
  194.         timedisplay->Set_Pos( game_res_w * 0.70f, 18 );
  195.         timedisplay->Update();
  196.     }
  197.  
  198.     if( debugdisplay )
  199.     {
  200.         debugdisplay->Set_Pos( game_res_w * 0.45f, 80 );
  201.         debugdisplay->Update();
  202.     }
  203.  
  204.     if( Itembox ) 
  205.     {
  206.         Itembox->Set_Pos( game_res_w * 0.49f, 10 );
  207.         Itembox->Update();
  208.     }
  209. }
  210.  
  211. void cHud_Manager :: Update( void )
  212. {
  213.     // update HUD objects
  214.     for( HudSpriteList::iterator itr = objects.begin(), itr_end = objects.end(); itr != itr_end; ++itr )
  215.     {
  216.         (*itr)->Update();
  217.     }
  218. }
  219.  
  220. void cHud_Manager :: Draw( void )
  221. {
  222.     // draw HUD objects
  223.     for( HudSpriteList::iterator itr = objects.begin(), itr_end = objects.end(); itr != itr_end; ++itr )
  224.     {
  225.         (*itr)->Draw();
  226.     }
  227. }
  228.  
  229. /* *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** */
  230.  
  231. cHud_Manager *pHud_Manager = NULL;
  232.  
  233. /* *** *** *** *** *** *** PointsText *** *** *** *** *** *** *** *** *** *** *** */
  234.  
  235. PointsText :: PointsText( void )
  236. : cHudSprite()
  237. {
  238.     points = 0;
  239.     vely = 0;
  240. }
  241.  
  242. PointsText :: ~PointsText( void )
  243. {
  244.     //
  245. }
  246.  
  247. /* *** *** *** *** *** *** cMenuBackground *** *** *** *** *** *** *** *** *** *** *** */
  248.  
  249. cMenuBackground :: cMenuBackground( float x /* = 0 */, float y /* = 0 */ )
  250. : cHudSprite( NULL, x, y )
  251. {
  252.     type = TYPE_MENUBG;
  253.     sprite_array = ARRAY_HUD;
  254.  
  255.     maryo_head = pVideo->Get_Surface( "game/maryo_l.png" );
  256.     goldpiece = pVideo->Get_Surface( "game/gold_m.png" );
  257.  
  258.     if(    !maryo_head || !goldpiece )
  259.     {
  260.         printf( "Error : MenuBackground images loading failed\n" );
  261.         return;
  262.     }
  263.  
  264.     // maryo head
  265.     rect_maryo_head.x = game_res_w - game_res_w / 11 + 25;
  266.     rect_maryo_head.y = 15;
  267.     // goldpiece
  268.     rect_goldpiece.x = 250;
  269. }
  270.  
  271. cMenuBackground :: ~cMenuBackground( void )
  272. {
  273.     //
  274. }
  275.  
  276. void cMenuBackground :: Draw( cSurfaceRequest *request /* = NULL */ )
  277. {
  278.     if( editor_enabled || Game_Mode == MODE_MENU )
  279.     {
  280.         return;
  281.     }
  282.  
  283.     // maryo head
  284.     if( Game_Mode != MODE_OVERWORLD )
  285.     {
  286.         maryo_head->Blit( rect_maryo_head.x, rect_maryo_head.y, posz );
  287.     }
  288.  
  289.     // goldpiece
  290.     goldpiece->Blit( rect_goldpiece.x, rect_goldpiece.y, posz );
  291. }
  292.  
  293. /* *** *** *** *** *** *** cStatusText *** *** *** *** *** *** *** *** *** *** *** */
  294.  
  295. cStatusText :: cStatusText( float x /* = 0 */, float y /* = 0 */ )
  296. : cHudSprite( NULL, x, y )
  297. {
  298.     type = TYPE_STATUSTEXT;
  299.     sprite_array = ARRAY_HUD;
  300.  
  301.     Set_Shadow( black, 1.5f );
  302. }
  303.  
  304. cStatusText :: ~cStatusText( void )
  305. {
  306.     //
  307. }
  308.  
  309. void cStatusText :: Draw( cSurfaceRequest *request /* = NULL */ )
  310. {
  311.     if( Game_Mode == MODE_MENU )
  312.     {
  313.         return;
  314.     }
  315.  
  316.     cHudSprite::Draw();
  317. }
  318.  
  319. /* *** *** *** *** *** *** cPlayerPoints *** *** *** *** *** *** *** *** *** *** *** */
  320.  
  321. cPlayerPoints :: cPlayerPoints( float x /* = 0 */, float y /* = 0 */ )
  322. : cStatusText( x, y )
  323. {
  324.     sprite_array = ARRAY_HUD;
  325.     type = TYPE_POINTDISPLAY;
  326.     
  327.     Set_Points( pPlayer->points );
  328.  
  329.     pointsobjects.reserve( 50 );
  330. }
  331.  
  332. cPlayerPoints :: ~cPlayerPoints( void )
  333. {
  334.     //
  335. }
  336.  
  337. void cPlayerPoints :: Draw( cSurfaceRequest *request /* = NULL */ )
  338. {
  339.     if( editor_enabled || Game_Mode == MODE_MENU )
  340.     {
  341.         return;
  342.     }
  343.     
  344.     cHudSprite::Draw( request );
  345.  
  346.     // draw small points
  347.     for( PointsTextList::iterator itr = pointsobjects.begin(); itr != pointsobjects.end(); )
  348.     {
  349.         // get object pointer
  350.         PointsText *obj = (*itr);
  351.         
  352.         // if finished
  353.         if( !obj->image )
  354.         {
  355.             itr = pointsobjects.erase( itr );
  356.             delete obj;
  357.         }
  358.         // active
  359.         else
  360.         {
  361.             obj->vely -= obj->vely * 0.01f * pFramerate->speedfactor;
  362.             obj->posy += obj->vely * pFramerate->speedfactor;
  363.  
  364.             if( obj->vely > -1.0 )
  365.             {
  366.                 obj->Set_Image( NULL );
  367.                 continue;
  368.             }
  369.  
  370.             float x = obj->posx - pActive_Camera->x;
  371.             float y = obj->posy - pActive_Camera->y;
  372.  
  373.             // out in left
  374.             if( x < 0 )
  375.             {
  376.                 x = 5;
  377.             }
  378.             // out in right
  379.             else if( x > game_res_w )
  380.             {
  381.                 x = static_cast<float>(game_res_w) - obj->col_rect.w - 2; 
  382.             }
  383.  
  384.             // out on bottom
  385.             if( y < 0 )
  386.             {
  387.                 y = 5;
  388.             }
  389.             // out on top
  390.             else if( y > game_res_h )
  391.             {
  392.                 y = static_cast<float>(game_res_h) - obj->col_rect.h - 20;
  393.             }
  394.  
  395.             // create request
  396.             cSurfaceRequest *request = new cSurfaceRequest();
  397.             obj->image->Blit( x, y, posz, request );
  398.  
  399.             // shadow
  400.             request->shadow_color = black;
  401.             request->shadow_pos = 1;
  402.  
  403.             // color
  404.             request->color = Color( static_cast<Uint8>( 255 - ( obj->points / 150 ) ), static_cast<Uint8>( 255 - ( obj->points / 150 ) ), static_cast<Uint8>( 255 - ( obj->points / 30 ) ) );
  405.  
  406.             // add request
  407.             pRenderer->Add( request );
  408.  
  409.             ++itr;
  410.         }
  411.     }
  412. }
  413.  
  414. void cPlayerPoints :: Set_Points( unsigned int points )
  415. {
  416.     pPlayer->points = points;
  417.     
  418.     char text[70];
  419.     sprintf( text, _("Points %08d"), static_cast<int>(pPlayer->points) );
  420.     Set_Image( pFont->Render_Text( pFont->font_normal, text, white ), 0, 1 );
  421. }
  422.  
  423. void cPlayerPoints :: Add_Points( unsigned int points, float x /* = 0 */, float y /* = 0 */, string strtext /* = "" */, Color color /* = static_cast<Uint8>(255) */, bool allow_multiplier /* = 0 */ )
  424. {
  425.     if( allow_multiplier )
  426.     {
  427.         points = static_cast<unsigned int>( pPlayer->kill_multiplier * static_cast<float>(points) );
  428.     }
  429.  
  430.     Set_Points( pPlayer->points + points );
  431.  
  432.     if( x == 0 || y == 0 || pointsobjects.size() > 50 )
  433.     {
  434.         return;
  435.     }
  436.  
  437.     // if empty set the points as text
  438.     if( strtext.empty() )
  439.     {
  440.         strtext = int_to_string( points );
  441.     }
  442.  
  443.     PointsText *new_obj = new PointsText();
  444.     new_obj->Set_Image( pFont->Render_Text( pFont->font_small, strtext, color ), 1, 1 );
  445.  
  446.     new_obj->Set_Pos( x, y );
  447.     new_obj->vely = -1.4f;
  448.     new_obj->points = points;
  449.     
  450.     // check if it collides with an already active points text
  451.     for( PointsTextList::iterator itr = pointsobjects.begin(); itr != pointsobjects.end(); ++itr )
  452.     {
  453.         // get object pointer
  454.         PointsText *obj = (*itr);
  455.  
  456.         if( Col_Box( &new_obj->rect, &obj->col_rect ) )
  457.         {
  458.             new_obj->Move( obj->col_rect.w + 5, 0, 1 );
  459.         }
  460.     }
  461.  
  462.     pointsobjects.push_back( new_obj );
  463. }
  464.  
  465. void cPlayerPoints :: Clear( void )
  466. {
  467.     for( PointsTextList::iterator itr = pointsobjects.begin(), itr_end = pointsobjects.end(); itr != itr_end; ++itr )
  468.     {
  469.         delete *itr;
  470.     }
  471.  
  472.     pointsobjects.clear();
  473. }
  474.  
  475. /* *** *** *** *** *** *** *** cTimeDisplay *** *** *** *** *** *** *** *** *** *** */
  476.  
  477. cTimeDisplay :: cTimeDisplay( float x /* = 0 */, float y /* = 0 */ )
  478. : cStatusText( x, y )
  479. {
  480.     sprite_array = ARRAY_HUD;
  481.     type = TYPE_GAMETIMEDISPLAY;
  482.  
  483.     old_seconds = 0;
  484.     counter = 0;
  485. }
  486.  
  487. cTimeDisplay :: ~cTimeDisplay( void )
  488. {
  489.     //
  490. }
  491.  
  492. void cTimeDisplay :: Update( void )
  493. {
  494.     if( editor_enabled || Game_Mode == MODE_OVERWORLD || Game_Mode == MODE_MENU )
  495.     {
  496.         return;
  497.     }
  498.  
  499.     counter += pFramerate->speedfactor;
  500.  
  501.     // get seconds since start
  502.     unsigned int seconds = static_cast<unsigned int>( counter / speedfactor_fps );
  503.  
  504.     // no change
  505.     if( seconds == old_seconds )
  506.     {
  507.         return;
  508.     }
  509.  
  510.     unsigned int minutes = seconds / 60;
  511.  
  512.     // Set new time
  513.     sprintf( text, _("Time %02d:%02d"), minutes, seconds - ( minutes * 60 ) );
  514.     Set_Image( pFont->Render_Text( pFont->font_normal, text, white ), 0, 1 );
  515. }
  516.  
  517. void cTimeDisplay :: Draw( cSurfaceRequest *request /* = NULL */ )
  518. {
  519.     if( editor_enabled || Game_Mode == MODE_OVERWORLD || Game_Mode == MODE_MENU )
  520.     {
  521.         return;
  522.     }
  523.  
  524.     cHudSprite::Draw();
  525. }
  526.  
  527. /* *** *** *** *** *** *** *** cItemBox *** *** *** *** *** *** *** *** *** *** */
  528.  
  529. cItemBox :: cItemBox( float x /* = 0 */, float y /* = 0 */ )
  530. : cStatusText( x, y )
  531. {
  532.     sprite_array = ARRAY_HUD;
  533.     type = TYPE_ITEMBOXDISPLAY;
  534.  
  535.     Set_Image( pVideo->Get_Surface( "game/itembox.png" ) );
  536.     // disable shadow
  537.     Set_Shadow_Pos( 0 );
  538.  
  539.     box_color = white;
  540.  
  541.     item_counter = 0;
  542.     item_counter_mod = 0;
  543.     item_id = TYPE_UNDEFINED;
  544.  
  545.     item = new cMovingSprite();
  546.     item->Set_Ignore_Camera( 1 );
  547.     item->player_range = 0;
  548.     item->Set_Massive_Type( MASS_MASSIVE );
  549.     item->posz = 0.1299f;
  550. }
  551.  
  552. cItemBox :: ~cItemBox( void )
  553. {
  554.     delete item;
  555. }
  556.  
  557. void cItemBox :: Update( void )
  558. {
  559.     if( item_counter )
  560.     {
  561.         item->Move( 0, 4 );
  562.  
  563.         if( item_counter_mod )
  564.         {
  565.             item_counter += pFramerate->speedfactor * 10;
  566.  
  567.             if( item_counter >= 90 )
  568.             {
  569.                 item_counter_mod = 0;
  570.                 item_counter = 90;
  571.             }
  572.         }
  573.         else
  574.         {
  575.             item_counter -= pFramerate->speedfactor * 10;
  576.  
  577.             if( item_counter <= 0 )
  578.             {
  579.                 item_counter_mod = 1;
  580.                 item_counter = 1;
  581.             }
  582.         }
  583.  
  584.         if( item->posy > game_res_h )
  585.         {
  586.             Reset();
  587.         }
  588.  
  589.         cObjectCollisionType col_list = item->Collision_Check( &item->col_rect, COLLIDE_ONLY_CHECK );
  590.  
  591.         // if colliding with the player
  592.         if( col_list.find( TYPE_PLAYER ) )
  593.         {
  594.             SpriteType item_id_temp = item_id; // player can set the item back
  595.             Reset();
  596.             pPlayer->Get_Item( item_id_temp, 1 );
  597.         }
  598.     }
  599. }
  600.  
  601. void cItemBox :: Draw( cSurfaceRequest *request /* = NULL */ )
  602. {
  603.     if( editor_enabled || Game_Mode == MODE_OVERWORLD || Game_Mode == MODE_MENU )
  604.     {
  605.         return;
  606.     }
  607.  
  608.     if( item_id && item->image )
  609.     {
  610.         // with alpha
  611.         if( item_counter )
  612.         {
  613.             item->Set_Color( 255, 255, 255, 100 + static_cast<Uint8>(item_counter) );
  614.         }
  615.         
  616.         item->Draw();
  617.     }
  618.  
  619.     Set_Color( box_color.red, box_color.green, box_color.blue );
  620.     cHudSprite::Draw();
  621. }
  622.  
  623. void cItemBox :: Set_Item( SpriteType item_type, bool sound /* = 1 */ )
  624. {
  625.     // play sound
  626.     if( sound )
  627.     {
  628.         pAudio->Play_Sound( "itembox_set.ogg" );
  629.     }
  630.     // reset data
  631.     Reset();
  632.  
  633.     // reset startposition
  634.     item->Set_Pos( 0, 0, 1 );
  635.     // reset color
  636.     item->Set_Color( white );
  637.  
  638.     if( item_type == TYPE_MUSHROOM_DEFAULT )
  639.     {
  640.         box_color = Color( static_cast<Uint8>(250), 50, 50 );
  641.         item->Set_Image( pVideo->Get_Surface( "game/items/mushroom_red.png" ) );
  642.     }
  643.     else if( item_type == TYPE_FIREPLANT )
  644.     {
  645.         box_color = Color( static_cast<Uint8>(250), 200, 150 );
  646.         item->Set_Image( pVideo->Get_Surface( "game/items/fireplant.png" ) );
  647.     }
  648.     else if( item_type == TYPE_MUSHROOM_BLUE )
  649.     {
  650.         box_color = Color( static_cast<Uint8>(100), 100, 250 );
  651.         item->Set_Image( pVideo->Get_Surface( "game/items/mushroom_blue.png" ) );
  652.     }
  653.  
  654.  
  655.     if( item->image )
  656.     {
  657.         item->Set_Pos( posx - ( ( item->image->w - rect.w ) / 2 ), posy - ( ( item->image->h - rect.h ) / 2 ) );
  658.     }
  659.  
  660.     item_id = item_type;
  661. }
  662.  
  663. void cItemBox :: Request_Item( void )
  664. {
  665.     if( !item_id || item_counter ) 
  666.     {
  667.         return;
  668.     }
  669.  
  670.     pAudio->Play_Sound( "itembox_get.ogg" );
  671.  
  672.     item_counter = 255;
  673.     // draw item with camera
  674.     item->Set_Ignore_Camera( 0 );
  675.     item->Set_Pos( item->posx + pActive_Camera->x, item->posy + pActive_Camera->y );
  676. }
  677.  
  678. void cItemBox :: Push_back( void )
  679. {
  680.     item_counter = 0;
  681.     item_counter_mod = 0;
  682.  
  683.     // draw item without camera
  684.     item->Set_Ignore_Camera( 1 );
  685.     item->Set_Pos( item->startposx, item->startposy );
  686.     item->Set_Color( white );
  687. }
  688.  
  689. void cItemBox :: Reset( void )
  690. {
  691.     item->Set_Ignore_Camera( 1 );
  692.     item_id = TYPE_UNDEFINED;
  693.     item_counter = 0;
  694.     item_counter_mod = 0;
  695.     box_color = white;
  696. }
  697.  
  698. /* *** *** *** *** *** *** cDebugDisplay *** *** *** *** *** *** *** *** *** *** *** */
  699.  
  700. cDebugDisplay :: cDebugDisplay( float x /* = 0 */, float y /* = 0 */ )
  701. : cStatusText( x, y )
  702. {
  703.     sprite_array = ARRAY_HUD;
  704.     type = TYPE_DEBUGDISPLAY;
  705.  
  706.     text.clear();
  707.     text_old.clear();
  708.  
  709.     // debug box text data
  710.     Game_Mode_last = MODE_NOTHING;
  711.     level_old = ".";
  712.     obj_counter = -1;
  713.     pass_counter = -1;
  714.     mass_counter = -1;
  715.     enemy_counter = -1;
  716.     active_counter = -1;
  717.  
  718.     // debug text window
  719.     window_debugtext = CEGUI::WindowManager::getSingleton().loadWindowLayout( "debugtext.layout" );
  720.     pGuiSystem->getGUISheet()->addChildWindow( window_debugtext );
  721.     // debug text
  722.     text_debugtext = static_cast<CEGUI::Window *>(CEGUI::WindowManager::getSingleton().getWindow( "text_debugmessage" ));
  723.     // hide
  724.     text_debugtext->setVisible( 0 );
  725.  
  726.     // debug box positions
  727.     float tempx = static_cast<float>(game_res_w) - 200;
  728.     float tempy = static_cast<float>(game_res_h) / 2 - 250;
  729.  
  730.     for( unsigned int i = 0; i < 23; i++ )
  731.     {
  732.         sprites.push_back( new cHudSprite( NULL, tempx, tempy ) );
  733.         sprites[i]->Set_Shadow( black, 1 );
  734.         sprites[i]->posz = posz;
  735.  
  736.         // not the framerate text
  737.         if( i > 2 )
  738.         {
  739.             tempy += 19;
  740.         }
  741.  
  742.         // active box
  743.         if( i > 10 && i < 16 )
  744.         {
  745.             sprites[i]->Set_Pos_X( sprites[i]->startposx += 5, 1 );
  746.         }
  747.     }
  748.  
  749.     // fps display position
  750.     sprites[0]->Set_Pos( 15, 5, 1 );
  751.     // average
  752.     sprites[1]->Set_Pos( 290, 5, 1 );
  753.     // speedfactor
  754.     sprites[2]->Set_Pos( 480, 5, 1 );
  755.  
  756.     // Debug type text
  757.     sprites[4]->Set_Image( pFont->Render_Text( pFont->font_small, _("Level"), lightblue ), 0, 1 );
  758.     sprites[16]->Set_Image( pFont->Render_Text( pFont->font_small, _("Player"), lightblue ), 0, 1 );
  759.  
  760.     counter = 0;
  761. }
  762.  
  763. cDebugDisplay :: ~cDebugDisplay( void )
  764. {
  765.     pGuiSystem->getGUISheet()->removeChildWindow( window_debugtext );
  766.     CEGUI::WindowManager::getSingleton().destroyWindow( window_debugtext );
  767.  
  768.     for( HudSpriteList::iterator itr = sprites.begin(), itr_end = sprites.end(); itr != itr_end; ++itr )
  769.     {
  770.         delete *itr;
  771.     }
  772.  
  773.     sprites.clear();
  774. }
  775.  
  776. void cDebugDisplay :: Update( void )
  777. {
  778.     // no text to display
  779.     if( text.empty() )
  780.     {
  781.         return;
  782.     }
  783.  
  784.     // if time reached hide the text display
  785.     if( counter <= 0 )
  786.     {
  787.         text.clear();
  788.         text_old.clear();
  789.  
  790.         text_debugtext->setVisible( 0 );
  791.         return;
  792.     }
  793.  
  794.     // update counter
  795.     counter -= pFramerate->speedfactor;
  796.  
  797.     // set new text
  798.     if( text.compare( text_old ) != 0 )
  799.     {
  800.         text_old = text;
  801.         CEGUI::String gui_text = reinterpret_cast<const CEGUI::utf8*>(text.c_str());
  802.  
  803.         // display the new text
  804.         text_debugtext->setText( gui_text );
  805.         text_debugtext->setVisible( 1 );
  806.  
  807.         // update position
  808.         CEGUI::Font *font = CEGUI::FontManager::getSingleton().getFont( "bluebold_medium" );
  809.         float text_width = font->getTextExtent( gui_text ) * global_downscalex;
  810.  
  811.         text_debugtext->setWidth( CEGUI::UDim( 0, ( text_width + 15 ) * global_upscalex ) );
  812.         text_debugtext->setXPosition( CEGUI::UDim( 0, ( game_res_w / 2 - text_width / 2 ) * global_upscalex ) );
  813.     }
  814. }
  815.  
  816. void cDebugDisplay :: Draw( cSurfaceRequest *request /* = NULL */ )
  817. {
  818.     // debug mod info
  819.     Draw_Debug_Mode();
  820.     Draw_Performance_Debug_Mode();
  821. }
  822.  
  823. void cDebugDisplay :: Set_Text( string ntext, float display_time /* = speedfactor_fps * 2 */ )
  824. {
  825.     text = ntext;
  826.  
  827.     if( text.empty() )
  828.     {
  829.         text = text_old;
  830.         text_old.empty();
  831.  
  832.         counter = 0;
  833.         return;
  834.     }
  835.  
  836.     counter = display_time;
  837. }
  838.  
  839. void cDebugDisplay :: Draw_fps( void )
  840. {
  841.     // ### Frames per Second
  842.     sprites[0]->Set_Image( pFont->Render_Text( pFont->font_very_small, _("FPS : best ") + int_to_string( static_cast<int>(pFramerate->fps_best) ) + _(", worst ") + int_to_string( static_cast<int>(pFramerate->fps_worst) ) + _(", current ") + int_to_string( static_cast<int>(pFramerate->fps) ), white ), 0, 1 );
  843.     // average
  844.     sprites[1]->Set_Image( pFont->Render_Text( pFont->font_very_small, _("average ") + int_to_string( static_cast<int>(pFramerate->fps_average) ), white ), 0, 1 );
  845.     // speedfactor
  846.     sprites[2]->Set_Image( pFont->Render_Text( pFont->font_very_small, _("Speedfactor ") + float_to_string( pFramerate->speedfactor, 4 ), white ), 0, 1 );
  847. }
  848.  
  849. void cDebugDisplay :: Draw_Debug_Mode( void )
  850. {
  851.     if( !game_debug || ( Game_Mode == MODE_LEVEL && pPlayer->maryo_type == MARYO_DEAD ) ) 
  852.     {
  853.         return;
  854.     }
  855.  
  856.     /* ### Extend
  857.     - Ground Object name, position and velocity
  858.     */
  859.  
  860.     // black background
  861.     Color color = blackalpha128;
  862.     pVideo->Draw_Rect( static_cast<float>(game_res_w) - 205, static_cast<float>(game_res_h) * 0.08f, 190, 390, posz - 0.00001f, &color );
  863.  
  864.     // Active objects rect
  865.  
  866.     // create request
  867.     cRectRequest *request = new cRectRequest();
  868.     pVideo->Draw_Rect( sprites[11]->posx - 4, sprites[11]->posy - 4, 135, 95, posz, &white, request );
  869.  
  870.     // not filled
  871.     request->filled = 0;
  872.  
  873.     // add request
  874.     pRenderer->Add( request );
  875.  
  876.     // fps
  877.     Draw_fps();
  878.  
  879.     string temp_text;
  880.  
  881.     // Camera position
  882.     temp_text = _("Camera : X ") + int_to_string( static_cast<int>(pActive_Camera->x) ) + ", Y " + int_to_string( static_cast<int>(pActive_Camera->y) );
  883.     sprites[3]->Set_Image( pFont->Render_Text( pFont->font_very_small, temp_text, white ), 0, 1 );
  884.  
  885.     // Level information
  886.     if( pActive_Level->levelfile.compare( level_old ) != 0 ) 
  887.     {
  888.         string lvl_text = _("Name : ") + Get_Filename( pActive_Level->data_file, 0, 0 );
  889.         level_old = pActive_Level->levelfile;
  890.  
  891.         sprites[5]->Set_Image( pFont->Render_Text( pFont->font_very_small, lvl_text, white ), 0, 1 );
  892.     }
  893.  
  894.     // Level objects
  895.     if( obj_counter != static_cast<int>(pActive_Sprite_Manager->size()) )
  896.     {
  897.         obj_counter = pActive_Sprite_Manager->size();
  898.  
  899.         temp_text = _("Objects : ") + int_to_string( obj_counter );
  900.         sprites[6]->Set_Image( pFont->Render_Text( pFont->font_very_small, temp_text, white ), 0, 1 );
  901.     }
  902.     // Passive
  903.     if( pass_counter != static_cast<int>(pActive_Sprite_Manager->Get_Size_Array( ARRAY_PASSIVE ) + pActive_Sprite_Manager->Get_Size_Array( ARRAY_FRONT_PASSIVE )) )
  904.     {
  905.         pass_counter = pActive_Sprite_Manager->Get_Size_Array( ARRAY_PASSIVE ) + pActive_Sprite_Manager->Get_Size_Array( ARRAY_FRONT_PASSIVE );
  906.  
  907.         temp_text = _("Passive : ") + int_to_string( pass_counter );
  908.         sprites[7]->Set_Image( pFont->Render_Text( pFont->font_very_small, temp_text, white ), 0, 1 );
  909.     }
  910.     // Massive
  911.     if( mass_counter != static_cast<int>(pActive_Sprite_Manager->Get_Size_Array( ARRAY_MASSIVE )) )
  912.     {
  913.         mass_counter = pActive_Sprite_Manager->Get_Size_Array( ARRAY_MASSIVE );
  914.  
  915.         temp_text = _("Massive : ") + int_to_string( mass_counter );
  916.         sprites[8]->Set_Image( pFont->Render_Text( pFont->font_very_small, temp_text, white ), 0, 1 );
  917.     }
  918.     // Enemy
  919.     if( enemy_counter != static_cast<int>(pActive_Sprite_Manager->Get_Size_Array( ARRAY_ENEMY )) ) 
  920.     {
  921.         enemy_counter = pActive_Sprite_Manager->Get_Size_Array( ARRAY_ENEMY );
  922.  
  923.         temp_text = _("Enemy : ") + int_to_string( enemy_counter );
  924.         sprites[9]->Set_Image( pFont->Render_Text( pFont->font_very_small, temp_text, white ), 0, 1 );
  925.     }
  926.     // Active
  927.     if( active_counter != static_cast<int>(pActive_Sprite_Manager->Get_Size_Array( ARRAY_ACTIVE )) )
  928.     {
  929.         active_counter = pActive_Sprite_Manager->Get_Size_Array( ARRAY_ACTIVE );
  930.  
  931.         temp_text = _("Active : ") + int_to_string( active_counter );
  932.         sprites[10]->Set_Image( pFont->Render_Text( pFont->font_very_small, temp_text, white ), 0, 1 );
  933.  
  934.         // Halfmassive
  935.         unsigned int halfmassive = 0;
  936.  
  937.         for( SpriteList::iterator itr = pActive_Sprite_Manager->objects.begin(), itr_end = pActive_Sprite_Manager->objects.end(); itr != itr_end; ++itr )
  938.         {
  939.             // get object pointer
  940.             cSprite *obj = (*itr);
  941.  
  942.             if( obj->type == TYPE_HALFMASSIVE )
  943.             {
  944.                 halfmassive++;
  945.             }
  946.         }
  947.  
  948.         temp_text = _("Halfmassive : ") + int_to_string( halfmassive );
  949.         sprites[11]->Set_Image( pFont->Render_Text( pFont->font_very_small, temp_text, white ), 0, 1 );
  950.  
  951.         // Moving Platform
  952.         unsigned int moving_platform = 0;
  953.  
  954.         for( SpriteList::iterator itr = pActive_Sprite_Manager->objects.begin(), itr_end = pActive_Sprite_Manager->objects.end(); itr != itr_end; ++itr )
  955.         {
  956.             // get object pointer
  957.             cSprite *obj = (*itr);
  958.  
  959.             if( obj->type == TYPE_MOVING_PLATFORM )
  960.             {
  961.                 moving_platform++;
  962.             }
  963.         }
  964.  
  965.         temp_text = _("Moving Platform : ") + int_to_string( moving_platform );
  966.         sprites[12]->Set_Image( pFont->Render_Text( pFont->font_very_small, temp_text, white ), 0, 1 );
  967.  
  968.         // Goldbox
  969.         unsigned int goldbox = 0;
  970.  
  971.         for( SpriteList::iterator itr = pActive_Sprite_Manager->objects.begin(), itr_end = pActive_Sprite_Manager->objects.end(); itr != itr_end; ++itr )
  972.         {
  973.             // get object pointer
  974.             cSprite *obj = (*itr);
  975.  
  976.             if( obj->type == TYPE_BONUSBOX )
  977.             {
  978.                 cBonusBox *bonusbox = static_cast<cBonusBox *>(obj);
  979.  
  980.                 if( bonusbox->box_type == TYPE_GOLDPIECE )
  981.                 {
  982.                     goldbox++;
  983.                 }
  984.             }
  985.         }
  986.  
  987.         temp_text = _("Goldbox : ") + int_to_string( goldbox );
  988.         sprites[13]->Set_Image( pFont->Render_Text( pFont->font_very_small, temp_text, white ), 0, 1 );
  989.  
  990.         // Bonusbox
  991.         unsigned int bonusbox = 0;
  992.  
  993.         for( SpriteList::iterator itr = pActive_Sprite_Manager->objects.begin(), itr_end = pActive_Sprite_Manager->objects.end(); itr != itr_end; ++itr )
  994.         {
  995.             // get object pointer
  996.             cSprite *obj = (*itr);
  997.  
  998.             if( obj->type == TYPE_BONUSBOX )
  999.             {
  1000.                 cBonusBox *bonusbox = static_cast<cBonusBox *>(obj);
  1001.  
  1002.                 if( bonusbox->box_type != TYPE_GOLDPIECE )
  1003.                 {
  1004.                     bonusbox++;
  1005.                 }
  1006.             }
  1007.         }
  1008.  
  1009.         temp_text = _("Bonusbox : ") + int_to_string( bonusbox );
  1010.         sprites[14]->Set_Image( pFont->Render_Text( pFont->font_very_small, temp_text, white ), 0, 1 );
  1011.  
  1012.         // Other
  1013.         unsigned int active_other = active_counter - halfmassive - moving_platform - goldbox - bonusbox;
  1014.  
  1015.         temp_text = _("Other : ") + int_to_string( active_other );
  1016.         sprites[15]->Set_Image( pFont->Render_Text( pFont->font_very_small, temp_text, white ), 0, 1 );
  1017.     }
  1018.  
  1019.     // Player information
  1020.     // position x
  1021.     temp_text = "X1 " + float_to_string( pActive_Player->posx, 4 ) + "  X2 " + float_to_string( pPlayer->col_rect.x + pPlayer->col_rect.w, 4 );
  1022.     sprites[17]->Set_Image( pFont->Render_Text( pFont->font_very_small, temp_text, white ), 0, 1 );
  1023.     // position y
  1024.     temp_text = "Y1 " + float_to_string( pActive_Player->posy, 4 ) + "  Y2 " + float_to_string( pPlayer->col_rect.y + pPlayer->col_rect.h, 4 );
  1025.     sprites[18]->Set_Image( pFont->Render_Text( pFont->font_very_small, temp_text, white ), 0, 1 );
  1026.     // velocity
  1027.     temp_text = _("Velocity X ") + float_to_string( pPlayer->velx, 2 ) + " ,Y " + float_to_string( pPlayer->vely, 2 );
  1028.     sprites[19]->Set_Image( pFont->Render_Text( pFont->font_very_small, temp_text, white ), 0, 1 );
  1029.     // moving state
  1030.     temp_text = _("Moving State ") + int_to_string( static_cast<int>(pPlayer->state) );
  1031.     sprites[20]->Set_Image( pFont->Render_Text( pFont->font_very_small, temp_text, white ), 0, 1 );
  1032.     // ground type
  1033.     string ground_type;
  1034.     if( pPlayer->ground_object )
  1035.     {
  1036.         ground_type = int_to_string( pPlayer->ground_object->massivetype ) + " (" + Get_Massive_Type_Name( pPlayer->ground_object->massivetype ) + ")";
  1037.     }
  1038.     temp_text = _("Ground ") + ground_type;
  1039.     sprites[21]->Set_Image( pFont->Render_Text( pFont->font_very_small, temp_text, white ), 0, 1 );
  1040.     // game mode
  1041.     if( Game_Mode != Game_Mode_last )
  1042.     {
  1043.         sprites[22]->Set_Image( pFont->Render_Text( pFont->font_very_small, _("Game Mode : ") + int_to_string( Game_Mode ), white ), 0, 1 );
  1044.     }
  1045.  
  1046.     // draw text
  1047.     for( HudSpriteList::iterator itr = sprites.begin(), itr_end = sprites.end(); itr != itr_end; ++itr )
  1048.     {
  1049.         (*itr)->Draw();
  1050.     }
  1051. }
  1052.  
  1053. void cDebugDisplay :: Draw_Performance_Debug_Mode( void )
  1054. {
  1055.     if( !game_debug_performance ) 
  1056.     {
  1057.         return;
  1058.     }
  1059.  
  1060.     string temp_text;
  1061.     float ypos = game_res_h * 0.08f;
  1062.  
  1063.     // black background
  1064.     Color color = blackalpha128;
  1065.     pVideo->Draw_Rect( 15, ypos, 190, 390, posz - 0.00001f, &color );
  1066.  
  1067.     // don't draw it twice
  1068.     if( !game_debug )
  1069.     {
  1070.         // fps
  1071.         Draw_fps();
  1072.         sprites[0]->Draw();
  1073.         sprites[1]->Draw();
  1074.         sprites[2]->Draw();
  1075.     }
  1076.  
  1077.     vector<string> text_strings;
  1078.     // draw
  1079.     text_strings.push_back( "Draw" );
  1080.     // overworld
  1081.     if( Game_Mode == MODE_OVERWORLD )
  1082.     {
  1083.         text_strings.push_back( _("World : ") + int_to_string( pFramerate->perf_timer[PERF_DRAW_OVERWORLD]->ms ) );
  1084.         text_strings.push_back( "- " );
  1085.         text_strings.push_back( "- " );
  1086.         text_strings.push_back( "- " );
  1087.         text_strings.push_back( "- " );
  1088.     }
  1089.     // menu
  1090.     else if( Game_Mode == MODE_MENU )
  1091.     {
  1092.         text_strings.push_back( _("Menu : ") + int_to_string( pFramerate->perf_timer[PERF_DRAW_MENU]->ms ) );
  1093.         text_strings.push_back( "- " );
  1094.         text_strings.push_back( "- " );
  1095.         text_strings.push_back( "- " );
  1096.         text_strings.push_back( "- " );
  1097.     }
  1098.     // level settings
  1099.     else if( Game_Mode == MODE_LEVEL_SETTINGS )
  1100.     {
  1101.         text_strings.push_back( _("Level Settings : ") + int_to_string( pFramerate->perf_timer[PERF_DRAW_LEVEL_SETTINGS]->ms ) );
  1102.         text_strings.push_back( "- " );
  1103.         text_strings.push_back( "- " );
  1104.         text_strings.push_back( "- " );
  1105.         text_strings.push_back( "- " );
  1106.     }
  1107.     // level (default)
  1108.     else
  1109.     {
  1110.         text_strings.push_back( _("Level Layer 1 : ") + int_to_string( pFramerate->perf_timer[PERF_DRAW_LEVEL_LAYER1]->ms ) );
  1111.         text_strings.push_back( _("Level Player : ") + int_to_string( pFramerate->perf_timer[PERF_DRAW_LEVEL_PLAYER]->ms ) );
  1112.         text_strings.push_back( _("Level Layer 2 : ") + int_to_string( pFramerate->perf_timer[PERF_DRAW_LEVEL_LAYER2]->ms ) );
  1113.         text_strings.push_back( _("Level Hud : ") + int_to_string( pFramerate->perf_timer[PERF_DRAW_LEVEL_HUD]->ms ) );
  1114.         text_strings.push_back( _("Level Editor : ") + int_to_string( pFramerate->perf_timer[PERF_DRAW_LEVEL_EDITOR]->ms ) );
  1115.     }
  1116.     text_strings.push_back( _("Mouse : ") + int_to_string( pFramerate->perf_timer[PERF_DRAW_MOUSE]->ms ) );
  1117.     // update
  1118.     text_strings.push_back( _("Update") );
  1119.     // overworld
  1120.     if( Game_Mode == MODE_OVERWORLD )
  1121.     {
  1122.         text_strings.push_back( _("World : ") + int_to_string( pFramerate->perf_timer[PERF_UPDATE_OVERWORLD]->ms ) );
  1123.         text_strings.push_back( "- " );
  1124.         text_strings.push_back( "- " );
  1125.         text_strings.push_back( "- " );
  1126.         text_strings.push_back( "- " );
  1127.         text_strings.push_back( "- " );
  1128.         text_strings.push_back( "- " );
  1129.     }
  1130.     // menu
  1131.     else if( Game_Mode == MODE_MENU )
  1132.     {
  1133.         text_strings.push_back( _("Menu : ") + int_to_string( pFramerate->perf_timer[PERF_UPDATE_MENU]->ms ) );
  1134.         text_strings.push_back( "- " );
  1135.         text_strings.push_back( "- " );
  1136.         text_strings.push_back( "- " );
  1137.         text_strings.push_back( "- " );
  1138.         text_strings.push_back( "- " );
  1139.         text_strings.push_back( "- " );
  1140.     }
  1141.     // level settings
  1142.     else if( Game_Mode == MODE_LEVEL_SETTINGS )
  1143.     {
  1144.         text_strings.push_back( _("Level Settings : ") + int_to_string( pFramerate->perf_timer[PERF_UPDATE_LEVEL_SETTINGS]->ms ) );
  1145.         text_strings.push_back( "- " );
  1146.         text_strings.push_back( "- " );
  1147.         text_strings.push_back( "- " );
  1148.         text_strings.push_back( "- " );
  1149.         text_strings.push_back( "- " );
  1150.         text_strings.push_back( "- " );
  1151.     }
  1152.     // level (default)
  1153.     else
  1154.     {
  1155.         text_strings.push_back( _("process input : ") + int_to_string( pFramerate->perf_timer[PERF_UPDATE_PROCESS_INPUT]->ms ) );
  1156.         text_strings.push_back( _("level : ") + int_to_string( pFramerate->perf_timer[PERF_UPDATE_LEVEL]->ms ) );
  1157.         text_strings.push_back( _("level editor : ") + int_to_string( pFramerate->perf_timer[PERF_UPDATE_LEVEL_EDITOR]->ms ) );
  1158.         text_strings.push_back( _("hud : ") + int_to_string( pFramerate->perf_timer[PERF_UPDATE_HUD]->ms ) );
  1159.         text_strings.push_back( _("player : ") + int_to_string( pFramerate->perf_timer[PERF_UPDATE_PLAYER]->ms ) );
  1160.         text_strings.push_back( _("collisions : ") + int_to_string( pFramerate->perf_timer[PERF_UPDATE_COLLISIONS]->ms ) );
  1161.         text_strings.push_back( _("camera : ") + int_to_string( pFramerate->perf_timer[PERF_UPDATE_CAMERA]->ms ) );
  1162.     }
  1163.  
  1164.     // render
  1165.     text_strings.push_back( _("Rendering : ") + int_to_string( pFramerate->perf_timer[PERF_RENDERING]->ms ) );
  1166.  
  1167.  
  1168.     unsigned int pos = 0;
  1169.  
  1170.     for( vector<string>::iterator itr = text_strings.begin(), itr_end = text_strings.end(); itr != itr_end; ++itr )
  1171.     {
  1172.         // sections
  1173.         float xpos = 20;
  1174.         ypos += 12;
  1175.  
  1176.         if( pos != 0 && pos != 7 )
  1177.         {
  1178.             xpos += 10;
  1179.         }
  1180.         if( pos == 7 || pos == 15 )
  1181.         {
  1182.             ypos += 10;
  1183.         }
  1184.  
  1185.         string current_text = (*itr);
  1186.  
  1187.         GL_Surface *surface_temp = pFont->Render_Text( pFont->font_small, current_text, white );
  1188.  
  1189.         // create request
  1190.         cSurfaceRequest *request = new cSurfaceRequest();
  1191.         surface_temp->Blit( xpos, ypos, posz, request );
  1192.         request->delete_texture = 1;
  1193.  
  1194.         // shadow
  1195.         request->shadow_pos = 1;
  1196.         request->shadow_color = black;
  1197.  
  1198.         // add request
  1199.         pRenderer->Add( request );
  1200.  
  1201.         surface_temp->auto_del_img = 0;
  1202.         delete surface_temp;
  1203.         
  1204.         pos++;
  1205.     }
  1206. }
  1207.  
  1208. /* *** *** *** *** *** cGoldDisplay *** *** *** *** *** *** *** *** *** *** *** *** */
  1209.  
  1210. cGoldDisplay :: cGoldDisplay( float x /* = 0 */, float y /* = 0 */ )
  1211. : cStatusText( x, y )
  1212. {
  1213.     sprite_array = ARRAY_HUD;
  1214.     type = TYPE_GOLDDISPLAY;
  1215.  
  1216.     Set_Gold( pPlayer->goldpieces );
  1217. }
  1218.  
  1219. cGoldDisplay :: ~cGoldDisplay( void )
  1220. {
  1221.     //
  1222. }
  1223.  
  1224. void cGoldDisplay :: Draw( cSurfaceRequest *request /* = NULL */ )
  1225. {
  1226.     if( editor_enabled || Game_Mode == MODE_MENU ) 
  1227.     {
  1228.         return;
  1229.     }
  1230.  
  1231.     cHudSprite::Draw();
  1232. }
  1233.  
  1234. void cGoldDisplay :: Set_Gold( int gold )
  1235. {
  1236.     if( gold >= 100 )
  1237.     {
  1238.         gold -= 100;
  1239.         pAudio->Play_Sound( "item/live_up_2.ogg" );    
  1240.         livedisplay->Add_Lives( 1 );
  1241.  
  1242.         pointsdisplay->Add_Points( 0, pPlayer->posx + pPlayer->image->w/3, pPlayer->posy + 5, "1UP", lightred );
  1243.     }
  1244.     
  1245.     pPlayer->goldpieces = gold;
  1246.     string text = int_to_string( pPlayer->goldpieces );
  1247.  
  1248.     Color color = Color( static_cast<Uint8>(255), 255, 255 - ( gold * 2 ) );
  1249.  
  1250.     Set_Image( pFont->Render_Text( pFont->font_normal, text, color ), 0, 1 );
  1251. }
  1252.  
  1253. void cGoldDisplay :: Add_Gold( int gold )
  1254. {
  1255.     Set_Gold( pPlayer->goldpieces + gold );
  1256. }
  1257.  
  1258.  
  1259. /* *** *** *** *** *** cLiveDisplay *** *** *** *** *** *** *** *** *** *** *** *** */
  1260.  
  1261. cLiveDisplay :: cLiveDisplay( float x /* = 0 */, float y /* = 0 */ )
  1262. : cStatusText( x, y )
  1263. {
  1264.     sprite_array = ARRAY_HUD;
  1265.     type = TYPE_LIFEDISPLAY;
  1266.  
  1267.     Set_Lives( pPlayer->lives );
  1268.  
  1269.     Set_Image( NULL );
  1270. }
  1271.  
  1272. cLiveDisplay :: ~cLiveDisplay( void )
  1273. {
  1274.     //
  1275. }
  1276.  
  1277. void cLiveDisplay :: Draw( cSurfaceRequest *request /* = NULL */ )
  1278. {
  1279.     if( editor_enabled || Game_Mode == MODE_MENU ) 
  1280.     {
  1281.         return;
  1282.     }
  1283.  
  1284.     cHudSprite::Draw();
  1285. }
  1286.  
  1287. void cLiveDisplay :: Set_Lives( int lives )
  1288. {
  1289.     pPlayer->lives = lives;
  1290.     
  1291.     if( lives >= 0 )
  1292.     {
  1293.         string text;
  1294.  
  1295.         // if not in Overworld
  1296.         if( Game_Mode != MODE_OVERWORLD )
  1297.         {
  1298.             text = int_to_string( pPlayer->lives ) + "x";
  1299.         }
  1300.         else
  1301.         {
  1302.             text = _("Lives : ") + int_to_string( pPlayer->lives );
  1303.         }
  1304.     
  1305.         Set_Image( pFont->Render_Text( pFont->font_normal, text, green ), 0, 1 );
  1306.     }
  1307. }
  1308.  
  1309. void cLiveDisplay :: Add_Lives( int lives )
  1310. {
  1311.     Set_Lives( pPlayer->lives + lives );
  1312. }
  1313.  
  1314. /* *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** */
  1315.  
  1316. cPlayerPoints *pointsdisplay = NULL;
  1317. cDebugDisplay *debugdisplay = NULL;
  1318. cGoldDisplay *golddisplay = NULL;
  1319. cLiveDisplay *livedisplay = NULL;
  1320. cTimeDisplay *timedisplay = NULL;
  1321. cItemBox *Itembox = NULL;
  1322.