using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Xml.Linq;

namespace pcd_g1
{

	class startStage : ScrollableStage
	{
		public HPWidghet HPWidghet { get; private set; }

		public startStage() : base()
		{
			//初期設定
			ScrollRangeX = 640 * 7 + 32;			//ステージのサイズ
			ScrollRangeY = 480;
			MainCharacter = new MainCharacterStageObject(32, 32, this);

			for (int i = 0; i < 640*7; i += 32)
			{
				Add(new NormalBlockStageObject(i, 448));
				Add(new NormalBlockStageObject(i, 0));
			}
			for (int i = 0; i < 480; i += 32)
			{
				Add(new NormalBlockStageObject(0, i));
				Add(new NormalBlockStageObject(640 * 6 - 32, i));
			}
			for (int i = 256; i < 1920; i += 32)
				Add(new NormalBlockStageObject(i, 300));

			Add(new KaminariBlockStageObject(200, 300, this));

			//Characterの配置
			Add(new TogeBlockStageObject(300, 268, "865"));
			Add(MainCharacter);

			MainForm.PlaySound("000");

			//HPゲージ
			HPWidghet = new HPWidghet((MainCharacterStageObject)MainCharacter);
			MainForm.form.Widghets.Add(HPWidghet);
			Command.OnMainCharacerDiedCommandCalled += StageCommand_MainCharacterDied;

			//イベント関連の処理
			Command.OnMainCharacerDiedCommandCalled += new MainCharacterDiedEventHandler(StageCommand_MainCharacterDied);
		}

		public void StageCommand_MainCharacterDied()
		{
			MainForm.form.Widghets.Remove(HPWidghet);
		}

		public override void Draw(Graphics g, int width, int height)
		{
			//背景画像の描画
			var imgLoc = new Point(-(ScrollX / 2) % width, -(ScrollY / 2) % height);
			g.DrawImage(ImageManager.Search("back-forest"), imgLoc.X, imgLoc.Y, width, height);
			g.DrawImage(ImageManager.Search("back-forest"), imgLoc.X + width, imgLoc.Y, width, height);
			g.DrawImage(ImageManager.Search("back-forest"), imgLoc.X, imgLoc.Y + height, width, height);
			g.DrawImage(ImageManager.Search("back-forest"), imgLoc.X + width, imgLoc.Y + height, width, height);

			base.Draw(g, width, height);
		}
	}
}