Пример #1
0
        private void DrawWorldMap()
        {
            Vector2 cameraPostition = worldCharacter.CameraPosition;
            Point   positionOffset  = worldCharacter.PositionOffset + new Point(EngineSettings.TileSize, EngineSettings.TileSize);

            int worldmapLength = _worldMapSpriteSet[0].Length;

            for (int yOffset = ((int)cameraPostition.Y * WorldInformation.mapWidth) - 1, TileY = -positionOffset.Y; yOffset < (int)(cameraPostition.Y + _halfWidthPlus) * WorldInformation.mapWidth; yOffset += WorldInformation.mapWidth, TileY += EngineSettings.TileSize)
            {
                for (int x = (int)cameraPostition.X + yOffset, TileX = -positionOffset.X; x < (int)cameraPostition.X + _halfHeightPlus + yOffset + 1; x++, TileX += EngineSettings.TileSize)
                {
                    int ColorIndex = x;

                    while (ColorIndex < yOffset)
                    {
                        ColorIndex += WorldInformation.mapWidth;
                    }
                    while (ColorIndex > yOffset + WorldInformation.mapWidth)
                    {
                        ColorIndex -= WorldInformation.mapWidth;
                    }

                    while (ColorIndex < 0)
                    {
                        ColorIndex += worldmapLength;
                    }
                    while (ColorIndex >= worldmapLength)
                    {
                        ColorIndex -= worldmapLength;
                    }

                    Color TileColor = _worldmapAnimator.Get()[ColorIndex];

                    if (TilePalette.TileColor.ContainsKey(TileColor))
                    {
                        Point t   = GetCoordinate(ColorIndex);
                        int   col = TilePalette.TileColor[TileColor];

                        if (GSS.DebugMapX0Y0)
                        {
                            GSS.SpriteBatch.Draw(mapTileCollection.GetTile(col),
                                                 new Rectangle(TileX, TileY, EngineSettings.TileSize, EngineSettings.TileSize),
                                                 t.X == 0 || t.Y == 0 ? new Color(0, 0, 0) : _sunColor);
                        }
                        else
                        {
                            GSS.SpriteBatch.Draw(mapTileCollection.GetTile(col),
                                                 new Rectangle(TileX, TileY, EngineSettings.TileSize, EngineSettings.TileSize), _sunColor);
                        }
                    }
                    else
                    {
                        GSS.SpriteBatch.Draw(mapTileCollection.GetTile(),
                                             new Rectangle(TileX, TileY, EngineSettings.TileSize, EngineSettings.TileSize),
                                             new Color(0, 0, 0));
                    }
                }
            }
        }
Пример #2
0
        private void WorldMapClouds(GameTime gameTime)
        {
            _cloudsInPlay.ForEach(a => a.Update());
            _cloudsInPlay.RemoveAll(a => !a.IsAlive);

            if (_cloudsInPlay.Count < 500)
            {
                MapCloud newCloud = new MapCloud(cloudsTileCollection.GetTile().Width, cloudsTileCollection.GetTile().Height);
                _cloudsInPlay.Add(newCloud);
            }
        }
Пример #3
0
        /// <summary>
        /// Initialize the tile engine
        /// </summary>
        /// <param name="tiles">List of tiles to use</param>
        /// <param name="worldMap">Bitmap index of world-map</param>
        /// <param name="ScreenTexturecolors">Index of colors from the worldMap bitmap</param>
        /// <param name="Outofbound">Fallback texture to use on tiles not render-able</param>
        public void LoadWorld()
        {
            _autoElements        = GSS.TextureLoader.WorldAutoElements();
            worldCharacter       = GSS.TextureLoader.WorldCharacter();
            cloudsTileCollection = GSS.TextureLoader.Clouds();
            Minimap = GSS.TextureLoader.Minimap();
            _worldMapAnimationSet  = GSS.TextureLoader.WorldMaps();
            _minimapSpriteAnimator = new AnimationRotator <Rectangle>(_minimapLightAnimationSize, AnimationFunction.FORWARD_BACKWARD, playTimeSeconds: 2f);

            WorldInformation.mapWidth  = (int)_worldMapAnimationSet.Size.X;
            WorldInformation.mapHeight = (int)_worldMapAnimationSet.Size.Y;
            _minimapW = (int)(DisplayOutputSettings.ScreenWidth * 0.2);
            _minimapH = (int)(DisplayOutputSettings.ScreenHeight * 0.2);

            mapTileCollection = GSS.TextureLoader.WorldMapTiles();

            int mapCount = _worldMapAnimationSet.Length;

            _worldMapSpriteSet = new Color[mapCount][];
            for (int a = 0; a < mapCount; a++)
            {
                _worldMapSpriteSet[a] = new Color[(int)(_worldMapAnimationSet.Size.X * _worldMapAnimationSet.Size.Y)];
                _worldMapAnimationSet.GetTile(a).GetData(_worldMapSpriteSet[a]);
            }
            _worldmapAnimator = new AnimationRotator <Color[]>(_worldMapSpriteSet, AnimationFunction.FORWARD_BACKWARD, playTimeSeconds: 3f);

            WorldInformation.worldMapCheck = _worldMapSpriteSet[0];

            _tileUsedBy = new object[WorldInformation.mapHeight * WorldInformation.mapWidth];
            //+1 is added to buffed draw the next coulomb to the right of the frame
            //1600 is screen width
            _halfHeightPlus = (int)(DisplayOutputSettings.ScreenWidth / (float)EngineSettings.TileSize) + 1;
            //900 is screen height
            //+2 is added to buffed draw the next two rows bellow the frame (one row was not enough)
            _halfWidthPlus = (int)(DisplayOutputSettings.ScreenHeight / (float)EngineSettings.TileSize) + 2;

            minimapXoff = DisplayOutputSettings.ScreenWidth - _minimapW - 10;
            RunInitWork();
            sw.Start();
        }