User:Navarr/PoKéQuesT/src/main.c

From WiiBrew
Jump to: navigation, search
// Libraries
	#include <wiiuse/wpad.h>
	#include <ogc/lwp_watchdog.h>
	#include <wiisprite.h>
	#include <mp3player.h>

// Graphics
	#include "aurora_png.h"
	#include "banner_png.h"

// Music
	#include "syst002_mp3.h"

using namespace wsp;

// Variables
	GameWindow gwd;

	Sprite logo;
	Image logoImage;

	Sprite backdrop;
	Image bgImage;


// Return to Loader
	void gotoLoader()
	{
		gwd.SetBackground((GXColor){0,0,0,255});	// Set Background Black
		gwd.Flush();					// Flush the Output
		if (MP3Player_IsPlaying()) { MP3Player_Stop(); }
		exit(0);					// Exit without Errors
	}

// Main Function
	int main(int argc, char **argv)
	{
		gwd.InitVideo();
		LayerManager manager(3);
		
		// Set the Background Black
			gwd.SetBackground((GXColor){0,0,0,255});

		// Load the PoKéQuesT Logo
			if(logoImage.LoadImage(banner_png) != IMG_LOAD_ERROR_NONE) exit(0);
			logo.SetImage(&logoImage);
		// Position it
			logo.SetPosition(88,0);
			manager.Append(&logo);

		// Load the Background
			if(bgImage.LoadImage(aurora_png) != IMG_LOAD_ERROR_NONE) exit(0);
			backdrop.SetImage(&bgImage);
		// Position it
			backdrop.SetPosition(10,10);
			manager.Append(&backdrop);
		
		// Get Wiimote Working
			WPAD_Init();
			WPAD_SetDataFormat(WPAD_CHAN_0, WPAD_FMT_BTNS_ACC_IR);

		// Music!
			MP3Player_Init();
			MP3Player_PlayBuffer(syst002_mp3,syst002_mp3_size,NULL);

		// Start Thread for Home Button
		//	lwp_t homeButtonThread;
		//	LWP_CreateThread(&homeButtonThread,homeButton,NULL,NULL,0,80);

		while(true)
		{
			if (!MP3Player_IsPlaying()) { MP3Player_PlayBuffer(syst002_mp3,syst002_mp3_size,NULL); }
			WPAD_ScanPads();
			if (WPAD_ButtonsDown(0) & WPAD_BUTTON_HOME) { gotoLoader(); }
			manager.Draw(0,0);
			gwd.Flush();
		}
		manager.Draw(0,0);
		gwd.Flush();
		return 0;
	}