Пример #1
0
        /// <summary>
        /// Looks for any tiles that are "ground tiles"
        /// ! = new tile.
        /// !00!
        /// 1!!1
        /// 1111
        /// 0000
        /// </summary>
        /// <param name="inMat">multi array to analyse</param>
        /// <param name="ratio">0-1 how much chance of returning a solid block</param>
        /// <returns>multi array that has decorations only</returns>
        public int[,] createDecorationsMap(int[,] inMat, float ratio)
        {
            Console.WriteLine("Create Decorations map");

            int numRows = inMat.GetLength(0);
            int numCols = inMat.GetLength(1);

            int[,] outMat = this.genInitMatrix(_numTilesRows, _numTilesCols);

            for (int _y = 1; _y < numRows - 2; _y++)
            {
                for (int _x = 1; _x < numCols - 1; _x++)
                {
                    // test for flat surface with empty above
                    if (inMat[_y, _x] == 0 && inMat[_y + 1, _x] == 1 && inMat[_y + 1, _x - 1] == 1 && inMat[_y + 1, _x + 1] == 1)
                    {
                        if (FlxU.random() < ratio)
                        {
                            outMat[_y, _x] = 1;
                        }
                        else
                        {
                            outMat[_y, _x] = 0;
                        }
                    }
                    else
                    {
                        outMat[_y, _x] = 0;
                    }
                }
            }
            return(outMat);
        }
Пример #2
0
        /// <summary>
        /// Finds a random empty spot
        /// </summary>
        /// <param name="inMat">Matrix to search</param>
        /// <returns>int[] array {rx, ry} of a empty spot</returns>
        public int[] findRandomEmpty(int[,] inMat)
        {
            //Console.WriteLine("Find Random Empty");

            int numRows = inMat.GetLength(0);
            int numCols = inMat.GetLength(1);

            int n  = 0;
            int rx = 0;
            int ry = 0;

            while (n != 1)
            {
                rx = (int)(FlxU.random() * (numRows - 1));
                ry = (int)(FlxU.random() * (numCols - 1));

                if (inMat[rx, ry] == 0)
                {
                    n = 1;
                    //Console.WriteLine("X:" + rx + "Y:" + ry);
                }
            }

            return(new int[] { rx, ry });
        }
Пример #3
0
 /// <summary>
 /// An internal function used by the binary auto-tilers.
 /// </summary>
 /// <param name="Index">The index of the tile you want to analyze.</param>
 protected void randomTile(int Index)
 {
     if (_data[Index] == 0)
     {
         return;
     }
     _data[Index] = (int)(FlxU.random() * randomLimit);
 }
Пример #4
0
        public override void updateFlickering()
        {
            base.updateFlickering();

            if (flickering())
            {
                if (flickerStyle == FLICKER_TYPE_SCALE)
                {
                    scale = FlxU.random(0.9f, 1.1f);
                }
            }
        }
Пример #5
0
        /// <summary>
        /// An internal function used by the binary auto-tilers.
        /// </summary>
        /// <param name="Index">The index of the tile you want to analyze.</param>
        protected void autoTile(int Index)
        {
            if (_data[Index] == 0)
            {
                return;
            }
            _data[Index] = 0;
            if ((Index - widthInTiles < 0) || (_data[Index - widthInTiles] > 0))                //UP
            {
                _data[Index] += 1;
            }
            if ((Index % widthInTiles >= widthInTiles - 1) || (_data[Index + 1] > 0))           //RIGHT
            {
                _data[Index] += 2;
            }
            if ((Index + widthInTiles >= totalTiles) || (_data[Index + widthInTiles] > 0)) //DOWN
            {
                _data[Index] += 4;
            }
            if ((Index % widthInTiles <= 0) || (_data[Index - 1] > 0))                                  //LEFT
            {
                _data[Index] += 8;
            }
            if ((auto == ALT) && (_data[Index] == 15))  //The alternate algo checks for interior corners
            {
                if ((Index % widthInTiles > 0) && (Index + widthInTiles < totalTiles) && (_data[Index + widthInTiles - 1] <= 0))
                {
                    _data[Index] = 1;           //BOTTOM LEFT OPEN
                }
                if ((Index % widthInTiles > 0) && (Index - widthInTiles >= 0) && (_data[Index - widthInTiles - 1] <= 0))
                {
                    _data[Index] = 2;           //TOP LEFT OPEN
                }
                if ((Index % widthInTiles < widthInTiles - 1) && (Index - widthInTiles >= 0) && (_data[Index - widthInTiles + 1] <= 0))
                {
                    _data[Index] = 4;           //TOP RIGHT OPEN
                }
                if ((Index % widthInTiles < widthInTiles - 1) && (Index + widthInTiles < totalTiles) && (_data[Index + widthInTiles + 1] <= 0))
                {
                    _data[Index] = 8;           //BOTTOM RIGHT OPEN
                }
            }
            _data[Index] += 1;

            if (useExtraMiddleTiles)
            {
                if (_extraMiddleTiles >= 1 && _data[Index] == 16)
                {
                    _data[Index] += (int)(FlxU.random() * (_extraMiddleTiles + 1));
                }
            }
        }
