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

namespace HH
{
    class CBasic
    {
        //public bool alive = false;
        public Vector position ;
        public Vector velocity ;
        public Box hitboxDiff ;

        public double speed;
        public double level;

        public uint life;

        public bool isAlive ;
        
        
        public int graphicsHandle;
        public int destroySoundHandle;
        //GraphicPositionDiff

        public CType kind = CType.Enemy;
        public int timer = 0;
        public string scriptfile;

        public AttackSequence atk;

        public Vector graphicPosition;

        public CBasic()
        {

            this.position = new Vector(0, 0);
            this.velocity = new Vector(0, 0);
            this.hitboxDiff = new Box(new Vector(-2, -2), new Vector(2, 2));
            this.graphicPosition = new Vector(-12, -12);
            this.isAlive = true;
            this.life = 1;
        }

        //真下に打つ。そのための的。
        public static CBasic virtualCharacter(CBasic somecharacter)
        {
            CBasic returnedCharacter = new CBasic();

            returnedCharacter.position = new Vector(somecharacter.position.x, 480);
            returnedCharacter.velocity = new Vector(0, 0);
            returnedCharacter.hitboxDiff = new Box(new Vector(-2, -2), new Vector(2, 2));
            returnedCharacter.isAlive = true;
            returnedCharacter.life = 1;

            return returnedCharacter;
        }

        public Box HitBoxABS
        {
            get
            {
                return new Box(position + hitboxDiff.topLeft,
                                position + hitboxDiff.bottomRight);
            }
        }

        public Vector graphicPositionABS
        {
            get
            {
                return this.position + this.graphicPosition;
            }
        }

        public enum CType
        {
            Enemy,
            EnemyBullet, 
            Player, 
            PlayerBullet,
            Item
        }

        
        public virtual void update()
        {
            this.position = this.position + this.velocity;
            isInScreen();

        }

        public void draw()
        {
            DX.DrawGraph((int) this.graphicPositionABS.x , (int) this.graphicPositionABS.y , graphicsHandle, DX.TRUE);
        }

        public bool isInScreen()
        {
            if (this.isAlive == false) { return false; }

            if (this.position.x >= 0 && this.position.x <= 640
                && this.position.y >= 0 && this.position.y <= 480)
            { this.isAlive = true; return true; }
            else
            { this.isAlive = false; return false;  }
        
        }
    }
}
