Beispiel #1
0
        /// <summary>
        /// Tells this camera object what <code>FlxObject</code> to track.
        /// </summary>
        /// <param name="target">The object you want the camera to track. Set to null to not follow anything.</param>
        /// <param name="style">Leverage one of the existing "deadzone" presets.  If you use a custom deadzone, ignore this parameter and manually specify the deadzone after calling <code>follow()</code>.</param>
        public void follow(FlxObject target, uint style = StyleLockon)
        {
            Target = target;
            float helper;

            switch (style)
            {
            case StylePlatformer:
                float w = Width / 8;
                float h = Height / 3;
                Deadzone = new FlxRect((Width - w) / 2, (Height - h) / 2 - h * 0.25f, w, h);
                break;

            case StyleTopdown:
                helper   = FlxU.max(Width, Height) / 4;
                Deadzone = new FlxRect((Width - helper) / 2, (Height - helper) / 2, helper, helper);
                break;

            case StyleTopdownTight:
                helper   = FlxU.max(Width, Height) / 8;
                Deadzone = new FlxRect((Width - helper) / 2, (Height - helper) / 2, helper, helper);
                break;

            case StyleLockon:
                break;

            case StyleLoose:
                Deadzone = new FlxRect(0, 0, Width, Height);
                break;

            default:
                Deadzone = null;
                break;
            }
        }
Beispiel #2
0
        /**
         * You can use this if you have a lot of text parameters to set instead of
         * the individual properties.
         *
         * @param Font The name of the font face for the text display.
         * @param Size The size of the font (in pixels essentially).
         * @param Color The color of the text in 0xRRGGBB format.
         * @param Alignment A string representing the desired alignment
         *        ("left,"right" or "center").
         * @param ShadowColor An int representing the desired text shadow color
         *        0xAARRGGBB format.
         * @param ShadowX The x-position of the shadow, default is 1.
         * @param ShadowY The y-position of the shadow, default is 1.
         *
         * @return This FlxText instance (nice for chaining stuff together, if
         *         you're into that).
         */
        public FlxText setFormat(String Font, float size, Color color, String Alignment, Color ShadowColor, float ShadowX = 1f, float ShadowY = 1f)
        {
            if (Font == null)
            {
                Font = _font;
            }
            _size = (int)FlxU.floor(size);
            if (Font != null && (!Font.Equals(_font) || size != _size))
            {
                try {
                    //_textField = new SpriteBatch(FlxG.loadFont(Font, FlxU.round(Size), _bitmapFontParameter));
                    //_textField = new SpriteBatch(GraphicsDevice);
                } catch (Exception e) {
                    Console.WriteLine(e.Message);
                    FlxG.log(e.Message);
                    //_textField = new SpriteBatch(FlxG.loadFont("org/flixel/data/font/nokiafc.fnt", 22, _bitmapFontParameter));
                }

                _font      = Font;
                LoadedFont = FlxS.ContentManager.Load <SpriteFont> (_font);
            }

            Color = color;
            if (Alignment != null)
            {
                _alignment = (Alignment.ToUpper());
            }
            _shadow  = ShadowColor;
            _shadowX = ShadowX;
            _shadowY = ShadowY;

            calcFrame();

            return(this);
        }