Пример #6
0
        /**
         * Returns a member at random from the group.
         *
         * @return	A <code>FlxObject</code> from the members list.
         */
        public FlxObject getRandom()
        {
            int       c = 0;
            FlxObject o = null;
            int       l = members.Count;
            int       i = (int)(FlxU.random() * l);

            while ((o == null) && (c < members.Count))
            {
                o = members[(++i) % l] as FlxObject;
                c++;
            }
            return(o);
        }
Пример #7
0
        /// <summary>
        /// The Update Cycle. Called once every cycle.
        /// </summary>
        override public void update()
        {
            if (angle != 0)
            {
                if (alpha > 0)
                {
                    if (FlxU.random() > 0.5f)
                    {
                        alpha -= 0.1f;
                    }
                }
            }

            y = t.Position;
            t.Update(FlxG.elapsedAsGameTime);
            base.update();
        }
Пример #8
0
 /**
  * Updates and/or animates this special effect.
  */
 public void update()
 {
     if (_timer > 0)
     {
         _timer -= FlxG.elapsed;
         if (_timer <= 0)
         {
             _timer = 0;
             x      = 0;
             y      = 0;
         }
         else
         {
             x = (int)(FlxU.random() * _intensity * FlxG.width * 2 - _intensity * FlxG.width) * _zoom;
             y = (int)(FlxU.random() * _intensity * FlxG.height * 2 - _intensity * FlxG.height) * _zoom;
         }
     }
 }
Пример #9
0
        /// <summary>
        /// Generates a completely random set of 1s and 0s.
        /// </summary>
        /// <returns>Returns a matrix of a cave!</returns>
        public int[,] generateCaveLevel()
        {
            // Initialize random array

            int[,] mat = new int[_numTilesRows, _numTilesCols];

            mat = this.genInitMatrix(_numTilesRows, _numTilesCols);

            int floor = _numTilesRows - 2;

            for (int _y = 0; _y < _numTilesRows; _y++)
            {
                for (int _x = 0; _x < _numTilesCols; _x++)
                {
                    //Throw in a random assortment of ones and zeroes.
                    if (FlxU.random() < initWallRatio)
                    {
                        mat[_y, _x] = 1;
                    }
                    else
                    {
                        mat[_y, _x] = 0;
                    }
                }
            }

            // Secondary buffer
            int[,] mat2 = genInitMatrix(_numTilesRows, _numTilesCols);

            // Run automata

            for (int i = 0; i <= numSmoothingIterations; i++)
            {
                runCelluarAutomata(mat, mat2);

                int[,] temp = new int[mat.GetLength(0), mat.GetLength(1)];
                mat         = mat2;
                mat2        = temp;
            }

            return(mat);
        }
Пример #10
0
        virtual public FlxSprite emitParticleAndReturnSprite()
        {
            _counter++;
            FlxSprite s = members[_particle] as FlxSprite;

            s.visible    = true;
            s.exists     = true;
            s.active     = true;
            s.x          = x - ((int)s.width >> 1) + FlxU.random() * width;
            s.y          = y - ((int)s.height >> 1) + FlxU.random() * height;
            s.velocity.X = minParticleSpeed.X;
            if (minParticleSpeed.X != maxParticleSpeed.X)
            {
                s.velocity.X += FlxU.random() * (maxParticleSpeed.X - minParticleSpeed.X);
            }
            s.velocity.Y = minParticleSpeed.Y;
            if (minParticleSpeed.Y != maxParticleSpeed.Y)
            {
                s.velocity.Y += FlxU.random() * (maxParticleSpeed.Y - minParticleSpeed.Y);
            }
            s.acceleration.Y  = gravity;
            s.angularVelocity = minRotation;
            if (minRotation != maxRotation)
            {
                s.angularVelocity += FlxU.random() * (maxRotation - minRotation);
            }
            if (s.angularVelocity != 0)
            {
                s.angle = FlxU.random() * 360 - 180;
            }
            s.drag.X = particleDrag.X;
            s.drag.Y = particleDrag.Y;
            _particle++;
            if (_particle >= members.Count)
            {
                _particle = 0;
            }
            s.onEmit();
            justEmitted = true;
            return(s);
        }
