Example #1
0
        protected AI(string name, Texture tex, int width, int height, int tilesPerRow, int[] keyFrames, float frameLength, bool show, bool stop) : base(name)
        {
            Renderer = new AnimationRenderer(tex, width, height, tilesPerRow, keyFrames, frameLength, show, stop);
            Renderer.RenderOffset = (int)RenderLayer.AI;
            AddComponent(Renderer);
            this.Layer  = (uint)CollisionLayer.Enemy;
            patrolState = new PatrolState(this);
            chaseState  = new ChaseState(this);

            patrolState.Next = chaseState;
            chaseState.Next  = patrolState;

            BoxCollider2D collider = new BoxCollider2D(new Vector2(1, 1));

            collider.CollisionEnter += OnCollisionEnter;
            AddComponent(collider);

            Rigidbody2D rigidBody = new Rigidbody2D();

            rigidBody.IsGravityAffected = false;
            AddComponent(rigidBody);

            AddComponent(new BoxCollider2DRenderer(new Vector4(1f, 0f, 0f, 0f)));
            patrolState.OnStateEnter();

            AddComponent(new FSMUpdater(patrolState));
        }