#include "Graphics.h"

//#defene PROFILE(X) lastprofile = clock(); X; printf("\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t%s %i\n", #X, (clock() - lastprofile))
#define PROFILE(X) X

extern int tick;
extern int lasttick;

void game2_death()
{
  int currentstart = 0;
  int introframe = 0;
  sound_voices(4);

  sound_set_voice(1,"WaveSynth-Beep");
  sound_set_voice(2,"WaveSynth-Beep");
  sound_set_voice(3,"WaveSynth-Beep");
  sound_set_voice(4,"WaveSynth-Beep");
  sound_composition_init();
  
  currentstart += 100;
  sound_composition_element_add(currentstart,1,sound_note("D2"),150);
  currentstart += 100;
  sound_composition_element_add(currentstart,2,sound_note("G2"),200);
  currentstart += 200;
  sound_composition_element_add(currentstart,3,sound_note("B3"),75);
  currentstart += 40;
  sound_composition_element_add(currentstart,4,sound_note("G2"),75);
  currentstart += 50;
  sound_composition_element_add(currentstart,2,sound_note("B3"),200);
  currentstart += 200;
  sound_composition_element_add(currentstart,1,sound_note("A3"),100);
  currentstart += 100;
  sound_composition_element_add(currentstart,3,sound_note("G2"),150);
  currentstart += 150;
  sound_composition_element_add(currentstart,2,sound_note("E2"),100);
  currentstart += 100;
  sound_composition_element_add(currentstart,1,sound_note("D2"),150);
  currentstart += 150;
  sound_composition_element_add(currentstart,3,sound_note("D2"),150);
  currentstart += 100;
  sound_composition_element_add(currentstart,4,sound_note("G2"),150);
  currentstart += 150;
  sound_composition_element_add(currentstart,1,sound_note("B3"),75);
  currentstart += 40;
  sound_composition_element_add(currentstart,2,sound_note("G2"),75);
  currentstart += 40;
  sound_composition_element_add(currentstart,3,sound_note("B3"),150);
  currentstart += 150;
  sound_composition_element_add(currentstart,4,sound_note("A3"),130);
  currentstart += 100;
  sound_composition_element_add(currentstart,1,sound_note("G2"),200);
  currentstart += 300;
  tick = clock();

  sound_composition_start(clock());

  draw_sprite("spacebar",(DISPLAY_X/2)-106,50);
  draw_sprite("kia",(DISPLAY_X/2)-300,500);

  screen_flipbuffer();

  while(sound_composition_incomplete())
  {
    sound_composition_tick(clock());

    if(clock() > (tick + 100))
    {
      if(input_readkey(98))
        sound_composition_stop();
    }
  }
}

void game2_briefing()
{
  screen_clear();

  draw_spritetext(
"~~~~~~~~{chief engineers log - uss archimedes - stardate 1234567890 ~~==========~~===============}\n\n\nYour mission is to be dead until I make mission 2. \n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n~~~~~~~~{==========================================~~~~~~~~=======}"
, 50, 950);

  draw_sprite("spacebar",(DISPLAY_X/2)-106,50);

  screen_flipbuffer();

  tick = clock();
  while(1)
  {
    if(clock() > (tick + 100))
    {
      if(input_readkey(98))
        return;
    }
  }
}

int game2_tick()
{
  lasttick = tick;
  tick = clock();

  screen_flipbuffer();
  screen_clear();

  if(0)
  {
    return 0;
  }else{
    screen_flipbuffer();
    screen_clear();
    game2_death();
    return 1;
  }
  

}
