Example #1
0
        public AI(string AIScriptPath, Character character)
            : base(Constants.AI_EVENT)
        {
            _character = character;
            _AIScriptPath = AIScriptPath;
            _id = Guid.NewGuid();

            //Load AIScript
            _PyRuntime = Python.CreateRuntime();
            LoadAIScript(AIScriptPath);
        }
Example #2
0
        public static void CharGoToChar(Character A, Character target)
        {
            AABB aabb;
            if (A.Direction == Direction.Left)
            {
                aabb.upperBound = World.B2Value(new Vector2(A.Position.X - A.Width / 2, A.Position.Y + A.Height / 2 - 10));
                aabb.lowerBound =
                    World.B2Value(new Vector2(A.Position.X - A.Width / 2 - 80, A.Position.Y - A.Height / 2 + 10));
            }
            else
            {
                aabb.upperBound =
                    World.B2Value(new Vector2(A.Position.X + A.Width / 2 + 80, A.Position.Y + A.Height / 2 - 10));
                aabb.lowerBound = World.B2Value(new Vector2(A.Position.X + A.Width / 2, A.Position.Y - A.Height / 2 + 10));
            }

            A.World.PhysicsWorld.QueryAABB(fixtureProxy =>
            {
                if (fixtureProxy.fixture.IsSensor())
                {
                    return true;
                }
                var unit = fixtureProxy.fixture.GetBody().GetUserData() as Unit;
                if (unit != null)
                {
                    if (unit.Group == Group.Destructable)
                    {
                        A.Do("Walk");
                        A.Do("Jump");
                    }
                }
                return true;
            }, ref aabb);

            if (target.Position.X > A.Position.X)
            {
                if (A.Direction != Direction.Right)
                {
                    A.Do("TurnRight");
                }
            }
            else
            {
                if (A.Direction != Direction.Left)
                {
                    A.Do("TurnLeft");
                }
            }

            A.Do("Walk");
        }
Example #3
0
        public override void Initialize()
        {
            _world = new World(new Vector2(0, 0), EventManager);
            //Player1
            var def = XmlHelper.LoadFromFile<CharacterDef>(@"Data\Hua.xml");
            def.ScaleX = 1.3f;
            def.ScaleY = 1.3f;
            def.Width *= 1.3f;
            def.Height *= 1.3f;
            def.SoundEffects = null;
            _player1 = _world.CreateCharacter(def);

            _player1.Sprite.IsVisible = false;
            Root.Add(_player1.Sprite);

            _unitCam = new UnitCamera(_player1, new Vector2(40.0f, 40.0f),
                new Vector2(80.0f, 80.0f),
                new Vector2(-9550, 465),
                new Vector2(9550, -9550),
                new Vector2(190, 190),
                new Vector3(0.0f, 120.0f, 500.0f));
        }
        private void LoadPlayer()
        {
            //Player1
            var def = XmlHelper.LoadFromFile<CharacterDef>(@"Data\Hua.xml");
            def.ScaleX = 1.3f;
            def.ScaleY = 1.3f;
            def.Width *= 1.3f;
            def.Height *= 1.3f;
            def.MaxHP = 100;
            def.HP = 100;

            _player1 = _world.CreateCharacter(def);

            var hpBar = new HPBar("bloodframe", "blood");
            hpBar.Width = 186;
            hpBar.Height = 20;
            hpBar.X = -93;
            hpBar.Y = 100;
            hpBar.Target = _player1;

            Root.Add(_player1.Sprite);

            //Player2
            def = XmlHelper.LoadFromFile<CharacterDef>(@"Data\Dan1.xml");
            def.ScaleX = 1.2f;
            def.ScaleY = 1.2f;
            def.Width *= 1.2f;
            def.Height *= 1.2f;
            def.X = -9600;
            def.Y = 600;
            def.AI = @"AI\DuplicatePlayer.py";
            _player2 = _world.CreateCharacter(def);

            hpBar = new HPBar("bloodframe", "blood");
            hpBar.Width = 186;
            hpBar.Height = 20;
            hpBar.X = -93;
            hpBar.Y = 100;
            hpBar.Target = _player2;

            Root.Add(_player2.Sprite);
            EventManager.Register(_player2.AI);
        }
        private void LoadBoss()
        {
            //Boss
            _boss = CreateCharacter(@"Data\Hua.xml", Group.PlayerThree, 10000, 300, 99, 30, 300, 600, 2.0f, 2.0f, 2.0f,
                1.0f, 1.0f);

            _boss.Actions["Dying"].ActionEnd += s =>
            {
                _board.SwitchTex(_boardTexs[_countBoard]);
                _board.Show();
            };

            _boss.AI.LoadAIScript(@"AI\Boss.py");
            Root.Add(_boss.Sprite);
            EventManager.Register(_boss.AI);
        }
Example #6
0
        public Character CreateCharacter(CharacterDef charDef)
        {
            var bodydef = new BodyDef();
            bodydef.type = charDef.BodyType;
            bodydef.angle = charDef.RotateZ;
            bodydef.fixedRotation = charDef.FixedRotation;
            bodydef.position.X = B2Value(charDef.X);
            bodydef.position.Y = B2Value(charDef.Y);
            Body body = _world.CreateBody(bodydef);
            var shape = new PolygonShape();
            shape.SetAsBox(B2Value(charDef.Width*0.5f), B2Value(charDef.Height*0.5f));
            var fixtureDef = new FixtureDef();
            fixtureDef.shape = shape;
            fixtureDef.density = charDef.Density;
            fixtureDef.friction = charDef.Fraction;
            fixtureDef.restitution = charDef.Restitution;
            body.CreateFixture(fixtureDef);

            var tex = XNADevicesManager.Instance.ContentManager.Load<Texture2D>(charDef.TexName);
            var sprite = new Sprite(tex);
            sprite.Alpha = charDef.Alpha;
            sprite.ScaleX = charDef.ScaleX;
            sprite.ScaleY = charDef.ScaleY;
            sprite.RotateX = charDef.RotateX;
            sprite.RotateY = charDef.RotateY;
            sprite.RotateZ = charDef.RotateZ;
            sprite.R = charDef.R;
            sprite.G = charDef.G;
            sprite.B = charDef.B;
            sprite.X = charDef.X;
            sprite.Y = charDef.Y;
            sprite.Z = charDef.Z;
            sprite.DrawRectangle = charDef.DrawRectangle;
            sprite.TransformOrigin = charDef.TransformOrigin;
            sprite.ZWriteEnable = charDef.ZWriteEnable;
            var character = new Character(sprite, body, this, charDef);
            character.Group = charDef.Group;
            character.Damage = charDef.Damage;
            character.HP = charDef.HP;
            character.MaxHP = charDef.MaxHP;
            body.SetUserData(character);

            return character;
        }
Example #7
0
 public void UnRegister(Character character)
 {
     UnRegister(character.AI);
 }
Example #8
0
 public void Register(Character character)
 {
     Register(character.AI);
 }