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

using Microsoft.DirectX;
using Microsoft.DirectX.Direct3D;
using System.Drawing;
using System.Reflection;
using System.Windows.Forms;

namespace DirectX_BallExample
{
    // 自分のキャラクタを示すクラス
    class MyCharacter
    {
        // DirectXのデバイスオブジェクト
        private Device device;

        // 自機座標
        private int x, y;

        // 自機サイズ
        private Size mysize;

        // 動かせる右の最大位置
        private int maxwidth, maxheight;

        private Texture texture;

        public MyCharacter(Device device, int maxwidth, int maxheight)
        {
            this.device = device;
            this.maxwidth = maxwidth;
            this.maxheight = maxheight;

            // テクスチャを作る
            Bitmap bmp = DirectX_BallExample.Properties.Resources.mychar;
            // 白を透明色に
            bmp.MakeTransparent(Color.White);
            mysize = bmp.Size;

            texture = Texture.FromBitmap(
                device, bmp,
                Usage.None, Pool.Managed);

            // 自機の初期位置設定
            this.x = (int)(maxwidth / 2 - mysize.Width / 2);
            this.y = (int)(maxheight - mysize.Height - 10);    // 10ピクセルほど上に
        }

        public int X
        {
            get {return x;}
        }

        public int Y
        {
            get {return y;}
        }

        public Point CenterTop
        {
            // 中心点を返す
            get
            {
                return new Point(X + mysize.Width / 2, Y);
            }
        }


        public Texture CharTexture
        {
            get {return texture;}
        }

        public void MoveX(int add)
        {
            int oldx = x;
            x += add;
            if ((x < 0) || x > maxwidth - mysize.Width)
            {
                x = oldx;
            }
        }

        public void DrawMychar(Sprite sprite)
        {
            // 自機を描画
            sprite.Draw2D(texture, new Point(0, 0), 0, new Point(X, Y), Color.White);
        }
    }
}
