#include <stdio.h>
#include "swis.h"
#include <kernel.h>
#include <time.h>
#include "Sound.h"
#include "Graphics.h"

// SWI Registers
_kernel_swi_regs inreg;
_kernel_swi_regs outreg;

// Sprite buffer
unsigned char *buffer;
extern int screen;
extern struct CompositionElement composition[128];
extern int current_element;
int lastprofile = 0;

int tick = 0;
int lasttick = 0;
extern int screen;

extern int game1_tick();
extern void game1_setup();

int game_hitbox_collide(int x1, int y1, int w1, int h1, int x2, int y2, int w2, int h2)
{
    if((x1 + w1) >= x2)
      if(x1 <= (x2 + w2))
        if((y1 + h1) >= y2)
          if(y1 <= (y2 + h2))
            return 1;

  return 0;
}

int main(int argc, char *argv[])
{
  int lastoutcome = 1;
  int outcome = 0;
  sound_on();

  // Set initial display mode
  display_mode(DISPLAY_MODE);
  screen_clear();

  // Load sprite library
  load_sprites("Spr");

  // Intro titles + music
  intro();

  screen_flipbuffer();
  screen_clear();

  // Mission 1
  while(lastoutcome == 1)
  {
    outcome = 0;
    game1_briefing();
    screen_clear();
    game1_setup();
    while(!outcome)
    {
      outcome = game1_tick();
    }
    lastoutcome = outcome;
  }
  game1_victory();

  lastoutcome = 1;

  // Mission 2
  while(lastoutcome == 1)
  {
    outcome = 0;
    game2_briefing();
    screen_clear();
    //game2_setup();
    while(!outcome)
    {
      outcome = game2_tick();
    }
    lastoutcome = outcome;
  }


  free(buffer);

  return 0;
}
