Пример #1
0
        /**
         * Called by <code>FlxGame</code> to set up <code>FlxG</code> during <code>FlxGame</code>'s constructor.
         */
        static internal void setGameData(FlxGame Game, int Width, int Height)
        {
            _game  = Game;
            width  = Width;
            height = Height;

            _mute   = false;
            _volume = 0.5f;

            FlxG.camera = new FlxCamera();

            FlxG.camera.unfollow();

            level = 0;
            score = 0;

            pause        = false;
            timeScale    = 1.0f;
            maxElapsed   = 0.0333f;
            FlxG.elapsed = 0;
            showBounds   = false;
#if !WINDOWS_PHONE
            mobile = false;
#else
            mobile = true;
#endif
            FlxU.setWorldBounds(0, 0, FlxG.width, FlxG.height);
        }
Пример #2
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);
        }
Пример #3
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 });
        }
Пример #4
0
 protected void drawBounds(SpriteBatch spriteBatch, int X, int Y)
 {
     spriteBatch.Draw(FlxG.XnaSheet,
                      new Rectangle((int)(FlxU.floor(x + FlxU.roundingError) + FlxU.floor(FlxG.scroll.X * scrollFactor.X)),
                                    (int)(FlxU.floor(y + FlxU.roundingError) + FlxU.floor(FlxG.scroll.Y * scrollFactor.Y)), (int)width, (int)height),
                      new Rectangle(1, 1, 1, 1), getBoundingColor());
 }
Пример #5
0
        /**
         * Call this function to figure out the on-screen position of the object.
         *
         * @param	P	Takes a <code>Point</code> object and assigns the post-scrolled X and Y values of this object to it.
         *
         * @return	The <code>Point</code> you passed in, or a new <code>Point</code> if you didn't pass one, containing the screen X and Y position of this object.
         */
        virtual public Vector2 getScreenXY()
        {
            Vector2 Point = Vector2.Zero;

            Point.X = FlxU.floor(x + FlxU.roundingError) + FlxU.floor(FlxG.scroll.X * scrollFactor.X);
            Point.Y = FlxU.floor(y + FlxU.roundingError) + FlxU.floor(FlxG.scroll.Y * scrollFactor.Y);
            return(Point);
        }
Пример #6
0
        /// <summary>
        /// Call this function to figure out the on-screen position of the object.
        ///
        /// Takes a <code>Point</code> object and assigns the post-scrolled X and Y values of this object to it.
        /// </summary>
        /// <returns>The <code>Point</code> you passed in, or a new <code>Point</code> if you didn't pass one, containing the screen X and Y position of this object.</returns>
        override public Vector2 getScreenXY()
        {
            Vector2 Point = Vector2.Zero;

            Point.X = FlxU.floor(x + FlxU.roundingError) + FlxU.floor(FlxG.scroll.X * scrollFactor.X) - offset.X;
            Point.Y = FlxU.floor(y + FlxU.roundingError) + FlxU.floor(FlxG.scroll.Y * scrollFactor.Y) - offset.Y;
            return(Point);
        }
Пример #7
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);
 }
Пример #8
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 autoTileWithRemap(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 == REMAPALT) && (_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
                }
            }


            if (remapGuide.ContainsKey(_data[Index]))
            {
                int count = FlxU.randomInt(0, remapGuide[_data[Index]].Length - 1);


                _data[Index] = remapGuide[_data[Index]][count];
            }
            else
            {
                _data[Index] = remapGuide[0][0];
            }
            _data[Index] += 1;
        }
Пример #9
0
 protected void drawPivot(SpriteBatch spriteBatch, int X, int Y, Color col)
 {
     spriteBatch.Draw(FlxG.XnaSheet,
                      new Rectangle((int)(FlxU.floor(X + FlxU.roundingError) + FlxU.floor(FlxG.scroll.X * scrollFactor.X)),
                                    (int)(FlxU.floor(Y + FlxU.roundingError) + FlxU.floor(FlxG.scroll.Y * scrollFactor.Y)),
                                    1,
                                    1),
                      new Rectangle(1, 1, 1, 1),
                      col);
 }
