Exemplo n.º 1
0
        public Map3D(SorcererStreetMap Map, MapLayer Grid, Map2D GroundLayer, GraphicsDevice g)
        {
            this.Map         = Map;
            this.Grid        = Grid;
            this.GroundLayer = GroundLayer;
            sprCursor        = Map.sprCursor;
            Camera           = new SorcererStreetCamera(g);
            Radius           = (Map.MapSize.X * Map.TileSize.X) / 2;

            PolygonEffect = new BasicEffect(g);

            PolygonEffect.VertexColorEnabled = true;
            PolygonEffect.TextureEnabled     = true;

            float aspectRatio = g.Viewport.Width / (float)g.Viewport.Height;

            Matrix Projection = Matrix.CreatePerspectiveFieldOfView(MathHelper.PiOver4,
                                                                    aspectRatio,
                                                                    1, 10000);

            PolygonEffect.Projection = Projection;

            PolygonEffect.World = Matrix.Identity;
            PolygonEffect.View  = Matrix.Identity;

            DicDrawablePointPerColor = new Dictionary <Color, List <Tile3D> >();
            DicTile3D = new Dictionary <Texture2D, List <Tile3D> >();

            CreateMap(Map);

            int CursorWidth  = sprCursor == null ? 32 : sprCursor.Width;
            int CursorHeight = sprCursor == null ? 32 : sprCursor.Height;

            Cursor = CreateCursor(Map, Map.CursorPositionVisible.X, Map.CursorPositionVisible.Y, Grid.ArrayTerrain[(int)Map.CursorPositionVisible.X, (int)Map.CursorPositionVisible.Y].Position.Z,
                                  CursorWidth, CursorHeight, Radius);
        }
Exemplo n.º 2
0
        public override int GetNextLayerIndex(Vector3 CurrentPosition, int NextX, int NextY, float MaxClearance, float ClimbValue, out List <int> ListLayerPossibility)
        {
            ListLayerPossibility = new List <int>();

            Terrain CurrentTerrain     = ListLayer[(int)CurrentPosition.Z].ArrayTerrain[(int)CurrentPosition.X, (int)CurrentPosition.Y];
            string  CurrentTerrainType = GetTerrainType(CurrentPosition.X, CurrentPosition.Y, (int)CurrentPosition.Z);
            float   CurrentZ           = CurrentTerrain.Position.Z + CurrentPosition.Z;

            int   ClosestLayerIndexDown      = -1;
            int   ClosestLayerIndexUp        = 0;
            float ClosestTerrainDistanceDown = float.MaxValue;
            float ClosestTerrainDistanceUp   = float.MinValue;

            for (int L = 0; L < ListLayer.Count; L++)
            {
                MapLayer ActiveLayer = ListLayer[L];
                Terrain  NextTerrain = ActiveLayer.ArrayTerrain[NextX, NextY];

                string NextTerrainType = GetTerrainType(NextX, NextY, L);
                float  NextTerrainZ    = NextTerrain.Position.Z + L;

                //Check lower or higher neighbors if on solid ground
                if (CurrentTerrainType != UnitStats.TerrainAir && CurrentTerrainType != UnitStats.TerrainVoid)
                {
                    if (NextTerrainType != UnitStats.TerrainAir && NextTerrainType != UnitStats.TerrainVoid)
                    {
                        //Prioritize going downward
                        if (NextTerrainZ <= CurrentZ)
                        {
                            float ZDiff = CurrentZ - NextTerrainZ;
                            if (ZDiff <= ClosestTerrainDistanceDown && HasEnoughClearance(NextTerrainZ, NextX, NextY, L, MaxClearance))
                            {
                                ClosestTerrainDistanceDown = ZDiff;
                                ClosestLayerIndexDown      = L;
                                ListLayerPossibility.Add(L);
                            }
                        }
                        else
                        {
                            float ZDiff = NextTerrainZ - CurrentZ;
                            if (ZDiff >= ClosestTerrainDistanceUp && ZDiff <= ClimbValue)
                            {
                                ClosestTerrainDistanceUp = ZDiff;
                                ClosestLayerIndexUp      = L;
                                ListLayerPossibility.Add(L);
                            }
                        }
                    }
                }
                //Already in void, check for any neighbors
                else
                {
                    if (NextTerrainZ == CurrentPosition.Z && NextTerrainType == CurrentTerrainType)
                    {
                        return(L);
                    }
                    //Prioritize going upward
                    else if (NextTerrainZ > CurrentPosition.Z)
                    {
                        float ZDiff = NextTerrainZ - CurrentZ;
                        if (ZDiff < ClosestTerrainDistanceUp && ZDiff <= ClimbValue)
                        {
                            ClosestTerrainDistanceUp = ZDiff;
                            ClosestLayerIndexUp      = L;
                            ListLayerPossibility.Add(L);
                        }
                    }
                }
            }

            if (ClosestLayerIndexDown >= 0)
            {
                return(ClosestLayerIndexDown);
            }
            else
            {
                return(ClosestLayerIndexUp);
            }
        }