コード例 #1
0
ファイル: Tilemap.cs プロジェクト: KleinerMensch/CR4VE
        public static void updateActiveTilemaps(Tilemap[] currentMaps)
        {
            float switchRange = 150f;

            float deltaXRight;
            float deltaXLeft;

            //get distance to switch point
            if (GameControls.isGhost)
            {
                deltaXRight = Singleplayer.ghost.Position.X - currentMaps[Singleplayer.activeIndex2].StartPosition.X;
                deltaXLeft = Singleplayer.ghost.Position.X - currentMaps[Singleplayer.activeIndex1].StartPosition.X;
            }
            else
            {
                deltaXRight = Singleplayer.player.Position.X - currentMaps[Singleplayer.activeIndex2].StartPosition.X;
                deltaXLeft = Singleplayer.player.Position.X - currentMaps[Singleplayer.activeIndex1].StartPosition.X;
            }

            //change indices if necessary
            if (deltaXRight > switchRange)
            {
                Singleplayer.activeIndex1 = (int)MathHelper.Clamp(Singleplayer.activeIndex1 + 1, 0, currentMaps.Length - 2);
                Singleplayer.activeIndex2 = (int)MathHelper.Clamp(Singleplayer.activeIndex2 + 1, 1, currentMaps.Length - 1);
            }

            if (deltaXLeft < switchRange)
            {
                Singleplayer.activeIndex1 = (int)MathHelper.Clamp(Singleplayer.activeIndex1 - 1, 0, currentMaps.Length - 2);
                Singleplayer.activeIndex2 = (int)MathHelper.Clamp(Singleplayer.activeIndex2 - 1, 1, currentMaps.Length - 1);
            }
        }
コード例 #2
0
ファイル: Tilemap.cs プロジェクト: KleinerMensch/CR4VE
        public static List<Tile> getVisibleTiles(Tilemap[] currentMaps)
        {
            int i1 = Singleplayer.activeIndex1;
            int i2 = Singleplayer.activeIndex2;

            List<Tile> result = new List<Tile>();

            foreach (Tile t in currentMaps[i1].TileList)
            {
                //slightly larger Frustum than Camera2D.BoundingFrustum to prevent clipping errors
                Matrix clippView = Matrix.CreateLookAt(Camera2D.FrustumPosition + new Vector3(0, 0, 50), Camera2D.FrustumTarget, Vector3.Up);

                BoundingFrustum clippingFrus = new BoundingFrustum(clippView * Camera2D.ProjectionMatrix);

                if (clippingFrus.Intersects(t.Boundary))
                {
                    result.Add(t);
                }
            }
            foreach (Tile t in currentMaps[i2].TileList)
            {
                //slightly larger Frustum than Camera2D.BoundingFrustum to prevent clipping errors
                Matrix clippView = Matrix.CreateLookAt(Camera2D.FrustumPosition + new Vector3(0, 0, 50), Camera2D.FrustumTarget, Vector3.Up);

                BoundingFrustum clippingFrus = new BoundingFrustum(clippView * Camera2D.ProjectionMatrix);

                if (clippingFrus.Intersects(t.Boundary))
                {
                    result.Add(t);
                }
            }

            return result;
        }