Пример #11
0
        /// <summary>
        /// Finds a random solid piece in a Matrix
        /// </summary>
        /// <param name="inMat">Matrix to search</param>
        /// <returns>int[] array {rx, ry} of a solid</returns>
        public int[] findRandomSolid(int[,] inMat)
        {
            //Console.WriteLine("Find Random Solid");

            int numRows = inMat.GetLength(0);
            int numCols = inMat.GetLength(1);

            int n  = 0;
            int rx = (int)(FlxU.random() * (numRows - 1));
            int ry = (int)(FlxU.random() * (numCols - 1));

            if (inMat[rx, ry] == 1)
            {
                return(new int[] { rx, ry });
            }
            else
            {
                while (n != 1)
                {
                    rx++;
                    ry++;
                    if (rx > numRows - 1)
                    {
                        rx = (int)(FlxU.random() * (numRows - 1));
                    }
                    if (ry > numRows - 1)
                    {
                        ry = (int)(FlxU.random() * (numCols - 1));
                    }

                    if (inMat[rx, ry] == 1)
                    {
                        n = 1;
                    }
                }
            }

            return(new int[] { rx, ry });
        }
Пример #12
0
        /// <summary>
        /// Add Decorations such as top, right, etc decorations.
        /// </summary>
        /// <param name="mat">In Matrix</param>
        /// <param name="Chance">Chance of adding.</param>
        /// <returns>a string[,] matrix cave.</returns>
        public string[,] addDecorations(string[,] mat, float Chance)
        {
            for (int x = 0; x < mat.GetLength(1); x++)
            {
                for (int y = 0; y < mat.GetLength(0); y++)
                {
                    if (FlxU.random() <= Chance)
                    {
                        string value = mat[y, x];

                        if (value == "8" && coordIsInMatrix(mat, x - 1, y))
                        {
                            mat[y, x - 1] = ((int)FlxU.random(TOP_DECORATION_MIN, TOP_DECORATION_MAX)).ToString();
                        }
                        if (value == "14" && coordIsInMatrix(mat, x + 1, y))
                        {
                            mat[y, x + 1] = UNDER_DECORATION;
                        }
                        if (value == "13" && coordIsInMatrix(mat, x + 1, y))
                        {
                            mat[y, x + 1] = TOP_RIGHT_DECORATION;
                        }
                        if (value == "10" && coordIsInMatrix(mat, x + 1, y))
                        {
                            mat[y, x + 1] = UNDER_LEFT_DECORATION;
                        }
                        if (value == "7" && coordIsInMatrix(mat, x - 1, y))
                        {
                            mat[y, x - 1] = TOP_LEFT_DECORATION;
                        }
                        if (value == "4" && coordIsInMatrix(mat, x - 1, y))
                        {
                            mat[y, x - 1] = UNDER_RIGHT_DECORATION;
                        }
                    }
                }
            }
            return(mat);
        }
Пример #13
0
        public int[,] generateBridgeLevel(int NumberOfLadders, int MinLength, int MaxLength)
        {
            Console.WriteLine("generateBridgeLevel");
            // Initialize random array

            int[,] mat = new int[_numTilesRows, _numTilesCols];

            mat = this.genInitMatrix(_numTilesRows, _numTilesCols);

            for (int i = 0; i < NumberOfLadders; i++)
            {
                int length = (int)(FlxU.random(MinLength, MaxLength));
                int _x     = (int)(FlxU.random(0, _numTilesRows));
                int _y     = (int)(FlxU.random(0, _numTilesCols - length));

                for (int j = 0; j < length; j++)
                {
                    mat[_y + j, _x] = 1;
                }
            }
            return(mat);
        }
Пример #14
0
        /// <summary>
        /// Just updates the render-style flickering.
        /// </summary>
        public virtual void updatecolorFlickering()
        {
            if (colorFlickering())
            {
                if (_colorFlickerTimer > 0)
                {
                    _colorFlickerTimer -= FlxG.elapsed;
                    if (_colorFlickerTimer == 0)
                    {
                        _colorFlickerTimer = -1;
                    }
                }
                if (_colorFlickerTimer < 0)
                {
                    colorFlicker(-1);
                }
                else
                {
                    _colorFlicker = !_colorFlicker;

                    if (_colorFlicker)
                    {
                        color = new Color(0.99f, 0.99f, 0.99f);
                    }
                    else if (!_colorFlicker)
                    {
                        color = new Color(
                            FlxU.random(_colorFlickerRMin, _colorFlickerRMax),
                            FlxU.random(_colorFlickerGMin, _colorFlickerGMax),
                            FlxU.random(_colorFlickerBMin, _colorFlickerBMax));
                    }
                }
            }
            else
            {
                color = _lastColor;
            }
        }
