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

#include	<shinobi.h>
#include	"Nj.h"
#include	<NjDef.h>
#include	"data\ji.spa"
#include	"data\ji.csa"

/*
	
	TEXLIST		spaファイルより
	CELL_SPRITE	spaファイルより
	CELL_STREAM csaファイルより
*/
#define TEXLIST texlist_ji_scene1_ji_model1
#define CELL_SPRITE csprite_ji_scene1_ji_model1
#define CELL_STREAM cstream_ji_scene1_ji_model1


Float	x=60.f,y=300.f,z=0.f;
Float	sx=0.25f,sy=0.25f;
Sint32	rz=0;
Int step = 0;
int fno = 0;
Sint32 *wbuf;
Sint32 *wbuf2;
NJS_CELL_STREAM_LIST streamlist;
NJS_CELL_STREAM_LIST streamlist2;
NJS_CELL_SPRITE_VAL cval;
NJS_CELL_SPRITE_VAL cval2;

/*---------------------------------------------------------------------------
		初期化
		initialize
---------------------------------------------------------------------------*/
Sint32	UserInit(void)
{
	Sint32 size;
	
	if(nuLoadTexture( &TEXLIST ) < 0){
		return USER_EXIT;
	}
	njSetTexture( &TEXLIST );

	size = njCalcCellStreamWorkSize(&CELL_SPRITE,1);
	if((wbuf = syMalloc(size)) == NULL){
		return USER_EXIT;
	}
	njInitCellStreamList(&streamlist,&CELL_SPRITE,wbuf);
	njAddCellStream(&streamlist,&CELL_STREAM);

	size = njCalcCellStreamWorkSize(&CELL_SPRITE,1);
	if((wbuf2 = syMalloc(size)) == NULL){
		syFree(wbuf);
		return USER_EXIT;
	}
	
	njInitCellStreamList(&streamlist2,&CELL_SPRITE,wbuf2);
	njAddCellStream(&streamlist2,&CELL_STREAM);

	njSetCellSpriteAttr( 0xFFFF, NJD_FCA_TR);

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

	syFree(wbuf);
	syFree(wbuf2);

	return USER_CONTINUE;
}
/*---------------------------------------------------------------------------
		メイン
		main
---------------------------------------------------------------------------*/
Sint32	UserMain(void)
{
	Int i,j,t;
	char str[20];

#if DEBUG	
	njPrint(NJM_LOCATION(2,3),"CELLSTREAM SAMPLE [Wink Girl]");
	njPrint(NJM_LOCATION(2,5),"Picture NO.");
	njPrint(NJM_LOCATION(2,8),"PUSH START  MOTION RESET");
	
	njPrintD(NJM_LOCATION(13,5),fno,2);
#endif	
	if(Per->on & PDD_DGT_TA) {
		if(Per->on & PDD_DGT_KU) sy -= 0.01f;
		if(Per->on & PDD_DGT_KD) sy += 0.01f;
		if(Per->on & PDD_DGT_KL) sx -= 0.01f;
		if(Per->on & PDD_DGT_KR) sx += 0.01f;
	}
	else {
			if(Per->on & PDD_DGT_TL) rz += 100.f;
			if(Per->on & PDD_DGT_TR) rz -= 100.f;
			if(Per->on & PDD_DGT_KU) y -= 3.f;
			if(Per->on & PDD_DGT_KD) y += 3.f;
			if(Per->on & PDD_DGT_KL) x -= 3.f;
			if(Per->on & PDD_DGT_KR) x += 3.f;
	}

	cval.flag = NJD_CELLSPRITE_CONSTANT_XYZ|NJD_CELLSPRITE_CONSTANT_ZANG|NJD_CELLSPRITE_CONSTANT_SXSY;
	cval.cst_pos.x = x;
	cval.cst_pos.y = y;
	cval.cst_pos.z = CELL_SPRITE.pos.z + 4.f;

	cval.cst_zang = rz;

	cval.cst_sx = sx;
	cval.cst_sy = sy;

	step = 1;

	fno += step;
	if(fno == CELL_STREAM.timemax) fno = 0;
	
	if(Per->on & PDD_DGT_ST) {
		njResetCellStreamTime(&streamlist); /**/
		fno = 0;
		step = 0;
	}

	njDrawCellStream2D(&streamlist, NULL, step,&cval);
	njDrawCellStream2D(&streamlist2, NULL, step*2,NULL);

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