/*!

	鮫亀スクロールするBG部分

*/
#if defined SCROLLBG_INCLUDED___
  #endinput
#endif
#define SCROLLBG_INCLUDED___

#include "types.inc"

//////////////////////////////////////////////////////////////////////////////////

static obj:g_ScrollBG[9];		//背景
static float:g_ScrollSpeed;
static g_Direction;

//////////////////////////////////////////////////////////////////////////////////

//////////////////////////////////////////////////////////////////////////////////

enum {
	SCROLLBG_RIGHTDOWN,
	SCROLLBG_LEFTDOWN,
}


//////////////////////////////////////////////////////////////////////////////////

public ScrollBGAction() {

	new tmp_string[128];
	new float:speed;
	new dir;

	GetArg("speed", tmp_string);
 	speed = atof(tmp_string);

	GetArg("dir", tmp_string);
 	dir = atoi(tmp_string);


	new float:tmp_x, float:tmp_y, float:tmp_z;
	GetPos(Self(), tmp_x, tmp_y, tmp_z);

	for (;;) {

		switch (dir) {
			case SCROLLBG_LEFTDOWN: {
//				AnimMoveLine(Self(), -160.0, 799.0, 1.0, 1000.0);
//				wait(1000);
//				SetPos(Self(), 799.0, -160.0, 1.0);
				tmp_x -= speed;
				if (tmp_x < -160.0) {
					tmp_x = 799.0;
				}

				tmp_y += speed;
				if (tmp_y > 799.0) {
					tmp_y = -160.0;
				}
			}
			case SCROLLBG_RIGHTDOWN: {
//				AnimMoveLine(Self(), 799.0, 799.0, 1.0, 1000.0);
//				wait(1000);
//				SetPos(Self(), -160.0, -160.0, 1.0);
				tmp_x += speed;
				if (tmp_x > 799.0) {
					tmp_x = -160.0;
				}

				tmp_y += speed;
				if (tmp_y > 799.0) {
					tmp_y = -160.0;
				}

			}
		}

//		printf("%f\n", tmp_y);

		SetPos(Self(), tmp_x, tmp_y, tmp_z);

		sleep;
	}
}

//////////////////////////////////////////////////////////////////////////////////
/*!
	駒の作成をする
*/
stock ScrollBGCreate(const filename[], const float:speed = 0.5, const direction = SCROLLBG_RIGHTDOWN) {

	ScrollBGDestroy();

	g_ScrollSpeed = speed;
	g_Direction = direction;

//	new texture:tex_id = TextureLoad("./texture/kabegami01.png", false);
	new texture:tex_id = TextureLoad(filename, false);

	new i = 0;
	for (new y = 0; y < 3; y++) {
		for (new x = 0; x < 3; x++) {
			g_ScrollBG[i] = obj:CreateCharacterObject(
							x * 320.0 - 160.0, y * 320.0 - 240.0,
//							320.0, 224.0,
							320.0, 320.0,
							tex_id, _,
							ZSORT_NORMAL, 1.0);

			new args[256];
			sprintf(args, "speed = %f; dir = %d", g_ScrollSpeed, g_Direction);
			AttachScript(obj:g_ScrollBG[i], "ScrollBGAction", _, args);
			i++;
		}
	}
	ScrollBGHide();
}

stock ScrollBGDestroy() {
	ArrayDestroyObject(g_ScrollBG);
}

stock ScrollBGHide() {
	ArrayHideObject(g_ScrollBG);
}
stock ScrollBGShow() {
	ArrayShowObject(g_ScrollBG);
}