Esempio n. 1
0
        private void CheckTrashCollision(Orbit1 orbit1Instance, FlatRedBall.Math.PositionedObjectList<Trash> trashList, int p)
        {
            var trashLockoutFromSpace = new List<Trash>();

            foreach (var trash in trashList.Where(t => !t.Attached))
            {
                //Check if trash hit other trash
                foreach (var otherTrash in trashList)
                {
                    //Ignore trashes on the planet
                    if (otherTrash == trash || otherTrash.OnConveyor)
                    {
                        continue;
                    }

                    if (trash.CollisionCircle.CollideAgainstBounce(otherTrash.CollisionCircle, 10F, 0.1F, 0))
                    {
                        //trash.AttachTo(null, false);
                        //otherTrash.AttachTo(null, false);
                        trash.Detach();
                        otherTrash.Detach();

                        //trash fly to space
                        return;
                    }
                }

                //Only allow attach once
                if (!trash.Attached && trash.CollisionCircle.CollideAgainstBounce(Orbit1Instance.Circle, 0, 100, 2))
                {
                    trash.AttachTo(Orbit1Instance, true);
                    trash.Attached = true;
                }

                int halfScreenWidth = FlatRedBallServices.ClientWidth/2;
                int halfScreenHeight = FlatRedBallServices.ClientHeight/2;
                if (!trash.OnConveyor && (trash.X > halfScreenWidth ||
                    trash.X < -halfScreenWidth ||
                    trash.Y > halfScreenHeight ||
                    trash.Y < -halfScreenHeight))
                {
                    trashLockoutFromSpace.Add(trash);
                }
            }

            //Remove the trash from game
            foreach (var trash in trashLockoutFromSpace)
            {
                trashList.Remove(trash);
                trash.RemoveSelfFromListsBelongingTo();
                trash.Destroy();
            }
        }
        public override void Initialize(bool addToManagers)
        {
            // Generated Initialize
            LoadStaticContent(ContentManagerName);
            BackgroundFile = FlatRedBallServices.Load<Scene>("content/screens/gamescreen/backgroundfile.scnx", ContentManagerName);
            MoonInstance = new Ourobits.Entities.Moon(ContentManagerName, false);
            MoonInstance.Name = "MoonInstance";
            TrashList = new PositionedObjectList<Trash>();
            CannonBarrelInstance = new Ourobits.Entities.CannonBarrel(ContentManagerName, false);
            CannonBarrelInstance.Name = "CannonBarrelInstance";
            CannonBaseInstance = new Ourobits.Entities.CannonBase(ContentManagerName, false);
            CannonBaseInstance.Name = "CannonBaseInstance";
            TrashList2 = new PositionedObjectList<Trash2>();
            UserArrowInstance = new Ourobits.Entities.UserArrow(ContentManagerName, false);
            UserArrowInstance.Name = "UserArrowInstance";
            ConveyorInstance = new Ourobits.Entities.Conveyor(ContentManagerName, false);
            ConveyorInstance.Name = "ConveyorInstance";
            Orbit1Instance = new Ourobits.Entities.Orbit1(ContentManagerName, false);
            Orbit1Instance.Name = "Orbit1Instance";

            PostInitialize();
            base.Initialize(addToManagers);
            if (addToManagers)
            {
                AddToManagers();
            }
        }