コード例 #1
0
        public void TestCollisionZoneCollision()
        {
            CollisionZone <Bullet> TestCollisionZone = new CollisionZone <Bullet>(2000, 100, -500, -500);

            Vector2[] LocalPoints1 = CreateCube(Vector2.Zero, 40);
            Vector2[] LocalPoints2 = CreateCube(Vector2.Zero, 40);

            TestCollisionZone.AddToZone(new Bullet(null, LocalPoints1, 5, 5));
            TestCollisionZone.AddToZone(new Bullet(null, LocalPoints2, 5, 5));
            Assert.AreEqual(true, DetectCollisionBetweenSelfAndOthers(TestCollisionZone, TestCollisionZone.ListObjectInZoneAndOverlappingParents.First.Value));
        }
コード例 #2
0
        public void TestCollisionZoneAdd()
        {
            CollisionZone <Bullet> TestCollisionZone = new CollisionZone <Bullet>(2000, 100, -500, -500);

            Vector2[] LocalPoints1 = CreateCube(Vector2.Zero, 40);
            Vector2[] LocalPoints2 = CreateCube(Vector2.Zero, 5);

            TestCollisionZone.AddToZone(new Bullet(null, LocalPoints1, 5, 5));
            TestCollisionZone.AddToZone(new Bullet(null, LocalPoints2, 5, 5));
            Assert.AreEqual(2, TestCollisionZone.ListObjectInZoneAndOverlappingParents.Count);
            Assert.AreEqual(2, TestCollisionZone.ArraySubZone[25].ListObjectInZoneAndOverlappingParents.Count);
            Assert.AreEqual(TestCollisionZone.ArraySubZone[25], TestCollisionZone.ListObjectInZoneAndOverlappingParents.First.Value.Collision.ListParent.Find(TestCollisionZone.ArraySubZone[25]).Value);
            Assert.AreEqual(TestCollisionZone.ArraySubZone[25], TestCollisionZone.ListObjectInZoneAndOverlappingParents.First.Next.Value.Collision.ListParent.Find(TestCollisionZone.ArraySubZone[25]).Value);
        }
コード例 #3
0
ファイル: Layer.cs プロジェクト: Wargamer3/Project-Eternity
        public Layer(FightingZone Owner, BinaryReader BR)
            : this(Owner)
        {
            Dictionary <string, Prop> DicPropsByName = Prop.GetAllPropsByName();

            int ListPolygonCount = BR.ReadInt32();
            WorldCollisions = new CollisionZone <WorldPolygon>((int)Math.Max(Owner.CameraBounds.Width * 1.5, Owner.CameraBounds.Height * 1.5),
                                                               50,
                                                               (int)(Math.Min(Owner.CameraBounds.X * 1.5, -Owner.CameraBounds.X * 1.5)),
                                                               (int)(Math.Min(Owner.CameraBounds.Y * 1.5, -Owner.CameraBounds.Y * 1.5)));

            for (int P = 0; P < ListPolygonCount; P++)
            {
                int ArrayVertexCount = BR.ReadInt32();

                Vector2[] ArrayVertex = new Vector2[ArrayVertexCount];
                for (int V = 0; V < ArrayVertexCount; V++)
                {
                    ArrayVertex[V] = new Vector2(BR.ReadSingle(), BR.ReadSingle());
                }

                bool BlockBullets = BR.ReadBoolean();
                bool IsPlatform   = BR.ReadBoolean();

                WorldPolygon NewPolygon;
                if (GameScreen.GraphicsDevice != null)
                {
                    NewPolygon = new WorldPolygon(ArrayVertex, GameScreen.GraphicsDevice.PresentationParameters.BackBufferWidth, GameScreen.GraphicsDevice.PresentationParameters.BackBufferHeight);
                }
                else
                {
                    NewPolygon = new WorldPolygon(ArrayVertex, 1, 1);
                }

                NewPolygon.BlockBullets = BlockBullets;
                NewPolygon.IsPlatform   = IsPlatform;

                NewPolygon.Collision.ListCollisionPolygon[0].ComputerCenter();
                WorldCollisions.AddToZone(NewPolygon);
                ListWorldCollisionPolygon.Add(NewPolygon);
            }

            int       ArrayGroundLevelCollisionCount = BR.ReadInt32();
            Vector2[] ArrayGroundLevelCollision      = new Vector2[ArrayGroundLevelCollisionCount];
            for (int V = 0; V < ArrayGroundLevelCollisionCount; V++)
            {
                ArrayGroundLevelCollision[V] = new Vector2(BR.ReadSingle(), BR.ReadSingle());
            }
            short[] ArrayGroundLevelCollisionIndex = new short[2];
            ArrayGroundLevelCollisionIndex[0] = 0;
            ArrayGroundLevelCollisionIndex[1] = 1;

            if (GameScreen.GraphicsDevice != null)
            {
                GroundLevelCollision = new Polygon(ArrayGroundLevelCollision, ArrayGroundLevelCollisionIndex, GameScreen.GraphicsDevice.PresentationParameters.BackBufferWidth, GameScreen.GraphicsDevice.PresentationParameters.BackBufferHeight);
            }
            else
            {
                GroundLevelCollision = new Polygon(ArrayGroundLevelCollision, ArrayGroundLevelCollisionIndex, 1, 1);
            }

            int ListImagesCount = BR.ReadInt32();
            ListImages = new List <SimpleAnimation>(ListImagesCount);
            for (int P = 0; P < ListImagesCount; P++)
            {
                SimpleAnimation NewBackground = new SimpleAnimation(BR, true);
                NewBackground.Position = new Vector2(BR.ReadSingle(), BR.ReadSingle());
                NewBackground.Depth    = BR.ReadSingle();

                if (!Owner.IsServer)
                {
                    NewBackground.Load(Owner.Content, "");
                    ListImages.Add(NewBackground);
                }
            }

            int ListPropCount = BR.ReadInt32();
            for (int P = 0; P < ListPropCount; ++P)
            {
                string PropName = BR.ReadString();
                Prop   NewProp  = DicPropsByName[PropName].Copy();
                NewProp.Load(BR, Owner.Content, this, Owner);

                //Props are Client side only.
                if (NewProp.CanRunOnServer || !Owner.IsServer)
                {
                    ListProp.Add(NewProp);
                }
            }

            int ListSpawnPointSPCount = BR.ReadInt32();
            for (int S = 0; S < ListSpawnPointSPCount; ++S)
            {
                ListSpawnPointTeam.Add(SpawnPoint.Load(BR));
            }

            int ListSpawnPointMPCount = BR.ReadInt32();
            for (int S = 0; S < ListSpawnPointMPCount; ++S)
            {
                ListSpawnPointTeam.Add(SpawnPoint.Load(BR));
            }
        }