Пример #15
0
        public int[,] addChunks(int[,] inMat, int number, int minSize, int maxSize, int fillWith)
        {
            for (int i = 0; i < number; i++)
            {
                int ysize = (int)FlxU.random(minSize, maxSize);
                int xsize = (int)FlxU.random(minSize, maxSize);

                int offsetx = (int)FlxU.random(0, _numTilesCols - xsize);
                int offsety = (int)FlxU.random(0, _numTilesRows - ysize);

                for (int _y = offsety; _y < ysize + offsety; _y++)
                {
                    for (int _x = offsetx; _x < xsize + offsetx; _x++)
                    {
                        if (offsetx < _numTilesCols && offsety < _numTilesRows)
                        {
                            inMat[_y, _x] = fillWith;
                        }
                    }
                }
            }

            int[,] mat2 = genInitMatrix(_numTilesRows, _numTilesCols);

            // Run automata
            for (int i = 0; i <= numSmoothingIterations; i++)
            {
                runCelluarAutomata(inMat, mat2);

                int[,] temp = new int[inMat.GetLength(0), inMat.GetLength(1)];
                inMat       = mat2;
                mat2        = temp;
            }

            return(inMat);
        }
Пример #16
0
        // X-flixel only.
        private void regenRects()
        {
            int widthInTiles  = ((int)width / _tileWidth);
            int heightInTiles = ((int)height / _tileHeight);

            width  = widthInTiles * _tileWidth;
            height = heightInTiles * _tileHeight;

            int tileCount   = widthInTiles * heightInTiles;
            int numGraphics = _tex.Width / _tileWidth;

            _rects = new Rectangle[tileCount];
            for (int i = 0; i < tileCount; i++)
            {
                if ((FlxU.random() * (numGraphics + _empties)) > _empties)
                {
                    _rects[i] = new Rectangle(_tileWidth * (int)(FlxU.random() * numGraphics), 0, _tileWidth, _tileHeight);
                }
                else
                {
                    _rects[i] = Rectangle.Empty;
                }
            }
        }
Пример #17
0
        /// <summary>
        /// Generates a cave level. <para> use a different method with int arrays for more control.</para>
        /// </summary>
        /// <param name="floor">levels of rows on the floor before smoothing</param>
        /// <param name="ceiling">levels of rows on the ceiling before smoothing</param>
        /// <param name="leftWall">left walls before smoothing</param>
        /// <param name="rightWall">right walls before smoothing</param>
        /// <param name="floorPermanent">floors after smoothing</param>
        /// <param name="ceilingPermanent">ceiling rows after smoothing</param>
        /// <param name="leftWallPermanent">left walls after smoothing</param>
        /// <param name="rightWallPermanent">right walls after smoothing</param>
        /// <returns></returns>
        public int[,] generateCaveLevel(int floor, int ceiling, int leftWall, int rightWall, int floorPermanent, int ceilingPermanent, int leftWallPermanent, int rightWallPermanent)
        {
            // Initialize random array

            int[,] mat = new int[_numTilesRows, _numTilesCols];

            mat = this.genInitMatrix(_numTilesRows, _numTilesCols);

            for (int _y = 0; _y < _numTilesRows; _y++)
            {
                for (int _x = 0; _x < _numTilesCols; _x++)
                {
                    //Throw in a random assortment of ones and zeroes.
                    if (FlxU.random() < initWallRatio)
                    {
                        mat[_y, _x] = 1;
                    }
                    else
                    {
                        mat[_y, _x] = 0;
                    }

                    //If you need a floor or walls or ceiling, throw them in here.
                    //Note: These will be smoothed.

                    // Floor
                    if (_y >= _numTilesRows - floor)
                    {
                        mat[_y, _x] = 1;
                    }

                    // Ceiling
                    if (_y < ceiling)
                    {
                        mat[_y, _x] = 1;
                    }

                    // Left wall

                    if (_x < leftWall)
                    {
                        mat[_y, _x] = 1;
                    }

                    if (_x >= _numTilesCols - rightWall)
                    {
                        mat[_y, _x] = 1;
                    }
                }
            }

            // Secondary buffer
            int[,] mat2 = genInitMatrix(_numTilesRows, _numTilesCols);

            // Run automata

            for (int i = 0; i <= numSmoothingIterations; i++)
            {
                runCelluarAutomata(mat, mat2);

                int[,] temp = new int[mat.GetLength(0), mat.GetLength(1)];
                mat         = mat2;
                mat2        = temp;
            }

            // This step puts some walls in after the smooth. Important only to run if needed

            if (floorPermanent != 0 || ceilingPermanent != 0 || leftWallPermanent != 0 || rightWallPermanent != 0)
            {
                for (int _y = 0; _y < _numTilesRows; _y++)
                {
                    for (int _x = 0; _x < _numTilesCols; _x++)
                    {
                        // Floor
                        if (_y >= _numTilesRows - floorPermanent)
                        {
                            mat[_y, _x] = 1;
                        }

                        // Ceiling
                        if (_y < ceilingPermanent)
                        {
                            mat[_y, _x] = 1;
                        }

                        // Left wall

                        if (_x < leftWallPermanent)
                        {
                            mat[_y, _x] = 1;
                        }

                        if (_x >= _numTilesCols - rightWallPermanent)
                        {
                            mat[_y, _x] = 1;
                        }
                    }
                }
            }

            return(mat);
        }