Пример #10
0
        /// <summary>
        /// Checks for overlaps between the provided object and any tiles above the collision index.
        /// </summary>
        /// <param name="Core">The <code>FlxObject</code> you want to check against.</param>
        /// <returns>True if overlap occurs, otherwise False</returns>
        override public bool overlaps(FlxObject Core)
        {
            int d;

            int dd;
            List <BlockPoint> blocks = new List <BlockPoint>();

            //First make a list of all the blocks we'll use for collision
            int ix = (int)FlxU.floor((Core.x - x) / _tileWidth);
            int iy = (int)FlxU.floor((Core.y - y) / _tileHeight);
            int iw = (int)FlxU.ceil((float)Core.width / (float)_tileWidth) + 1;
            int ih = (int)FlxU.ceil((float)Core.height / (float)_tileHeight) + 1;
            int r  = 0;
            int c;

            while (r < ih)
            {
                if (r >= heightInTiles)
                {
                    break;
                }
                d = (iy + r) * widthInTiles + ix;
                c = 0;
                while (c < iw)
                {
                    if (c >= widthInTiles)
                    {
                        break;
                    }
                    dd = _data[d + c];
                    if (dd >= collideMin && dd >= collideMax)
                    {
                        blocks.Add(new BlockPoint((int)(x + (ix + c) * _tileWidth), (int)(y + (iy + r) * _tileHeight), dd));
                    }
                    c++;
                }
                r++;
            }

            //Then check for overlaps
            int bl = blocks.Count;
            int i  = 0;

            while (i < bl)
            {
                _block.x = blocks[i].x;
                _block.y = blocks[i++].y;
                if (_block.overlaps(Core))
                {
                    return(true);
                }
            }
            return(false);
        }
Пример #11
0
 virtual public bool overlapsPoint(float X, float Y, bool PerPixel)
 {
     X      = X + FlxU.floor(FlxG.scroll.X);
     Y      = Y + FlxU.floor(FlxG.scroll.Y);
     _point = getScreenXY();
     if ((X <= _point.X) || (X >= _point.X + width) || (Y <= _point.Y) || (Y >= _point.Y + height))
     {
         return(false);
     }
     return(true);
 }
Пример #12
0
        public override void updateFlickering()
        {
            base.updateFlickering();

            if (flickering())
            {
                if (flickerStyle == FLICKER_TYPE_SCALE)
                {
                    scale = FlxU.random(0.9f, 1.1f);
                }
            }
        }
Пример #13
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));
                }
            }
        }
Пример #14
0
        /// <summary>
        /// <code>FlxU.collide()</code> (and thus <code>FlxObject.collide()</code>) call
        /// this function each time two objects are compared to see if they collide.
        /// It doesn't necessarily mean these objects WILL collide, however.
        /// </summary>
        /// <param name="Object">The <code>FlxObject</code> you're about to run into.</param>
        override public void preCollide(FlxObject Object)
        {
            //Collision fix, in case updateMotion() is called
            colHullX.x = 0;
            colHullX.y = 0;
            colHullY.x = 0;
            colHullY.y = 0;

            int r;
            int c;
            int rs;
            int ix = (int)FlxU.floor((Object.x - x) / _tileWidth);
            int iy = (int)FlxU.floor((Object.y - y) / _tileHeight);
            int iw = ix + (int)FlxU.ceil((float)Object.width / (float)_tileWidth) + 1;
            int ih = iy + (int)FlxU.ceil((float)Object.height / (float)_tileHeight) + 1;

            if (ix < 0)
            {
                ix = 0;
            }
            if (iy < 0)
            {
                iy = 0;
            }
            if (iw > widthInTiles)
            {
                iw = widthInTiles;
            }
            if (ih > heightInTiles)
            {
                ih = heightInTiles;
            }
            rs = iy * widthInTiles;
            r  = iy;
            colOffsets.Clear();
            while (r < ih)
            {
                c = ix;
                while (c < iw)
                {
                    if (_data[rs + c] >= collideMin && _data[rs + c] <= collideMax)
                    {
                        colOffsets.Add(new Vector2(x + c * _tileWidth, y + r * _tileHeight));
                    }
                    c++;
                }
                rs += widthInTiles;
                r++;
            }
        }
Пример #15
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);
        }
