Esempio n. 1
0
        private World(Game game)
            : base(game)
        {
            spriteBatch = new SpriteBatch(game.GraphicsDevice);

            layers = new Layer[5]; // 3 layers and 2 "buffer" layers, that will remain empty, but allow the player to go outside of the 1st and 3rd layers

            for (int i = 0; i < layers.Length; i++)
            {
                layers[i] = new Layer();
                layers[i].InitEntityLists();

                if (i != 0 && i != layers.Length - 1)
                    layers[i].InitTileData();
            }
        }
Esempio n. 2
0
        public static Layer[] Generate()
        {
            rnd = new Random();
            Layer[] layers = new Layer[5]; // 3 layers and 2 "buffer" layers, that will remain empty, but allow the player to go outside of the 1st and 3rd layers

            for (int i = 0; i < layers.Length; i++)
            {
                layers[i] = new Layer();
                layers[i].InitEntityLists();

                if (i == 2)
                    layers[i].InitTileData();
                if (i != 0 && i != layers.Length - 1)
                    layers[i].InitTileData();
            }

            Loop(layers);

            return layers;
        }
Esempio n. 3
0
        private static void GenerateIsland(Layer[] layers, int sizeX, int sizeY)
        {
            int startX = rnd.Next(0, World.Width - sizeX);
            int endX = startX + sizeX;
            // cant be RIGHT on the roof
            int startY = rnd.Next(30, World.Height - sizeY);
            int endY = startY + sizeY;

            // first we get the starting ground spot
            // will be in the upper half of the island
            int YPosition = startY + rnd.Next((endY - startY) / 2);

            for (int x = startX; x < endX; x++)
            {
                YPosition = (int)MathHelper.Clamp(YPosition, 0, World.Height - 1);

                for (int y = YPosition; y < YPosition + Math.Min(x - startX, endX - x); y++)
                {
                    if (y >= World.Height)
                        break;
                    // Edited to test different textures getting loaded from the file.
                    if(rnd.Next(2) == 1)
                        layers[2].SetTile(x, y, Tile.Dirt);
                    else
                        layers[2].SetTile(x, y, Tile.Stone);
                }

                // Edited for testing, feel free to edit again.
                int i = rnd.Next(100);
                // 60% chance to stay still
                // 20% chance to go up 1, 20% chance to go down 1
                // 0% chance to go up 2, 10% chance to go down 2
                // 0% chance to go up 3, 5% chance to go down 3
                if (i < 60)
                {
                    //nothing
                }
                else if (i < 80)
                {
                    YPosition++;
                }
                else if (i < 100)
                {
                    YPosition--;
                }
                else if (i < 0)
                {
                    YPosition += 2;
                }
                else if (i < 0)
                {
                    YPosition -= 2;
                }
                else if (i < 0)
                {
                    YPosition += 3;
                }
                else if (i < 0)
                {
                    YPosition -= 3;
                }
            }
        }
Esempio n. 4
0
        private static void Loop(Layer[] layers)
        {
            // i am purposely making it so the can overlap eachother
            if (islandPoints <= 0)
                return;
            // will generate one island
            int i = rnd.Next(100);

            int sizeXMin = 0, sizeXMax = 0;
            int sizeYMin = 0, sizeYMax = 0;

            // 33% tiny
            if (i < 33)
            {
                islandPoints -= 1;
                sizeXMin = 15;
                sizeXMax = 30;

                sizeYMin = 5;
                sizeYMax = 8;
            }
            // 22% small
            else if (i < 55 && islandPoints >= 3)
            {
                islandPoints -= 3;
                sizeXMin = 30;
                sizeXMax = 60;

                sizeYMin = 8;
                sizeYMax = 14;
            }
            // 10% medium
            else if (i < 65 && islandPoints >= 5)
            {
                islandPoints -= 5;
                sizeXMin = 60;
                sizeXMax = 120;

                sizeYMin = 15;
                sizeYMax = 21;
            }
            //5% large
            else if (i < 70 && islandPoints >= 10)
            {
                islandPoints -= 10;
                sizeXMin = 120;
                sizeXMax = 240;

                sizeYMin = 25;
                sizeYMax = 35;
            }
            //2% giant
            else if (i < 73 && islandPoints >= 20)
            {
                islandPoints -= 20;
                sizeXMin = 240;
                sizeXMax = 480;

                sizeYMin = 40;
                sizeYMax = 80;
            }//other reroll
            else
            {
                Loop(layers);
                return;
            }

            int sizeX = rnd.Next(sizeXMin, sizeXMax);
            int sizeY = rnd.Next(sizeYMin, sizeYMax);

            GenerateIsland(layers, sizeX, sizeY);

            Loop(layers);
        }
Esempio n. 5
0
 public void Draw(int x, int y, Layer layer)
 {
     Rectangle bounds = GetBounds(x, y);
     Rectangle source = GetSource();
     bounds.X -= (int)World.Instance.CameraPosition.X;
     bounds.Y -= (int)World.Instance.CameraPosition.Y;
     World.Instance.SpriteBatch.Draw(getTextureFile(FileName), bounds, source, Color.White);
 }
Esempio n. 6
0
 public void Draw(int x, int y, Layer layer)
 {
     Rectangle bounds = GetBounds(x, y);
     bounds.X -= (int)World.Instance.CameraPosition.X;
     bounds.Y -= (int)World.Instance.CameraPosition.Y;
     World.Instance.SpriteBatch.Draw(Texture, bounds, Color.White);
     if (EdgeTexture != null)
     {
         Vector2 origin = new Vector2(EdgeTexture.Width / 2, EdgeTexture.Height / 2);
         bounds.X += bounds.Width / 2;
         bounds.Y += bounds.Height / 2;
         if (x > 0)
         {
             if (layer.GetTile(x - 1, y) == this)
             {
                 // 90
                 World.Instance.SpriteBatch.Draw(EdgeTexture, bounds, null, Color.White, MathHelper.PiOver2, origin, SpriteEffects.None, 0);
             }
         }
         if (x < World.Width - 1)
         {
             if (layer.GetTile(x + 1, y) == this)
             {
                 // -90
                 World.Instance.SpriteBatch.Draw(EdgeTexture, bounds, null, Color.White, -MathHelper.PiOver2, origin, SpriteEffects.None, 0);
             }
         }
         if (y > 0)
         {
             if (layer.GetTile(x, y - 1) == this)
             {
                 // 0
                 World.Instance.SpriteBatch.Draw(EdgeTexture, bounds, null, Color.White, 0, origin, SpriteEffects.None, 0);
             }
         }
         if (y < World.Height - 1)
         {
             if (layer.GetTile(x, y + 1) == this)
             {
                 // 180
                 World.Instance.SpriteBatch.Draw(EdgeTexture, bounds, null, Color.White, MathHelper.Pi, origin, SpriteEffects.None, 0);
             }
         }
     }
 }