Пример #18
0
        public FlxEmitter createSprites(Texture2D Graphics, int Quantity, bool Multiple, float Collide, float Bounce)
        {
            members = new List <FlxObject>();
            int       r;
            FlxSprite s;
            int       tf = 1;
            float     sw;
            float     sh;

            if (Multiple)
            {
                s = new FlxSprite();
                s.loadGraphic(Graphics, true);
                tf = s.frames;
            }
            int i = 0;

            while (i < Quantity)
            {
                if ((Collide > 0) && (Bounce > 0))
                {
                    s = new FlxParticle(Bounce) as FlxSprite;
                }
                else
                {
                    s = new FlxSprite();
                }
                if (Multiple)
                {
                    r = (int)(FlxU.random() * tf);
                    //if(BakedRotations > 0)
                    //    s.loadRotatedGraphic(Graphics,BakedRotations,r);
                    //else
                    //{
                    s.loadGraphic(Graphics, true);
                    s.frame = r;
                    //}
                }
                else
                {
                    //if(BakedRotations > 0)
                    //    s.loadRotatedGraphic(Graphics,BakedRotations);
                    //else
                    s.loadGraphic(Graphics);
                }
                if (Collide > 0)
                {
                    sw         = s.width;
                    sh         = s.height;
                    s.width    = (int)(s.width * Collide);
                    s.height   = (int)(s.height * Collide);
                    s.offset.X = (int)(sw - s.width) / 2;
                    s.offset.Y = (int)(sh - s.height) / 2;
                    s.solid    = true;
                }
                else
                {
                    s.solid = false;
                }
                s.exists       = false;
                s.scrollFactor = scrollFactor;
                add(s);
                i++;
            }
            return(this);
        }
