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

using System.Drawing;

namespace pcd_g1
{
    class SwimmingMainCharacterStageObject : MainCharacterStageObject
    {
        public SwimmingMainCharacterStageObject(int x, int y, Stage stg)
            : base(x, y, stg)
        {
            isFloating = true;
        }

        const int SPEED_ADD = 1;

        public override void Update(int keyStatus, out int vx, out int vy)
        {
            if ((keyStatus & (int)MainForm.KEYBOARD.Up) != 0)
            {
                speedY -=  SPEED_ADD;
				if (speedY < -10) speedY = -10;
            }
			else if ((keyStatus & (int)MainForm.KEYBOARD.Down) != 0)
			{
				speedY += SPEED_ADD;
				if (speedY > 10) speedY = 10;
			}
			else
			{
				if (speedY > 0)
				{
					speedY -= 0.2;
					if (speedY < 0) speedY = 0;
				}
				else if (speedY < 0)
				{
					speedY += 0.2;
					if (speedY > 0) speedY = 0;
				}
			}
            if ((keyStatus & (int)MainForm.KEYBOARD.Right) != 0)
            {
                if (StageManager.CurrentDataSet.GetInt("event7") > 0)
                {
                    speedX += 5;
                }
            }
            
            base.Update(keyStatus, out vx, out vy);
        }

        int animationCount = 0;
        public override void Draw(Graphics g, int width, int height)
        {

            string imageName;

            imageName = character_number.ToString();

            if (moveDirection == direction.Left)
            {
                imageName += "2-";
            }
            else
            {
                imageName += "3-";
            }

            if (speedX == 0)
            {
                imageName += "1";
            }
            else
            {
                imageName += (animationCount < 10 ? "1" : (animationCount < 20 ? "2" : (animationCount < 30 ? "1" : "3")));
            }
            animationCount++;
            if (animationCount >= 40) animationCount = 0;

            g.DrawImage(ImageManager.Search(imageName), 0, 0);
        }
    }
}
