Exemple #1
0
        /**
         * Fills the block with a randomly arranged selection of graphics from the image provided.
         *
         * @param	TileGraphic 	The graphic class that contains the tiles that should fill this block.
         * @param	TileWidth		The width of a single tile in the graphic.
         * @param	TileHeight		The height of a single tile in the graphic.
         * @param	Empties			The number of "empty" tiles to add to the auto-fill algorithm (e.g. 8 tiles + 4 empties = 1/3 of block will be open holes).
         */
        public FlxTileblock loadTiles(string TileGraphic,uint TileWidth=0,uint TileHeight=0, uint Empties=0)
        {
            if(TileGraphic == null)
                return this;

            //First create a tile brush
            FlxSprite sprite = new FlxSprite();
            sprite.loadGraphic(TileGraphic, true, false, TileWidth, TileHeight);
            uint spriteWidth = (uint)sprite.Width;
            uint spriteHeight = (uint)sprite.Height;
            uint total = sprite.Frames + Empties;

            //Then prep the "canvas" as it were (just doublechecking that the size is on tile boundaries)
            bool regen = false;
            if(Width % sprite.Width != 0)
            {
                Width = (uint)(Width/spriteWidth+1)*spriteWidth;
                regen = true;
            }
            if(Height % sprite.Height != 0)
            {
                Height = (uint)(Height/spriteHeight+1)*spriteHeight;
                regen = true;
            }
            if(regen)
                makeGraphic((uint)Width,(uint)Height,Color.Green,true);
            else
                this.fill(Color.Green);

            //Stamp random tiles onto the canvas
            uint row = 0;
            uint column;
            int destinationX;
            int destinationY = 0;
            uint widthInTiles = (uint)Width/spriteWidth;
            uint heightInTiles = (uint)Height/spriteHeight;
            while(row < heightInTiles)
            {
                destinationX = 0;
                column = 0;
                while(column < widthInTiles)
                {
                    if(FlxG.random()*total > Empties)
                    {
                        sprite.randomFrame();
                        sprite.drawFrame();
                        stamp(sprite, destinationX, destinationY);
                    }
                    destinationX += (int)spriteWidth;
                    column++;
                }
                destinationY += (int)spriteHeight;
                row++;
            }

            return this;
        }
		private void setupPlayer ()
		{
			player = new FlxSprite (64, 220);
			player.loadGraphic (ImgSpaceman, true, true, 16);

			//bounding box tweaks
			player.Width = 14;
			player.Height = 14;
			player.Offset.X = 1;
			player.Offset.Y = 1;

			//basic player physics
			player.Drag.X = 640;
			player.Acceleration.Y = 420;
			player.MaxVelocity.X = 80;
			player.MaxVelocity.Y = 200;

			//animations
			player.addAnimation ("idle", new int[]{ 0 });
			player.addAnimation ("run", new int[]{ 1, 2, 3, 0 }, 12);
			player.addAnimation ("jump", new int[]{ 4 });

			add (player);
		}
Exemple #3
0
        /// <summary>
        /// This function generates a new array of particle sprites to attach to the emitter.
        /// </summary>
        /// <param name="graphics">Texture for the particles - can be one square or a spritesheet.  Set Multiple to true if it is a spritesheet and it will automatically create the particles as long as each frame on the spritesheet is square</param>
        /// <param name="Multiple">Whether or not the Texture contains multiple sprites for particles</param>
        /// <param name="Quantity">The number of particles to generate</param>
        /// <param name="Rotation">The amount of rotation in degrees per frame, so keep this number low</param>
        /// <param name="Collide">The collidability of the particle, 1 = Full and 0 = None</param>
        /// <returns>This FlxEmitter instance (nice for chaining stuff together, if you're into that).</returns>
        //public FlxEmitter makeParticles(Texture2D graphics, bool Multiple=false, uint Quantity = 50, float Rotation = 1f, float Collide = 0.8f)
        public FlxEmitter makeParticles(string graphics, uint Quantity = 50, uint BakedRotations = 0, bool Multiple = false, float Collide = 0.8f)
        {
            maxSize = Quantity;
            uint totalFrames = 0;

            if (Multiple) {
                FlxSprite sprite = new FlxSprite();
                sprite.loadGraphic(graphics,true);
                totalFrames = sprite.Frames;
                sprite.destroy();
            }

            uint randomFrame;
            FlxParticle particle;
            int i = 0;

            while(i < Quantity)
            {
                particle = new FlxParticle();
                /*
                if(particleClass == null)
                    particle = new FlxParticle();
                else
                    particle = new particleClass();
                */
                if(Multiple)
                {
                    randomFrame = (uint)(FlxG.random()*totalFrames);
                    if(BakedRotations > 0)
                        particle.loadRotatedGraphic(graphics,BakedRotations,(int)randomFrame);
                    else
                    {
                        particle.loadGraphic(graphics,true);
                        particle.Frame = (int)randomFrame;
                    }
                }
                else
                {
                    if(BakedRotations > 0)
                        particle.loadRotatedGraphic(graphics,BakedRotations);
                    else
                        particle.loadGraphic(graphics);
                }
                if(Collide > 0)
                {
                    particle.Width *= Collide;
                    particle.Height *= Collide;
                    particle.centerOffsets();
                }
                else
                    particle.AllowCollisions = FlxObject.None;
                particle.Exists = false;
                add(particle);
                i++;
            }

            return this;
        }