Пример #19
0
        /// <summary>
        /// X-flixel only.
        /// </summary>
        private void regenRects()
        {
            int widthInTiles  = ((int)width / _tileWidth);
            int heightInTiles = ((int)height / _tileHeight);

            width  = widthInTiles * _tileWidth;
            height = heightInTiles * _tileHeight;

            int tileCount   = widthInTiles * heightInTiles;
            int numGraphics = _tex.Width / _tileWidth;

            _rects = new Rectangle[tileCount];
            for (int i = 0; i < tileCount; i++)
            {
                if ((FlxU.random() * (numGraphics + _empties)) > _empties)
                {
                    if (auto == RANDOM)
                    {
                        //_rects[i] = new Rectangle(_tileWidth * (int)(FlxU.random() * numGraphics), 0, _tileWidth, _tileHeight);
                        _rects[i] = new Rectangle(_tileWidth * (int)(FlxU.random() * numGraphics), 0, _tileWidth, _tileHeight);


                        /*
                         * switch (i)
                         * {
                         *  case 0:
                         *      _rects[i] = new Rectangle(0, 0, _tileWidth, _tileHeight);
                         *      break;
                         *  default:
                         *      _rects[i] = new Rectangle(20, 0, _tileWidth, _tileHeight);
                         *      break;
                         *
                         * }
                         */
                    }
                    else if (auto == OFF)
                    {
                        _rects[i] = new Rectangle(0, 0, _tileWidth, _tileHeight);
                    }
                    else if (auto == AUTO)
                    {
                        int m = widthInTiles;
                        int n = heightInTiles;
                        int x = i / widthInTiles;
                        int y = i % heightInTiles;

                        int gi = 14;
                        if (x == 0 && y == 0)
                        { //top left
                            gi = 0;
                        }
                        else if (x == 0 && y == m - 1)
                        { //top right
                            gi = 1;
                        }
                        else if (x == n - 1 && y == 0)
                        { //bottom left
                            gi = 2;
                        }
                        else if (x == n - 1 && y == m - 1)
                        { //bottom right
                            gi = 3;
                        }
                        else if (x == 0 && y != 0 && y != m - 1)
                        { //straight top
                            gi = 4;
                        }
                        else if (x == n - 1 && y != 0 && y != m - 1)
                        { //straight bottom
                            gi = 5;
                        }
                        else if (i == 0 && x != 0 && x != n - 1)
                        { //left down straight
                            gi = 6;
                        }
                        else if (i == m - 1 && x != 0 && x != n - 1)
                        { //right down straight
                            gi = 7;
                        }

                        if (m == 1 && x == 0)
                        { //top single down.
                            gi = 12;
                        }
                        else if (m == 1 && x == n - 1)
                        { //bottom single down.
                            gi = 13;
                        }
                        else if (m == 1)
                        { // single straight down
                            gi = 11;
                        }
                        else if (n == 1 && y == 0)
                        { //single flat first
                            gi = 9;
                        }
                        else if (n == 1 && y == m - 1)
                        { //single flat horizontal last.
                            gi = 10;
                        }
                        else if (n == 1)
                        { // single flat horizontal middle
                            gi = 8;
                        }

                        _rects[i] = new Rectangle(_tileWidth * gi, 0, _tileWidth, _tileHeight);
                    }
                    else if (auto == FRAMENUMBER)
                    {
                        _rects[i] = new Rectangle(_tileWidth * frameNumber, 0, _tileWidth, _tileHeight);
                    }
                    else if (auto == HUDELEMENT)
                    {
                        int m = widthInTiles;
                        int n = heightInTiles;
                        int x = i / widthInTiles;
                        int y = i % widthInTiles;

                        int posx = 0;
                        int posy = 0;

                        if (x == 0 && y == 0)
                        { //top left
                            posx = 0;
                            posy = 0;
                        }
                        else if (x == 0 && y == m - 1)
                        { //top right
                            posx = 2;
                            posy = 0;
                        }
                        else if (x == 0 && y != 0 && y != m - 1)
                        { //straight top
                            posx = 1;
                            posy = 0;
                        }
                        else if (x == n - 1 && y == 0)
                        { //bottom left
                            posx = 0;
                            posy = 2;
                        }
                        else if (x == n - 1 && y == m - 1)
                        { //bottom right
                            posx = 2;
                            posy = 2;
                        }
                        else if (x == n - 1 && y != 0 && y != m - 1)
                        { //straight bottom
                            posx = 1;
                            posy = 2;
                        }
                        else if (y == 0 && x != 0 && x != n - 1)
                        { //left down straight
                            posx = 0;
                            posy = 1;
                        }
                        else if (y == m - 1 && x != 0 && x != n - 1)
                        { //right down straight
                            posx = 2;
                            posy = 1;
                        }
                        else
                        {
                            posx = 1;
                            posy = 1;
                        }

                        _rects[i] = new Rectangle(_tileWidth * posx, _tileHeight * posy, _tileWidth, _tileHeight);
                    }

                    //to do: create auto tile tileblocks.

                    //_rects[i] = new Rectangle(0, 0, _tileWidth, _tileHeight);
                }

                else
                {
                    _rects[i] = Rectangle.Empty;
                }
            }
        }
Пример #20
0
        public static Color randomColor()
        {
            Color c = new Color(FlxU.random(), FlxU.random(), FlxU.random());

            return(c);
        }
Пример #21
0
        /// <summary>
        /// Draws the tilemap.
        /// </summary>
        /// <param name="spriteBatch"> SpriteBatch </param>
        public override void render(SpriteBatch spriteBatch)
        {
            //NOTE: While this will only draw the tiles that are actually on screen, it will ALWAYS draw one screen's worth of tiles
            Vector2 _p = getScreenXY();
            int     bX = (int)Math.Floor(-_p.X / _tileWidth);
            int     bY = (int)Math.Floor(-_p.Y / _tileHeight);
            int     eX = (int)Math.Floor((-_p.X + FlxG.width - 1) / _tileWidth);
            int     eY = (int)Math.Floor((-_p.Y + FlxG.height - 1) / _tileHeight);

            if (bX < 0)
            {
                bX = 0;
            }
            if (bY < 0)
            {
                bY = 0;
            }
            if (eX >= widthInTiles)
            {
                eX = widthInTiles - 1;
            }
            if (eY >= heightInTiles)
            {
                eY = heightInTiles - 1;
            }

            int ri = bY * widthInTiles + bX;
            int cri;

            for (int iy = bY; iy <= eY; iy++)
            {
                cri = ri;
                for (int ix = bX; ix <= eX; ix++)
                {
                    if (_rects[cri] != Rectangle.Empty)
                    {
                        // Render the color too;

                        if (rainbow)
                        {
                            color = new Color(FlxU.random(0.15, 1), FlxU.random(0.15, 1), FlxU.random(0.15, 1));
                        }

                        // Add addition of adding:
                        //  + (int)this.x
                        //  + (int)this.y
                        // to the position

                        spriteBatch.Draw(_tileBitmap,
                                         new Rectangle((ix * _tileWidth) + (int)Math.Floor(FlxG.scroll.X * scrollFactor.X),  //+ (int)this.x
                                                       (iy * _tileHeight) + (int)Math.Floor(FlxG.scroll.Y * scrollFactor.Y), // + (int)this.y
                                                       _tileWidth,
                                                       _tileHeight),
                                         _rects[iy * widthInTiles + ix],
                                         color);

                        if (FlxG.showBounds && boundingBoxOverride == true)
                        {
                            spriteBatch.Draw(FlxG.XnaSheet,
                                             new Rectangle((ix * _tileWidth) + (int)Math.Floor(FlxG.scroll.X * scrollFactor.X),
                                                           (iy * _tileHeight) + (int)Math.Floor(FlxG.scroll.Y * scrollFactor.Y), _tileWidth, _tileHeight),
                                             _rects[iy * widthInTiles + ix],
                                             getBoundingColor());
                        }
                    }
                    cri++;
                }
                ri += widthInTiles;
            }
        }