Beispiel #3
0
        // overlapsWithCallBack
        public Boolean overlapsWithCallback(FlxObject Object, Func <FlxObject, FlxObject, Boolean> Callback = null, Boolean FlipCallbackParams = false, FlxPoint Position = null)
        {
            Boolean results = false;

            float X = base.X;
            float Y = base.Y;

            if (Position != null)
            {
                X = Position.X;
                Y = Position.X;
            }

            //Figure out what tiles we need to check against
            int  selectionX      = (int)FlxU.floor((Object.X - X) / _tileWidth);
            int  selectionY      = (int)FlxU.floor((Object.Y - Y) / _tileHeight);
            uint selectionWidth  = (uint)(selectionX + (FlxU.ceil((int)Object.Width / _tileWidth)) + 2);
            uint selectionHeight = (uint)(selectionY + (FlxU.ceil((int)Object.Height / _tileHeight)) + 2);

            //Then bound these coordinates by the map edges
            if (selectionX < 0)
            {
                selectionX = 0;
            }
            if (selectionY < 0)
            {
                selectionY = 0;
            }
            if (selectionWidth > widthInTiles)
            {
                selectionWidth = (uint)widthInTiles;
            }
            if (selectionHeight > heightInTiles)
            {
                selectionHeight = (uint)heightInTiles;
            }

            //Then loop through this selection of tiles and call FlxObject.separate() accordingly
            uint    rowStart = (uint)selectionY * (uint)widthInTiles;
            uint    row      = (uint)selectionY;
            uint    column;
            FlxTile tile;
            Boolean overlapFound;
            float   deltaX = X - Last.X;
            float   deltaY = Y - Last.Y;



            while (row < selectionHeight)
            {
                column = (uint)selectionX;
                while (column < selectionWidth)
                {
                    overlapFound = false;
                    tile         = _tileObjects[(int)_data[(int)(rowStart + column)]] as FlxTile;
                    if (Convert.ToBoolean(tile.AllowCollisions))
                    {
                        tile.X      = X + (int)column * _tileWidth;
                        tile.Y      = Y + (int)row * _tileHeight;
                        tile.Last.X = tile.X - deltaX;
                        tile.Last.Y = tile.Y - deltaY;
                        if (Callback != null)
                        {
                            if (FlipCallbackParams)
                            {
                                overlapFound = Callback(Object, tile);
                            }
                            else
                            {
                                overlapFound = Callback(tile, Object);
                            }
                        }
                        else
                        {
                            overlapFound = (Object.X + Object.Width > tile.X) && (Object.X < tile.X + tile.Width) && (Object.Y + Object.Height > tile.Y) && (Object.Y < tile.Y + tile.Height);
                        }
                        if (overlapFound)
                        {
                            if ((tile.callback != null))
                            {
                                tile.mapIndex = (uint)rowStart + column;
                                tile.callback(tile, Object);
                            }
                            results = true;
                        }
                    }
                    else if ((tile.callback != null))
                    {
                        tile.mapIndex = (uint)rowStart + (uint)column;
                        tile.callback(tile, Object);
                    }
                    column++;
                }
                rowStart += (uint)widthInTiles;
                row++;
            }
            return(results);
        }
