示例#1
0
        public Block(Block b)
        {
            game = b.game;
            type = b.type;

            initFileString();
        }
示例#2
0
        // replace the blocks with clusters
        public void replaceBlocksWithClusters(List<int> groupPos, List<int>typeIndexes)
        {
            // replace existing blocks with the clusters
            for (int i = 0; i < groupPos.Count; i++)
            {
                Vector2 pos = blocks[groupPos[i]].Position; // the position of the block in the world

                int groupWidth = generateRandomNumber(3, 19);
                int groupHeight = generateRandomNumber(3, 19);

                if (groupWidth % 2 == 0)
                {
                    groupWidth += 1;
                }

                if (groupHeight % 2 == 0)
                {
                    groupHeight += 1;
                }

                // water will have a different cluster pattern so dont add it here
                if (((Block.bType)typeIndexes[i]) != Block.bType.WATER)
                {
                    // draws a block at the picked position
                    blocks[groupPos[i]] = new Block(game, blocktypes[typeIndexes[i]].Type, pos);

                    for (int k = 0; k < groupHeight; k++)
                    {
                        blocks[groupPos[i]] = new Block(game, blocktypes[typeIndexes[i]].Type, pos);

                        // draws a block below of the picked position
                        if (groupPos[i] + k * (width / 15) < blocks.Count) // i + width = the row above the current block
                        {
                            pos = blocks[groupPos[i] + k * (width / 15)].Position;
                            blocks[groupPos[i] + k * (width / 15)] = new Block(game, blocktypes[typeIndexes[i]].Type, pos);

                            for (int j = 0; j < groupWidth; j++)
                            {
                                // draws a block to the right of the picked position
                                if (groupPos[i] + j + k * (width / 15) < blocks.Count)
                                {
                                    pos = blocks[groupPos[i] + j + k * (width / 15)].Position;
                                    blocks[groupPos[i] + j + k * (width / 15)] = new Block(game, blocktypes[typeIndexes[i]].Type, pos);
                                }

                                // draws a block to the left of the picked position
                                if (groupPos[i] - j + k * (width / 15) >= 0)
                                {
                                    pos = blocks[groupPos[i] - j + k * (width / 15)].Position;
                                    blocks[groupPos[i] - j + k * (width / 15)] = new Block(game, blocktypes[typeIndexes[i]].Type, pos);
                                }
                            }
                            groupWidth -= 2;
                        }

                        // draws a block above of the picked position
                        if (groupPos[i] - k * (width / 15) >= 0) // i - width = the row above the current block
                        {
                            pos = blocks[groupPos[i] - k * (width / 15)].Position;
                            blocks[groupPos[i] - k * (width / 15)] = new Block(game, blocktypes[typeIndexes[i]].Type, pos);

                            for (int j = 0; j < groupWidth; j++)
                            {
                                // draws a block to the right of the picked position
                                if (groupPos[i] + j - k * (width / 15) < blocks.Count)
                                {
                                    pos = blocks[groupPos[i] + j - k * (width / 15)].Position;
                                    blocks[groupPos[i] + j - k * (width / 15)] = new Block(game, blocktypes[typeIndexes[i]].Type, pos);
                                }

                                // draws a block to the left of the picked position
                                if (groupPos[i] - j - k * (width / 15) >= 0)
                                {
                                    pos = blocks[groupPos[i] - j - k * (width / 15)].Position;
                                    blocks[groupPos[i] - j - k * (width / 15)] = new Block(game, blocktypes[typeIndexes[i]].Type, pos);
                                }
                            }
                            groupWidth -= 2;
                        }
                    }
                }

                else
                {
                    for (int k = 0; k < groupHeight; k++)
                    {
                        blocks[groupPos[i]] = new Block(game, blocktypes[typeIndexes[i]].Type, pos);

                        // draws a block below of the picked position
                        if (groupPos[i] + k * (width / 15) < blocks.Count) // i + width = the row above the current block
                        {
                            pos = blocks[groupPos[i] + k * (width / 15)].Position;
                            blocks[groupPos[i] + k * (width / 15)] = new Block(game, blocktypes[typeIndexes[i]].Type, pos);

                            for (int j = 0; j < groupWidth; j++)
                            {
                                // draws a block to the right of the picked position
                                if (groupPos[i] + j + k * (width / 15) < blocks.Count)
                                {
                                    pos = blocks[groupPos[i] + j + k * (width / 15)].Position;
                                    blocks[groupPos[i] + j + k * (width / 15)] = new Block(game, blocktypes[typeIndexes[i]].Type, pos);
                                }

                                // draws a block to the left of the picked position
                                if (groupPos[i] - j + k * (width / 15) >= 0)
                                {
                                    pos = blocks[groupPos[i] - j + k * (width / 15)].Position;
                                    blocks[groupPos[i] - j + k * (width / 15)] = new Block(game, blocktypes[typeIndexes[i]].Type, pos);
                                }
                            }
                            groupWidth -= 2;
                        }
                    }
                }
            }
        }
示例#3
0
        // reads in biome data file
        public void loadBiome(String fileName)
        {
            int numBlWide = 0;
            int numBlHigh = 0;
            float startX = position.X - (width / 2.0f);
            float startY = (position.Y - (height / 2.0f)) - 15; //subtracted 15 to get it to center itself correctly, value is out for some reason
            char[] delim = new char[2];
            delim[0] = '|';
            delim[1] = ',';
            //delim[2] = '\n';

            StreamReader sr = new StreamReader("../../../../Evolution GameContent/world data/biome data/" + fileName + segment.X + segment.Y + ".bio");
            try
            {
                String[] temp = sr.ReadLine().Split(delim);
                numBlWide = Convert.ToInt32(temp[0]);
                numBlHigh = Convert.ToInt32(temp[1]);

                for (String temp1; (temp1 = sr.ReadLine()) != null; )
                {
                    String[] items = temp1.Split(delim);
                    startX = position.X - (width / 2.0f);

                    for (int x = 0; x < items.Length; x++)
                    {
                        Block newBlock = new Block(game, items[x], new Vector2(startX, startY));
                        newBlock.setCoords(startX, startY); // dont know why, but without this blocks dont draw correctly, doing x * 15 on the new vector above has no effect also
                        blocks.Add(newBlock);

                        //Console.WriteLine(startX + "\t" + startY); // debug code
                        startX += 15;
                    }
                    startY += 15;
                }
            }
            catch (FormatException e)
            {
                Console.WriteLine("Invalid biome File Format");
            }

            sr.Close();

            Console.WriteLine("Biome file " + name.ToString().ToLower() + "_" + type.ToString().ToLower() + segment.X + segment.Y + ".bio read successfully");
        }
示例#4
0
        // generates a biome filled with the specified blocks
        public void generateBiome()
        {
            setBlockTypes();

            float endX = position.X + (width / 2.0f);
            float endY = position.Y + (height / 2.0f);
            int i = 0;

            for (float startX = position.X - (width / 2.0f); startX < endX; startX += 15)
            {
                for (float startY = position.Y - (height / 2.0f); startY < endY; startY += 15)
                {
                    Block block = new Block(blocktypes.ElementAt(0));
                    blocks.Add(block);
                    blocks.ElementAt(i).setCoords(startX, startY);
                    i++;
                }
            }

            generateBlockClusters();
            biomeFileWriter();
        }