Пример #22
0
        /// <summary>
        /// Generates a cave level
        /// </summary>
        /// <param name="solidRowsBeforeSmooth">int[] array = fill in these rows as solid before the smooth.</param>
        /// <param name="solidColumnsBeforeSmooth">int[] array = fill in these rows as solid before the smooth.</param>
        /// <param name="solidRowsAfterSmooth">int[] array = fill in these rows as solid before the smooth.</param>
        /// <param name="solidColumnsAfterSmooth">int[] array = fill in these rows as solid before the smooth.</param>
        /// <param name="emptyRowsBeforeSmooth">int[] array = fill in these rows as empty before the smooth.</param>
        /// <param name="emptyColumnsBeforeSmooth">int[] array = fill in these rows as empty before the smooth.</param>
        /// <param name="emptyRowsAfterSmooth">int[] array = fill in these rows as empty before the smooth.</param>
        /// <param name="emptyColumnsAfterSmooth">int[] array = fill in these rows as empty before the smooth.</param>
        /// <returns></returns>
        public int[,] generateCaveLevel(int[] solidRowsBeforeSmooth,
                                        int[] solidColumnsBeforeSmooth,
                                        int[] solidRowsAfterSmooth,
                                        int[] solidColumnsAfterSmooth,
                                        int[] emptyRowsBeforeSmooth,
                                        int[] emptyColumnsBeforeSmooth,
                                        int[] emptyRowsAfterSmooth,
                                        int[] emptyColumnsAfterSmooth)
        {
            //Console.WriteLine("x/y {0}, {1}", _numTilesCols, _numTilesRows);

            // Initialize random array

            int[,] mat = new int[_numTilesRows, _numTilesCols];

            mat = this.genInitMatrix(_numTilesRows, _numTilesCols);

            for (int _y = 0; _y < _numTilesRows; _y++)
            {
                for (int _x = 0; _x < _numTilesCols; _x++)
                {
                    //Throw in a random assortment of ones and zeroes.
                    if (FlxU.random() < initWallRatio)
                    {
                        mat[_y, _x] = 1;
                    }
                    else
                    {
                        mat[_y, _x] = 0;
                    }
                }
            }
            if (emptyRowsBeforeSmooth != null)
            {
                foreach (int _yEmpty in emptyRowsBeforeSmooth)
                {
                    for (int _i = 0; _i < _numTilesCols; ++_i)
                    {
                        if (_yEmpty < _numTilesRows)
                        {
                            mat[_yEmpty, _i] = 0;
                        }
                    }
                }
            }
            if (emptyColumnsBeforeSmooth != null)
            {
                foreach (int _xEmpty in emptyColumnsBeforeSmooth)
                {
                    for (int _i = 0; _i < _numTilesRows; ++_i)
                    {
                        if (_xEmpty < _numTilesCols)
                        {
                            mat[_i, _xEmpty] = 0;
                        }
                    }
                }
            }

            if (solidRowsBeforeSmooth != null)
            {
                foreach (int _ySolid in solidRowsBeforeSmooth)
                {
                    for (int _i = 0; _i < _numTilesCols; ++_i)
                    {
                        if (_ySolid < _numTilesRows)
                        {
                            mat[_ySolid, _i] = 1;
                        }
                    }
                }
            }
            if (solidColumnsBeforeSmooth != null)
            {
                foreach (int _xSolid in solidColumnsBeforeSmooth)
                {
                    for (int _i = 0; _i < _numTilesRows; ++_i)
                    {
                        if (_xSolid < _numTilesCols)
                        {
                            mat[_i, _xSolid] = 1;
                        }
                    }
                }
            }

            // Secondary buffer
            int[,] mat2 = genInitMatrix(_numTilesRows, _numTilesCols);

            // Run automata
            for (int i = 0; i <= numSmoothingIterations; i++)
            {
                runCelluarAutomata(mat, mat2);

                int[,] temp = new int[mat.GetLength(0), mat.GetLength(1)];
                mat         = mat2;
                mat2        = temp;
            }

            if (emptyRowsAfterSmooth != null)
            {
                foreach (int _yEmpty in emptyRowsAfterSmooth)
                {
                    for (int _i = 0; _i < _numTilesCols; ++_i)
                    {
                        if (_yEmpty < _numTilesRows)
                        {
                            mat[_yEmpty, _i] = 0;
                        }
                    }
                }
            }
            if (emptyColumnsAfterSmooth != null)
            {
                foreach (int _xEmpty in emptyColumnsAfterSmooth)
                {
                    for (int _i = 0; _i < _numTilesRows; ++_i)
                    {
                        if (_xEmpty < _numTilesCols)
                        {
                            mat[_i, _xEmpty] = 0;
                        }
                    }
                }
            }
            if (solidRowsAfterSmooth != null)
            {
                foreach (int _ySolid in solidRowsAfterSmooth)
                {
                    for (int _i = 0; _i < _numTilesCols; ++_i)
                    {
                        if (_ySolid < _numTilesRows)
                        {
                            mat[_ySolid, _i] = 1;
                        }
                    }
                }
            }
            if (solidColumnsAfterSmooth != null)
            {
                foreach (int _xSolid in solidColumnsAfterSmooth)
                {
                    for (int _i = 0; _i < _numTilesRows; ++_i)
                    {
                        if (_xSolid < _numTilesCols)
                        {
                            mat[_i, _xSolid] = 1;
                        }
                    }
                }
            }

            return(mat);
        }
