Questo sito utilizza cookies solo per scopi di autenticazione sul sito e nient'altro. Nessuna informazione personale viene tracciata. Leggi l'informativa sui cookies.
Username: Password: oppure
Explosive Race - Main.cpp

Main.cpp

Caricato da: RiccardoG97
Scarica il programma completo

  1. // Main.cpp
  2. // Progetto: Explosive Race
  3.  
  4. // Inclusione della libreria allegro
  5. #include "allegro.h"
  6.  
  7. #include <cstdlib>
  8. #include <ctime>
  9. using std::rand;
  10. using std::srand;
  11.  
  12. // Inclusione delle classi create
  13. #include "Car.h"
  14. #include "Dynamite.h"
  15.  
  16. // Dichiarazione delle variabili
  17. BITMAP *buf, *menuIniziale, *background, *scrolling, *explosion;
  18. PALETTE colors;
  19. MIDI *music;
  20. SAMPLE *speedUp;
  21. FONT *pointsFont;
  22. int yScroll = 0;
  23. int speed = 3;
  24. double points = 1;
  25. bool showDynamite = false;
  26.  
  27.  
  28. // Prototipi di funzione
  29. void doubleBuffering ( void );
  30. void makeMenu ( void );
  31. void makeBackground ( void );
  32.  
  33. // Funzioni
  34. void doubleBuffering ( void )
  35. {
  36.     vsync();
  37.     blit ( buf, screen, 0, 0, 0, 0, 600, 640 );
  38.     clear ( buf );
  39. }
  40.  
  41. void makeMenu ( void )
  42. {
  43.     blit ( menuIniziale, buf, 0, 0, 0, 0, 600, 640 );
  44. }
  45.  
  46. void makeBackground ( void )
  47. {
  48.     yScroll -= speed;
  49.     blit ( scrolling, buf, 0, yScroll, 0, 0, 600, 640 );
  50.     if ( yScroll <= 0 )
  51.         yScroll = 640;
  52. }
  53.  
  54. // Inizio del gioco
  55. int main ( void )
  56. {
  57.     srand ( time ( 0 ) );
  58.     allegro_init();
  59.     install_keyboard();
  60.     set_color_depth ( 32 );
  61.     set_palette ( colors );
  62.     set_gfx_mode ( GFX_AUTODETECT, 600, 640, 0, 0 );
  63.     install_sound ( DIGI_AUTODETECT, MIDI_AUTODETECT, 0 );
  64.     music = load_midi ( "Music.mid" );
  65.     speedUp = load_wav ( "SpeedUp.wav" );
  66.     set_volume ( 100, 100 );
  67.     buf = create_bitmap ( 600, 640 );
  68.     clear ( buf );
  69.     scrolling = create_bitmap ( 600, 1280 );
  70.     clear ( scrolling );
  71.     menuIniziale = load_bmp ( "Menu.bmp", colors );
  72.     background = load_bmp ( "Background.bmp", colors );
  73.     explosion = load_bmp ( "Explosion.bmp", colors );
  74.     pointsFont = load_font ( "PointsFont.pcx", NULL, NULL );
  75.     play_midi ( music, TRUE );
  76.  
  77.     for ( int i = 0; i <= 1280; i += 640 )
  78.         blit ( background, scrolling, 0, 0, 0, i, 600, 640 );
  79.  
  80.  
  81.     while ( !key[KEY_ENTER] )
  82.     {
  83.         doubleBuffering();
  84.         makeMenu();
  85.     }
  86.  
  87.     // Creazione degli oggetti
  88.     Car car;
  89.     Dynamite dynamite;
  90.  
  91.     while ( !key[KEY_ESC] )
  92.     {
  93.         doubleBuffering();
  94.         makeBackground();
  95.         points += 0.1;
  96.  
  97.         if ( ( ( dynamite.getY() + 89 ) >= 430 ) && ( dynamite.getY() <= 539 ) )
  98.         {
  99.             if ( ( ( dynamite.getX() + 63 ) >= car.getX() ) && ( dynamite.getX() <= ( car.getX() + 57 ) ) )
  100.             {
  101.                 draw_sprite ( buf, explosion, car.getX(), 430 );
  102.                 textprintf ( buf, pointsFont, 275, 200, makecol ( 0, 0, 255 ), "%i", static_cast<int>( points ) );
  103.                 doubleBuffering();
  104.                 break;
  105.             }
  106.         }
  107.  
  108.         if ( ( static_cast<int> ( points ) % 50 ) == 0 )
  109.         {
  110.             points += 5;
  111.             speed += 2.5;
  112.             play_sample ( speedUp, 255, 128, 1000, FALSE );
  113.         }
  114.  
  115.         textprintf ( buf, pointsFont, 0, 595, makecol ( 0, 0, 255 ), "%i", static_cast<int>( points ) );
  116.  
  117.         dynamite.makeDynamite ( buf );
  118.  
  119.         if ( showDynamite == false )
  120.         {
  121.             showDynamite = true;
  122.         }
  123.  
  124.         if ( showDynamite == true )
  125.             showDynamite = dynamite.moveDynamite ( speed );
  126.  
  127.         car.makeCar ( buf );
  128.         car.moveCar ( speed );
  129.  
  130.     }
  131.  
  132.     allegro_message ( "Bel punteggio! Condividilo con un commento!" );
  133.  
  134.     destroy_bitmap ( menuIniziale );
  135.     destroy_bitmap ( buf );
  136.     destroy_bitmap ( scrolling );
  137.     destroy_bitmap ( explosion );
  138.     destroy_bitmap ( background );
  139.     destroy_midi ( music );
  140.  
  141.     return EXIT_SUCCESS;
  142. }
  143. // Fine del gioco
  144. END_OF_MAIN();