Пример #16
0
        public void startPlayingBack(string Filename)
        {
            _history = new List <bool[]>();

            string x = FlxU.loadFromDevice(Filename);

            string[] y = x.Split('\n');

            int line = 0;

            foreach (var item in y)
            {
                string[] item1 = item.Split(',');

                line++;
                if (item1.Length == 14)
                {
                    try
                    {
                        _history.Add(new bool[] { bool.Parse(item1[0]),
                                                  bool.Parse(item1[1]),
                                                  bool.Parse(item1[2]),
                                                  bool.Parse(item1[3]),
                                                  bool.Parse(item1[4]),
                                                  bool.Parse(item1[5]),
                                                  bool.Parse(item1[6]),
                                                  bool.Parse(item1[7]),
                                                  bool.Parse(item1[8]),
                                                  bool.Parse(item1[9]),
                                                  bool.Parse(item1[10]),
                                                  bool.Parse(item1[11]),
                                                  bool.Parse(item1[12]),
                                                  bool.Parse(item1[13]) });
                    }
                    catch (Exception)
                    {
                        Console.WriteLine("History Not Added " + item1.Length + " -- " + item1[1]);
                    }
                }
            }
            //_rec = Recording.Playback;

            control = Controls.file;

            frameCount = 0;
        }
Пример #17
0
        /// <summary>
        /// Get a position of any tile that matches Tiles
        /// </summary>
        /// <param name="Tiles">Provide an array of tiles you want to match.</param>
        /// <returns></returns>
        public Vector2 getRandomTilePositionWithType(int[] Tiles)
        {
            int[] empties = remapGuide[15];
            int   rx      = FlxU.randomInt(0, widthInTiles);
            int   ry      = FlxU.randomInt(0, heightInTiles);
            int   rz      = getTile(rx, ry);

            while (empties.Contains(rz) == false)
            {
                rx = FlxU.randomInt(0, widthInTiles);
                ry = FlxU.randomInt(0, heightInTiles);

                rz = getTile(rx, ry);
            }

            return(new Vector2(rx * _tileWidth, ry * _tileHeight));
        }
Пример #18
0
        /// <summary>
        /// Get a random tile with the type you specify.
        /// </summary>
        /// <param name="Tiles">Array of tiles you want to search for.</param>
        /// <returns></returns>
        public int getRandomTileWithType(int[] Tiles)
        {
            int[] empties = remapGuide[15];
            int   rx      = FlxU.randomInt(0, widthInTiles);
            int   ry      = FlxU.randomInt(0, heightInTiles);
            int   rz      = getTile(rx, ry);

            while (empties.Contains(rz) == false)
            {
                rx = FlxU.randomInt(0, widthInTiles);
                ry = FlxU.randomInt(0, heightInTiles);

                rz = getTile(rx, ry);
            }

            return(rz);
        }
Пример #19
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();
        }
Пример #20
0
 /// <summary>
 /// Specify the boundaries of the level or where the camera is allowed to move.
 /// </summary>
 /// <param name="MinX">The smallest X value of your level (usually 0).</param>
 /// <param name="MinY">The smallest Y value of your level (usually 0).</param>
 /// <param name="MaxX">The largest X value of your level (usually the level width).</param>
 /// <param name="MaxY">The largest Y value of your level (usually the level height).</param>
 /// <param name="UpdateWorldBounds">Whether the quad tree's dimensions should be updated to match.</param>
 static public void followBounds(int MinX, int MinY, int MaxX, int MaxY, bool UpdateWorldBounds)
 {
     followMin = new Point(-MinX, -MinY);
     followMax = new Point(-MaxX + width, -MaxY + height);
     if (followMax.X > followMin.X)
     {
         followMax.X = followMin.X;
     }
     if (followMax.Y > followMin.Y)
     {
         followMax.Y = followMin.Y;
     }
     if (UpdateWorldBounds)
     {
         FlxU.setWorldBounds(MinX, MinY, MaxX - MinX, MaxY - MinY);
     }
     doFollow();
 }
Пример #21
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;
         }
     }
 }
Пример #22
0
        public void saveRecording()
        {
            string _historyString = "";

            foreach (var item in _history)
            {
                _historyString += item[0].ToString() + "," + item[1].ToString() + "," + item[2].ToString() + "," + item[3].ToString() + "," +
                                  item[4].ToString() + "," + item[5].ToString() + "," + item[6].ToString() + "," + item[7].ToString() + "," +
                                  item[8].ToString() + "," + item[9].ToString() + "," + item[10].ToString() + "," + item[11].ToString() + "," +
                                  item[12].ToString() + "," + item[13].ToString() + "\n";
            }

            FlxU.saveToDevice(_historyString, (filename + "_" + DateTime.Now.Ticks.ToString() + ".txt"));

            infoText.text = "Saved file to device: " + filename + "_" + DateTime.Now.Ticks.ToString() + ".txt";

            _rec = Recording.None;
        }