Пример #23
0
 /// <summary>
 /// Tell the sprite to change to a random frame of animation
 /// Useful for instantiating particles or other weird things.
 /// </summary>
 public void randomFrame()
 {
     _curAnim = null;
     _caf     = (int)(FlxU.random() * (_tex.Width / frameWidth));
     calcFrame();
 }
Пример #24
0
        /// <summary>
        /// Returns an auto tiled cave.
        /// </summary>
        /// <returns>Returns a matrix of a cave!</returns>
        public string[,] generateCaveLevel(bool WithDecorations)
        {
            // Initialize random array

            string[,] mat = new string[_numTilesRows, _numTilesCols];

            mat = this.genInitMatrix(_numTilesRows, _numTilesCols);

            int floor = _numTilesRows - 2;

            if (generateMethod == RANDOM)
            {
                for (int _y = 0; _y < _numTilesRows; _y++)
                {
                    for (int _x = 0; _x < _numTilesCols; _x++)
                    {
                        //Throw in a random assortment of ones and zeroes.
                        if (FlxU.random() < initWallRatio)
                        {
                            mat[_y, _x] = "1";
                        }
                        else
                        {
                            mat[_y, _x] = "0";
                        }
                    }
                }
            }
            else if (generateMethod == GROW_FROM)
            {
                for (int _y = 0; _y < _numTilesRows; _y++)
                {
                    for (int _x = 0; _x < _numTilesCols; _x++)
                    {
                        //Throw in a random assortment of ones and zeroes.
                        if (FlxU.random() < initWallRatio)
                        {
                            mat[_y, _x] = "1";
                        }
                        else
                        {
                            mat[_y, _x] = "0";
                        }
                    }
                }
            }

            // Secondary buffer
            string[,] mat2 = genInitMatrix(_numTilesRows, _numTilesCols);

            // Run automata

            for (int i = 0; i <= numSmoothingIterations; i++)
            {
                runCelluarAutomata(mat, mat2);

                string[,] temp = new string[mat.GetLength(0), mat.GetLength(1)];
                mat            = mat2;
                mat2           = temp;
            }

            //auto tile

            _data = convertMultiArrayStringToIntArray(mat);

            //int total = 0;
            int ii         = 0;
            int totalTiles = _data.Length;

            while (ii < totalTiles)
            {
                autoTile(ii++);
            }

            //reconvert int[] to string[,]

            mat = convertIntArrayToMultiArray(_data);

            //add decorations.
            if (WithDecorations)
            {
                mat = addDecorations(mat);
            }

            return(mat);
        }