#include <wiisprite.h>
#include <fat.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <wiiuse/wpad.h>
#include <snd.h>
#include <fcntl.h>
#include "oggplayer.h"
#include "missilecommand.h"

using namespace wsp;

extern u32 MAXMISSILES;

int main(int argc, char **argv)
{
  srand(time(NULL));

	GameWindow gwd;
	gwd.InitVideo();
	WPAD_Init();
  WPAD_SetDataFormat(WPAD_CHAN_0, WPAD_FMT_BTNS_ACC_IR);

	fatInitDefault();

  SND_Init(INIT_RATE_48000);
  SND_Pause(0);

  PlayOgg(open("bgm.ogg", O_RDONLY, 0), 0, OGG_INFINITE_TIME);

	Game game;
	gwd.SetBackground((GXColor){0,0,0,0});
	
  game.initialize();
  game.activate();

  while(1) {
		WPAD_ScanPads();
		if(WPAD_ButtonsDown(0)&WPAD_BUTTON_HOME)
			break;
    if(WPAD_ButtonsDown(0)&WPAD_BUTTON_PLUS) {
      if(WPAD_ButtonsHeld(0) & WPAD_BUTTON_1)
        MAXMISSILES = 10;
      else if(WPAD_ButtonsHeld(0) & WPAD_BUTTON_2)
        MAXMISSILES = 100;
      game.initialize();
      game.activate();
    }
		game.update();
    game.draw();

		gwd.Flush();
	}
}