Exemple #4
0
        /// <summary>
        /// This function generates a new array of particle sprites to attach to the emitter.
        /// </summary>
        /// <param name="graphics">Texture for the particles - can be one square or a spritesheet.  Set Multiple to true if it is a spritesheet and it will automatically create the particles as long as each frame on the spritesheet is square</param>
        /// <param name="Multiple">Whether or not the Texture contains multiple sprites for particles</param>
        /// <param name="Quantity">The number of particles to generate</param>
        /// <param name="Rotation">The amount of rotation in degrees per frame, so keep this number low</param>
        /// <param name="Collide">The collidability of the particle, 1 = Full and 0 = None</param>
        /// <returns>This FlxEmitter instance (nice for chaining stuff together, if you're into that).</returns>
        //public FlxEmitter makeParticles(Texture2D graphics, bool Multiple=false, uint Quantity = 50, float Rotation = 1f, float Collide = 0.8f)
        public FlxEmitter makeParticles(string graphics, uint Quantity = 50, uint BakedRotations = 0, bool Multiple = false, float Collide = 0.8f)
        {
            maxSize = Quantity;
            uint totalFrames = 0;

            if (Multiple)
            {
                FlxSprite sprite = new FlxSprite();
                sprite.loadGraphic(graphics, true);
                totalFrames = sprite.Frames;
                sprite.destroy();
            }

            uint        randomFrame;
            FlxParticle particle;
            int         i = 0;

            while (i < Quantity)
            {
                particle = new FlxParticle();

                /*
                 * if(particleClass == null)
                 *      particle = new FlxParticle();
                 * else
                 *      particle = new particleClass();
                 */
                if (Multiple)
                {
                    randomFrame = (uint)(FlxG.random() * totalFrames);
                    if (BakedRotations > 0)
                    {
                        particle.loadRotatedGraphic(graphics, BakedRotations, (int)randomFrame);
                    }
                    else
                    {
                        particle.loadGraphic(graphics, true);
                        particle.Frame = (int)randomFrame;
                    }
                }
                else
                {
                    if (BakedRotations > 0)
                    {
                        particle.loadRotatedGraphic(graphics, BakedRotations);
                    }
                    else
                    {
                        particle.loadGraphic(graphics);
                    }
                }
                if (Collide > 0)
                {
                    particle.Width  *= Collide;
                    particle.Height *= Collide;
                    particle.centerOffsets();
                }
                else
                {
                    particle.AllowCollisions = FlxObject.None;
                }
                particle.Exists = false;
                add(particle);
                i++;
            }

            return(this);
        }
Exemple #5
0
        /**
         * Fills the block with a randomly arranged selection of graphics from the image provided.
         *
         * @param	TileGraphic     The graphic class that contains the tiles that should fill this block.
         * @param	TileWidth		The width of a single tile in the graphic.
         * @param	TileHeight		The height of a single tile in the graphic.
         * @param	Empties			The number of "empty" tiles to add to the auto-fill algorithm (e.g. 8 tiles + 4 empties = 1/3 of block will be open holes).
         */
        public FlxTileblock loadTiles(string TileGraphic, uint TileWidth = 0, uint TileHeight = 0, uint Empties = 0)
        {
            if (TileGraphic == null)
            {
                return(this);
            }

            //First create a tile brush
            FlxSprite sprite = new FlxSprite();

            sprite.loadGraphic(TileGraphic, true, false, TileWidth, TileHeight);
            uint spriteWidth  = (uint)sprite.Width;
            uint spriteHeight = (uint)sprite.Height;
            uint total        = sprite.Frames + Empties;

            //Then prep the "canvas" as it were (just doublechecking that the size is on tile boundaries)
            bool regen = false;

            if (Width % sprite.Width != 0)
            {
                Width = (uint)(Width / spriteWidth + 1) * spriteWidth;
                regen = true;
            }
            if (Height % sprite.Height != 0)
            {
                Height = (uint)(Height / spriteHeight + 1) * spriteHeight;
                regen  = true;
            }
            if (regen)
            {
                makeGraphic((uint)Width, (uint)Height, Color.Green, true);
            }
            else
            {
                this.fill(Color.Green);
            }

            //Stamp random tiles onto the canvas
            uint row = 0;
            uint column;
            int  destinationX;
            int  destinationY  = 0;
            uint widthInTiles  = (uint)Width / spriteWidth;
            uint heightInTiles = (uint)Height / spriteHeight;

            while (row < heightInTiles)
            {
                destinationX = 0;
                column       = 0;
                while (column < widthInTiles)
                {
                    if (FlxG.random() * total > Empties)
                    {
                        sprite.randomFrame();
                        sprite.drawFrame();
                        stamp(sprite, destinationX, destinationY);
                    }
                    destinationX += (int)spriteWidth;
                    column++;
                }
                destinationY += (int)spriteHeight;
                row++;
            }

            return(this);
        }