Example #1
0
        private void PlayerHandler()
        {
            if (entityPlayer.SpritePos.X <= 0 || entityPlayer.SpritePos.X >= viewPort.Width)
            {
                entityPlayer.SpritePos = new Vector2(350, 550);
            }



            //Player intersect any objects
            for (int i = 0; i < ObjectsRight.Count - 1; i++)
            {
                //Remove objects outside the window
                if (entityPlayer.Rectangle().Intersects(ObjectsRight.ElementAt(i).Rectangle()))
                {
                    entityPlayer.SpritePos -= new Vector2(50, 0);
                }
            }

            //Player intersect any objects
            for (int i = 0; i < ObjectsLeft.Count - 1; i++)
            {
                //Remove objects outside the window
                if (entityPlayer.Rectangle().Intersects(ObjectsLeft.ElementAt(i).Rectangle()))
                {
                    entityPlayer.SpritePos += new Vector2(50, 0);
                }
            }
        }
Example #2
0
        private void DeleteObject()
        {
            //Right Side
            for (int i = 0; i < ObjectsRight.Count - 1; i++)
            {
                for (int j = i + 1; j < ObjectsRight.Count; j++)
                {
                    //Remove objects that intersect with each other
                    if (ObjectsRight.ElementAt(i).Rectangle().Intersects(ObjectsRight.ElementAt(j).Rectangle()))
                    {
                        ObjectsRight.RemoveAt(i);
                    }
                }
            }


            //Left Side
            for (int i = 0; i < ObjectsLeft.Count - 1; i++)
            {
                for (int j = i + 1; j < ObjectsLeft.Count; j++)
                {
                    //Remove objects that intersect with each other
                    if (ObjectsLeft.ElementAt(i).Rectangle().Intersects(ObjectsLeft.ElementAt(j).Rectangle()))
                    {
                        ObjectsLeft.RemoveAt(i);
                    }
                }
            }



            //Right Side
            for (int i = 0; i < ObjectsRight.Count - 1; i++)
            {
                //Remove objects outside the window
                if (ObjectsRight.ElementAt(i).SpritePos.Y >= (viewPort.Height + ObjectsRight.ElementAt(i).SpriteImg.Height + 20))
                {
                    ObjectsRight.RemoveAt(i);
                }
            }


            //Left Side
            for (int i = 0; i < ObjectsLeft.Count - 1; i++)
            {
                //Remove objects outside the window
                if (ObjectsLeft.ElementAt(i).SpritePos.Y >= (viewPort.Height + ObjectsRight.ElementAt(i).SpriteImg.Height + 20))
                {
                    ObjectsLeft.RemoveAt(i);
                }
            }
        }
Example #3
0
        private void ObjectHandler()
        {
            DeleteObject();


            if (ObjectsLeft.Count <= 5)
            {
                //Add new object
                ObjectsLeft.Add(CreateObject(ObjectsLeft.Last(), true));
            }

            if (ObjectsRight.Count <= 5)
            {
                //Add new object
                ObjectsRight.Add(CreateObject(ObjectsRight.Last(), false));
            }
        }