Пример #1
0
        public void TestPlayerSwing()
        {
            GameObject Player = new GameObject();
            GameObject PlayerSword = new GameObject(false, false);
            PlayerSword.AddBehaviour("WeaponBehaviour", new WeaponBehaviour()
            {
                Wielder = Player
            });
            bool Clicked = true;
            Player.AddBehaviour("InputMovementBehaviour",new InputMovementBehaviour(5f, new FollowCamera()));
            Player.AddBehaviour("MovementBehaviour", new MovementBehaviour());
            Player.AddBehaviour("AttackBehaviour", new AttackBehaviour(PlayerSword));
            Player.AddBehaviour("StatBehaviour", new StatBehaviour(100, 100, 0.1f));
            var inputBehaviour = Player.GetBehaviourOfType("InputMovementBehaviour");
            var weaponBehaviour = PlayerSword.GetBehaviourOfType("WeaponBehaviour");
            var attackBehaviour = Player.GetBehaviourOfType("AttackBehaviour");

            if (Clicked)
            {
                (inputBehaviour as InputMovementBehaviour).SwingSword();
            }
            Assert.IsTrue((attackBehaviour as AttackBehaviour).Attack);

            Player.OnUpdate(new GameTime());

            Assert.AreEqual(TimeSpan.FromMilliseconds(700), (attackBehaviour as AttackBehaviour).Cooldown);
            Assert.IsTrue((weaponBehaviour as WeaponBehaviour).SwingSword);
        }
Пример #2
0
        public void TestMonsterAttack()
        {
            GameObject Player = new GameObject();
            GameObject Monster = new GameObject();
            GameObject MonsterSword = new GameObject(false, false);
            GameTime gameTime = new GameTime();
            MonsterSword.AddBehaviour("WeaponBehaviour",new WeaponBehaviour()
            {
                Wielder = Monster
            });
            Monster.AddBehaviour("MonsterAttack", new MonsterAttack(Player));
            Monster.AddBehaviour("AttackBehaviour" ,new AttackBehaviour(MonsterSword));
            Monster.AddBehaviour("StatBehaviour",new StatBehaviour(100, 100, 0.1f));
            Monster.Position = new Vector2(100, 100);
            Monster.Rotation = MathHelper.ToRadians(180);
            Player.Position = new Vector2(100, 130);

            Monster.OnUpdate(gameTime);

            var attackBehaviour = Monster.GetBehaviourOfType("AttackBehaviour");
            var monsterAttackBehaviour = Monster.GetBehaviourOfType("MonsterAttack");
            var weaponBehaviour = MonsterSword.GetBehaviourOfType("WeaponBehaviour");

            Assert.IsTrue((monsterAttackBehaviour as MonsterAttack).CheckRange());
            Assert.AreEqual(TimeSpan.FromMilliseconds(1050), (attackBehaviour as AttackBehaviour).Cooldown);
            Assert.IsTrue((weaponBehaviour as WeaponBehaviour).SwingSword);

            Player.Position = new Vector2(300, 300);

            Monster.OnUpdate(gameTime);
            MonsterSword.OnUpdate(gameTime);

            Assert.IsFalse((monsterAttackBehaviour as MonsterAttack).CheckRange());
            Assert.IsFalse((weaponBehaviour as WeaponBehaviour).SwingSword);
        }
Пример #3
0
        public void initialize()
        {
            player = new GameObject();
            player.AddBehaviour("StatBehaviour",new StatBehaviour(100, 100, 1));

            Stats = player.GetBehaviourOfType("StatBehaviour") as StatBehaviour;
        }
Пример #4
0
 public AttackBehaviour(GameObject sword)
 {
     Sword = sword;
     timeUntilUsage = TimeSpan.FromMilliseconds(0);
     if (Sword.HasBehaviourOfType("WeaponBehaviour"))
         BehaviourSword = Sword.GetBehaviourOfType("WeaponBehaviour");
 }
Пример #5
0
        public HUDBehaviour(Texture2D textureHealth, Texture2D textureTestos, SpriteFont text, GameObject gameObject)
        {
            TextureHealth = textureHealth;
            TextureTestos = textureTestos;
            Text = text;

            GameObject = gameObject;
            Stats = gameObject.GetBehaviourOfType("StatBehaviour") as StatBehaviour;

            PositionHealth = new Vector2(5, 5);
            PositionTestos = new Vector2(5, 30);
        }
Пример #6
0
 public DropItem(GameObject player)
 {
     GameObject = player;
     behaviourStat = GameObject.GetBehaviourOfType("StatBehaviour") as StatBehaviour;
 }