/*---------------------------------------------------------------------------
  Shinobi Sample
  COPYRIGHT (C) SEGA ENTERPRISES, LTD.
---------------------------------------------------------------------------*/

#include	<shinobi.h>
#include	"Nj.h"

#define	OBJECT1	 object_babyn2_Bip01_Bip01
#define	OBJECT2	 object_babyn2_Box01_Box01

#define TEXLIST1 texlist_babyn2_Bip01
#define TEXLIST2 texlist_babyn2_Box01

#define	MOTION1	 motion_backten_Bip01
#define	MOTION2	 motion_bback_Bip01
#define	MOTION3	 motion_facehit_Bip01
#define	MOTION4	 motion_babyn2_Bip01
#define	MOTION5	 motion_robot_Bip01

extern	NJS_CNK_OBJECT	OBJECT1[];
extern	NJS_CNK_OBJECT	OBJECT2[];
extern	NJS_MOTION	MOTION1[];
extern	NJS_MOTION	MOTION2[];
extern	NJS_MOTION	MOTION3[];
extern	NJS_MOTION	MOTION4[];
extern	NJS_MOTION	MOTION5[];
extern NJS_TEXLIST TEXLIST1[];
extern NJS_TEXLIST TEXLIST2[];

/*---------------------------------------------------------------------------
		初期化
		initialize
---------------------------------------------------------------------------*/
Sint32	UserInit(void)
{
	if(nuLoadTexture( TEXLIST1 ) < 0){
		return USER_EXIT;
	}
	if(nuLoadTexture( TEXLIST2 ) < 0){
		return USER_EXIT;
	}

	return USER_CONTINUE;
}
/*---------------------------------------------------------------------------
		終了処理
		exit
---------------------------------------------------------------------------*/
Sint32	UserExit(void)
{
	return USER_CONTINUE;
}

static	Float	zzz = -300.f;
static	Float	xxx = 0.f;
static	Float	yyy = -70.f;

static	Sint32	xx = 0;
static	Sint32	yy = 0;
static	Sint32	zz = 0;

static	Float	mo1=0.f;
static	Float	mo2=0.f;
static	Float	mo3=0.f;
static	Float	mo4=0.f;
static	Float	mo5=0.f;
static	Float	speed=0.5f;

static	Float	inten = 0.8f;
static	Float	ambi  = 0.2f;


static	Sint32	mo=0;

static	NJS_VECTOR	light = { 0.f, 0.f, -1.f };

NJS_QUAD_TEXTURE quad;

/*---------------------------------------------------------------------------
		メイン
		main
---------------------------------------------------------------------------*/
Sint32	UserMain(void)
{
	NJS_VECTOR	l;

//------------------------------------------------------------------
	njPushMatrixEx();

	njSetTexture( TEXLIST1 );

	njPushMatrixEx();
	njRotateXYZ( NULL, Per->y1*120,-Per->x1*120,0 );
	njCalcVector( NULL, &light, &l );
	njPopMatrixEx();

	
	njCnkSetSimpleLight( l.x, l.y, l.z );
	njCnkSetSimpleLightIntensity( inten, ambi );
	njCnkSetSimpleLightColor( 1.0f, 1.0f, 1.0f );
		
	njCnkSetEasyLight( l.x, l.y, l.z );
	njCnkSetEasyLightIntensity( inten, ambi );
	njCnkSetEasyLightColor( 1.0f, 1.0f, 1.0f );
		

	njTranslate( NULL, xxx, yyy, zzz );
	njRotateXYZ( NULL, xx,yy,zz );

	switch( mo ) {
	case 0:
		njCnkEasyDrawMotion( OBJECT1, MOTION1, mo1 );
		mo1 += speed;
		if( mo1 >= (MOTION1->nbFrame-1.0f) ) mo1=0.f;
		break;
	case 1:
		njCnkEasyDrawMotion( OBJECT1, MOTION2, mo2 );
		mo2 += speed;
		if( mo2 >= (MOTION2->nbFrame-1.0f) ) mo2=0.f;
		break;
	case 2:
		njCnkEasyDrawMotion( OBJECT1, MOTION3, mo3 );
		mo3 += speed;
		if( mo3 >= (MOTION3->nbFrame-1.0f) ) mo3=0.f;
		break;
	case 3:
		njCnkEasyDrawMotion( OBJECT1, MOTION4, mo4 );
		mo4 += speed;
		if( mo4 >= (MOTION4->nbFrame-1.0f) ) mo4=0.f;
		break;
	case 4:
		njCnkEasyDrawMotion( OBJECT1, MOTION5, mo5 );
		mo5 += speed;
		if( mo5 >= (MOTION5->nbFrame-1.0f) ) mo5=0.f;
		break;
	}

	njCnkSetSimpleLightIntensity( 0.0f, 1.0f );
	njCnkSetEasyLightIntensity( 0.0f, 1.0f );

	njSetTexture( TEXLIST2 );
	njCnkSimpleDrawObject( OBJECT2 );


	quad.x1 = 20.f;
	quad.y1 = 380.f;
	quad.x2 = 620.f;
	quad.y2 = 440.f;
	quad.u1 = 0.f;
	quad.v1 = 0.f;
	quad.u2 = 1.f;
	quad.v2 = 1.f;
	
	njQuadTextureStart( 1 );
	njSetQuadTexture( 1, 0xffffffff );
	njDrawQuadTexture( &quad, 10.f );
	njQuadTextureEnd();
	
	
	
	
	if (Per->on & PDD_DGT_TA ) {
		if (Per->on & PDD_DGT_KU) 	yyy += 2.f;
		if (Per->on & PDD_DGT_KD) 	yyy -= 2.f;
		if (Per->on & PDD_DGT_KR) 	xxx += 2.f;
		if (Per->on & PDD_DGT_KL) 	xxx -= 2.f;
		if (Per->on & PDD_DGT_TR) 	zzz += 2.f;
		if (Per->on & PDD_DGT_TL) 	zzz -= 2.f;
	}
	else if (Per->on & PDD_DGT_TX ) {
		if (Per->on & PDD_DGT_KU) 	speed += 0.01f;
		if (Per->on & PDD_DGT_KD) 	speed -= 0.01f;
		if( speed <= 0.f ) speed = 0.01f;
	}
	else if (Per->on & PDD_DGT_TB ) {
		if (Per->on & PDD_DGT_KU) 	inten += 0.01f;
		if (Per->on & PDD_DGT_KD) 	inten -= 0.01f;
		if (Per->on & PDD_DGT_KR) 	ambi += 0.01f;
		if (Per->on & PDD_DGT_KL) 	ambi -= 0.01f;
	}
	else {
		if (Per->on & PDD_DGT_KU) 	xx += 200;
		if (Per->on & PDD_DGT_KD) 	xx -= 200;
		if (Per->on & PDD_DGT_KR) 	yy += 200;
		if (Per->on & PDD_DGT_KL) 	yy -= 200;
		if (Per->on & PDD_DGT_TR) 	zz += 200;
		if (Per->on & PDD_DGT_TL) 	zz -= 200;
	}


	if (Per->press & PDD_DGT_TY)	mo++;
	if( mo > 4 ) mo = 0;
	
	if (Per->press & PDD_DGT_ST)	{
		zzz = -300.f;
		xxx = 0.f;
		yyy = -70.f;
		xx = 0;
		yy = 0;
		zz = 0;
		speed = 0.5f;
		inten = 0.8f;
		ambi = 0.2f;
	}

	njPopMatrixEx();

	return USER_CONTINUE;
}
/*-------------------------------------------------------------------------*/