Пример #23
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);
        }
Пример #24
0
        //public void setAngleBasedOnVelocity()
        //{
        //    double rot = Math.Atan2((float)velocity.Y, (float)velocity.X);
        //    double degrees = rot * 180 / Math.PI;

        //    angle = (float)degrees;
        //}

        /// <summary>
        /// Draws bounds
        /// </summary>
        /// <param name="spriteBatch">Sprite Batch</param>
        /// <param name="X">X</param>
        /// <param name="Y">Y</param>
        protected void drawBounds(SpriteBatch spriteBatch, int X, int Y)
        {
            spriteBatch.Draw(FlxG.XnaSheet,
                             new Rectangle((int)(FlxU.floor(x + FlxU.roundingError) + FlxU.floor(FlxG.scroll.X * scrollFactor.X)),
                                           (int)(FlxU.floor(y + FlxU.roundingError) + FlxU.floor(FlxG.scroll.Y * scrollFactor.Y)),
                                           (int)width,
                                           (int)height),
                             new Rectangle(1, 1, 1, 1),
                             getBoundingColor());

            if (path != null)
            {
                //int count = 0;


                // Draw a square for each node in a path
                //foreach (var item in path.nodes)
                //{
                //    spriteBatch.Draw(FlxG.XnaSheet,
                //        new Rectangle((int)item.X - 2 + (int)(FlxU.floor(FlxG.scroll.X * scrollFactor.X)),
                //            (int)item.Y - 2 + (int)(FlxU.floor(FlxG.scroll.Y * scrollFactor.Y)),
                //            4,
                //            4),
                //        new Rectangle(1, 1, 1, 1),
                //        Color.DarkOrange);
                //}

                // Draw a line for each node

                for (int i = 0; i < path.nodes.Count - 1; i++)
                {
                                        #if !__ANDROID__
                    spriteBatch.DrawLine(new Vector2((int)path.nodes[i].X - 2 + (int)(FlxU.floor(FlxG.scroll.X * scrollFactor.X)),
                                                     (int)path.nodes[i].Y - 2 + (int)(FlxU.floor(FlxG.scroll.Y * scrollFactor.Y))),
                                         new Vector2((int)path.nodes[i + 1].X - 2 + (int)(FlxU.floor(FlxG.scroll.X * scrollFactor.X)),
                                                     (int)path.nodes[i + 1].Y - 2 + (int)(FlxU.floor(FlxG.scroll.Y * scrollFactor.Y))),
                                         Color.DarkOrange, 1.0f);
                                        #endif
                }
            }
        }
Пример #25
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);
        }
Пример #26
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);
        }
Пример #27
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 });
        }
Пример #28
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);
        }
Пример #29
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;
            }
        }
Пример #30
0
 /// <summary>
 /// Checks to see if a point in 2D space overlaps this FlxCore object.
 /// </summary>
 /// <param name="X">The X coordinate of the point.</param>
 /// <param name="Y">The Y coordinate of the point.</param>
 /// <param name="PerPixel">Whether or not to use per pixel collision checking.</param>
 /// <returns>Whether or not the point overlaps this object.</returns>
 override public bool overlapsPoint(float X, float Y, bool PerPixel)
 {
     X      = X + FlxU.floor(FlxG.scroll.X);
     Y      = Y + FlxU.floor(FlxG.scroll.Y);
     _point = getScreenXY();
     //if(PerPixel)
     //    return _framePixels.hitTest(new Point(0,0),0xFF,new Point(X-_point.x,Y-_point.y));
     //else
     if (_stretchToFit == false)
     {
         if ((X <= _point.X) || (X >= _point.X + frameWidth) || (Y <= _point.Y) || (Y >= _point.Y + frameHeight))
         {
             return(false);
         }
     }
     else
     {
         if ((X <= _point.X) || (X >= _point.X + width) || (Y <= _point.Y) || (Y >= _point.Y + height))
         {
             return(false);
         }
     }
     return(true);
 }