Beispiel #4
0
        /**
         * Shoots a ray from the start point to the end point.
         * If/when it passes through a tile, it stores that point and returns false.
         *
         * @param	Start		The world coordinates of the start of the ray.
         * @param	End			The world coordinates of the end of the ray.
         * @param	Result		A <code>Point</code> object containing the first wall impact.
         * @param	Resolution	Defaults to 1, meaning check every tile or so.  Higher means more checks!
         * @return	Returns true if the ray made it from Start to End without hitting anything.  Returns false and fills Result if a tile was hit.
         */
        public bool ray(FlxPoint Start, FlxPoint End, FlxPoint Result = null, float Resolution = 1f)
        {
            float step = _tileWidth;

            if (_tileHeight < _tileWidth)
            {
                step = _tileHeight;
            }
            step /= Resolution;
            float deltaX   = End.X - Start.X;
            float deltaY   = End.Y - Start.Y;
            float distance = (float)Math.Sqrt(deltaX * deltaX + deltaY * deltaY);
            int   steps    = (int)FlxU.ceil(distance / step);
            float stepX    = deltaX / steps;
            float stepY    = deltaY / steps;
            float curX     = Start.X - stepX - X;
            float curY     = Start.Y - stepY - Y;
            int   tileX;
            int   tileY;
            int   i = 0;

            while (i < steps)
            {
                curX += stepX;
                curY += stepY;

                if ((curX < 0) || (curX > Width) || (curY < 0) || (curY > Height))
                {
                    i++;
                    continue;
                }

                tileX = (int)curX / _tileWidth;
                tileY = (int)curY / _tileHeight;
                if (Convert.ToBoolean((_tileObjects[_data[tileY * widthInTiles + tileX]] as FlxTile).AllowCollisions))
                {
                    //Some basic helper stuff
                    tileX *= _tileWidth;
                    tileY *= _tileHeight;
                    float rx = 0;
                    float ry = 0;
                    float q;
                    float lx = curX - stepX;
                    float ly = curY - stepY;

                    //Figure out if it crosses the X boundary
                    q = tileX;
                    if (deltaX < 0)
                    {
                        q += _tileWidth;
                    }
                    rx = q;
                    ry = ly + stepY * ((q - lx) / stepX);
                    if ((ry > tileY) && (ry < tileY + _tileHeight))
                    {
                        if (Result == null)
                        {
                            Result = new FlxPoint();
                        }
                        Result.X = rx;
                        Result.Y = ry;
                        return(false);
                    }

                    //Else, figure out if it crosses the Y boundary
                    q = tileY;
                    if (deltaY < 0)
                    {
                        q += _tileHeight;
                    }
                    rx = lx + stepX * ((q - ly) / stepY);
                    ry = q;
                    if ((rx > tileX) && (rx < tileX + _tileWidth))
                    {
                        if (Result == null)
                        {
                            Result = new FlxPoint();
                        }
                        Result.X = rx;
                        Result.Y = ry;
                        return(false);
                    }
                    return(true);
                }
                i++;
            }
            return(true);
        }
Beispiel #5
0
 /// <summary>
 /// Generates a random number based on the seed provided.
 /// </summary>
 /// <param name="seed">A number between 0 and 1, used to generate a predictable random number (very optional).</param>
 /// <returns>A <code>Number</code> between 0 and 1.</returns>
 public static float srand(float seed)
 {
     return(FlxU.abs((float)((69621 * (int)(seed * 0x7FFFFFFF)) % 0x7FFFFFFF) / 0x7FFFFFFF));
 }
Beispiel #6
0
        /// <summary>
        /// Handles fade out, fade in, panning, proximity, and amplitude operations each frame.
        /// </summary>
        override public void update()
        {
            if (_position != 0)
            {
                return;
            }

            float radial = 1.0f;
            float fade   = 1.0f;

            //Distance-based volume control
            if (_target != null)
            {
                radial = FlxU.getDistance(new FlxPoint(_target.X, _target.Y), new FlxPoint(x, y)) / _radius;
                if (radial < 0)
                {
                    radial = 0;
                }
                if (radial > 1)
                {
                    radial = 1;
                }

                if (_pan)
                {
                    float d = (_target.X - x) / _radius;
                    if (d < -1)
                    {
                        d = -1;
                    }
                    else if (d > 1)
                    {
                        d = 1;
                    }
                }
            }

            //Cross-fading volume control
            if (_fadeOutTimer > 0)
            {
                _fadeOutTimer -= FlxG.elapsed;
                if (_fadeOutTimer <= 0)
                {
                    if (_pauseOnFadeOut)
                    {
                        pause();
                    }
                    else
                    {
                        stop();
                    }
                }
                fade = _fadeOutTimer / _fadeOutTotal;
                if (fade < 0)
                {
                    fade = 0;
                }
            }
            else if (_fadeInTimer > 0)
            {
                _fadeInTimer -= FlxG.elapsed;
                fade          = _fadeInTimer / _fadeInTotal;
                if (fade < 0)
                {
                    fade = 0;
                }
                fade = 1 - fade;
            }

            _volumeAdjust = radial * fade;
            updateTransform();

            /*
             * if((_transform.volume > 0) && (_channel != null))
             * {
             *      amplitudeLeft = _channel.leftPeak/_transform.volume;
             *      amplitudeRight = _channel.rightPeak/_transform.volume;
             *      amplitude = (amplitudeLeft+amplitudeRight)*0.5;
             * }
             */
        }