// Inclusione delle classi create
#include "Helicopter.h"
#include "Wall.h"
// Inclusione di allegro
#include "allegro.h"
// Variabili
BITMAP *buf, *menuIniziale, *background, *scrolling;
PALETTE colors;
MIDI *music;
FONT *metersFont;
SAMPLE *newRecord;
int xScroll = 0;
int scrollSpeed = 3.5;
double meters = 0;
double record = 0;
bool sound = false;
// Prototipi di funzione
void doubleBuffering ( void );
void backgroundScroll ( void );
void makeMenu ( void );
void doubleBuffering ( void )
{
vsync();
blit ( buf, screen, 0, 0, 0, 0, 700, 500 );
clear ( buf );
}
void backgroundScroll ( void )
{
xScroll += scrollSpeed;
blit ( scrolling, buf, xScroll, 0, 0, 0, 700, 500 );
if ( xScroll >= 700 )
xScroll = 0;
}
void makeMenu ( void )
{
blit ( menuIniziale, buf, 0, 0, 0, 0, 700, 500 );
}
int main ( void )
{
allegro_init();
install_keyboard();
set_color_depth ( 32 );
set_palette ( colors );
set_gfx_mode ( GFX_AUTODETECT, 700, 500, 0, 0 );
install_sound ( DIGI_AUTODETECT, MIDI_AUTODETECT, 0 );
set_volume ( 200, 200 );
buf = create_bitmap ( 700, 500 );
clear ( buf );
scrolling = create_bitmap ( 1400, 500 );
clear ( scrolling );
menuIniziale = load_bmp ( "MenuIniziale.bmp", colors );
background = load_bmp ( "Background.bmp", colors );
music = load_midi ( "Music.mid" );
metersFont = load_font ( "MetersFont.pcx", NULL, NULL );
newRecord = load_wav ( "OhYeah.wav" );
play_midi ( music, TRUE );
for ( int i = 0; i <= 1400; i += 700 )
blit ( background, scrolling, 0, 0, i, 0, 700, 500 );
// Instanziamo gli oggetti
Helicopter helicopter;
Wall wall;
while ( !key[KEY_ESC] )
{
helicopter.setY();
wall.setX();
meters = 0;
xScroll = 0;
scrollSpeed = 3.5;
sound = false;
while ( !key[KEY_ENTER] )
{
doubleBuffering();
makeMenu();
textprintf ( buf, metersFont, 500, 150, makecol ( 0, 255, 0 ), "%i", static_cast<int>( record ) );
if ( key[KEY_ESC] )
return EXIT_SUCCESS;
}
while ( !key[KEY_ESC] )
{
doubleBuffering();
backgroundScroll();
helicopter.makeHelicopter ( buf );
helicopter.moveHelicopter();
wall.makeWall ( buf );
wall.moveWall ( scrollSpeed );
// Aumento delle velocità
if ( static_cast<int> ( meters ) % 100 == 0 )
{
scrollSpeed += 2.5;
meters += 1;
}
//Aumento dei metri
meters = meters + ( 0.1 * ( scrollSpeed * 0.1 ) );
//Output che indica la distanza percorsa
textprintf ( buf, metersFont, 0, 0, makecol ( 0, 255, 0 ), "%i", static_cast<int>( meters ) );
//Collisione fra Elicottero e Wall
if ( ( ( wall.getX() <= 197 ) && ( ( wall.getX() + 34 ) >= 110 ) ) && ( wall.getY() <= ( helicopter.getY() + 40 ) && ( ( wall.getY() + 106 ) >= helicopter.getY() ) ) )
{
if ( meters > record )
record = meters;
break;
}
if ( helicopter.getY() < 65 )
{
if ( meters > record )
record = meters;
break;
}
if ( helicopter.getY() > 405 )
{
if ( meters > record )
record = meters;
break;
}
if ( meters > record && sound == false )
{
play_sample ( newRecord, 255, 128, 1000, FALSE );
sound = true;
}
if ( record + 15 > meters && sound == true )
textprintf ( buf, metersFont, 300, 0, makecol ( 0, 255, 0 ), "NEW RECORD!" );
}
}
destroy_bitmap ( buf );
destroy_bitmap ( menuIniziale );
destroy_bitmap ( scrolling );
destroy_bitmap ( background );
return EXIT_SUCCESS;
}
END_OF_MAIN();