コード例 #1
0
        //Interaction Zombie->Object Collisionnable
        public void Update(BossZombieF Zombie, Vector2 JoueurPosition)
        {
            if (Zombie.Flip == SpriteEffects.None)
            {
                RecZombie = new Rectangle(Zombie.recZombie.X - 80, Zombie.recZombie.Y - 80, 80, 80);
            }
            else
            {
                RecZombie = new Rectangle(Zombie.recZombie.X, Zombie.recZombie.Y - 80, 80, 80);
            }

            if (RecZombie.isOnBottomOf(RecObj))
            {
                if (Zombie.position.X < JoueurPosition.X)
                {
                    Zombie.position = new Vector2(Zombie.position.X + 2, Zombie.position.Y + 2);
                }
                else
                {
                    Zombie.position = new Vector2(Zombie.position.X - 2, Zombie.position.Y + 2);
                }
            }
            else if (RecZombie.isOnTopOf(RecObj))
            {
                if (Zombie.position.X < JoueurPosition.X)
                {
                    Zombie.position = new Vector2(Zombie.position.X + 2, Zombie.position.Y - 2);
                }
                else
                {
                    Zombie.position = new Vector2(Zombie.position.X - 2, Zombie.position.Y - 2);
                }
            }
            else if (RecZombie.isOnRightOf(RecObj))
            {
                if (Zombie.position.Y < JoueurPosition.Y + RecObj.Height)
                {
                    Zombie.position = new Vector2(Zombie.position.X + 2, Zombie.position.Y + 4);
                }
                else
                {
                    Zombie.position = new Vector2(Zombie.position.X + 2, Zombie.position.Y - 4);
                }
            }

            else if (RecZombie.isOnLeftOf(RecObj))
            {
                if (Zombie.position.Y < JoueurPosition.Y + RecObj.Height)
                {
                    Zombie.position = new Vector2(Zombie.position.X - 2, Zombie.position.Y + 4);
                }
                else
                {
                    Zombie.position = new Vector2(Zombie.position.X - 2, Zombie.position.Y - 4);
                }
            }
        }
コード例 #2
0
        //Interaction Zombie->Object Collisionnable
        public void Update(ZombieCR Zombie, Vector2 JoueurPosition)
        {
            if (Zombie.Flip == SpriteEffects.None)
            {
                RecZombie = new Rectangle(Zombie.recZombie.X - 80, Zombie.recZombie.Y - 80, 80, 80);
            }
            else
            {
                RecZombie = new Rectangle(Zombie.recZombie.X, Zombie.recZombie.Y - 80, 80, 80);
            }

            if (RecZombie.isOnBottomOf(RecObj))
            {
                if (Zombie.position.X < JoueurPosition.X)
                {
                    Zombie.position = new Vector2(Zombie.position.X + 2, Zombie.position.Y + 2);
                }
                else
                {
                    Zombie.position = new Vector2(Zombie.position.X - 2, Zombie.position.Y + 2);
                }
            }
            else if (RecZombie.isOnTopOf(RecObj))
            {
                if (Zombie.position.X < JoueurPosition.X)
                {
                    Zombie.position = new Vector2(Zombie.position.X + 2, Zombie.position.Y - 2);
                }
                else
                {
                    Zombie.position = new Vector2(Zombie.position.X - 2, Zombie.position.Y - 2);
                }
            }
            else if (RecZombie.isOnRightOf(RecObj))
            {
                if (Zombie.position.Y < JoueurPosition.Y + RecObj.Height)
                {
                    Zombie.position = new Vector2(Zombie.position.X + 2, Zombie.position.Y + 4);
                }
                else
                {
                    Zombie.position = new Vector2(Zombie.position.X + 2, Zombie.position.Y - 4);
                }
            }

            else if (RecZombie.isOnLeftOf(RecObj))
            {
                if (Zombie.position.Y < JoueurPosition.Y + RecObj.Height)
                {
                    Zombie.position = new Vector2(Zombie.position.X - 2, Zombie.position.Y + 4);
                }
                else
                {
                    Zombie.position = new Vector2(Zombie.position.X - 2, Zombie.position.Y - 4);
                }
            }

            //if (RecZombie.Intersects(RecObj))
            //{
            //    if (Zombie.position.X > RecObj.X) Zombie.position = new Vector2(Zombie.position.X + 2, Zombie.position.Y);
            //    else Zombie.position = new Vector2(Zombie.position.X - 2, Zombie.position.Y);

            //    if (Zombie.position.Y > RecObj.Y) Zombie.position = new Vector2(Zombie.position.X, Zombie.position.Y + 2);
            //    else Zombie.position = new Vector2(Zombie.position.X, Zombie.position.Y - 2);
            //}
        }