Example #1
0
        public void shoot(FlxPoint Location, int Aim)
        {
            _sfxShoot.play(true);
            base.reset(Location.X - Width / 2, Location.Y - Height / 2);
            Solid = true;
            switch ((uint)Aim)
            {
            case Up:
                play("up");
                Velocity.Y = -speed;
                break;

            case Down:
                play("down");
                Velocity.Y = speed;
                break;

            case Left:
                play("left");
                Velocity.X = -speed;
                break;

            case Right:
                play("right");
                Velocity.X = speed;
                break;

            default:
                break;
            }
        }
Example #2
0
        public FlxSprite(float X = 0, float Y = 0, Texture2D Graphic = null)
            : base(X, Y)
        {
            scale = new FlxPoint(1.0f, 1.0f);
            offset = new FlxPoint();
            origin = new FlxPoint();
            alpha = 1.0f;
            _color = Color.White * alpha;

            _animations = new List<FlxAnim>();
            _animated = false;

            finished = false;
            _facing = RIGHT;
            _flipped = 0;
            _curAnim = null;
            _curFrame = 0;
            _curIndex = 0;
            _frameTimer = 0;

            _callback = null;
            _matrix = new Matrix();

            if (Graphic == null)
                Graphic = ImgDefault;
            loadGraphic(Graphic);

            angle = 0f;

            camX = camY = 0;
            oX = X;
            oY = Y;

            moving = false;
        }
Example #3
0
        /**
         * Creates a new <code>FlxButton</code> object with a gray background and a
         * callback function on the UI thread.
         *
         * @param X The X position of the button.
         * @param Y The Y position of the button.
         * @param Label The text that you want to appear on the button.
         * @param OnClick The function to call whenever the button is clicked.
         */
        public FlxButton(float x = 0, float y = 0, String label = null, FlxButtonEvent Callback = null) : base(x, y)
        {
            if (label != null)
            {
                Label = new FlxText(x - 1, y + 3, 80, label);
                Label.setFormat(null, 8, new Color(0x33, 0x33, 0x33), "center", Color.Transparent);
                LabelOffset = new FlxPoint(-1, 3);
            }
            loadGraphic(ImgDefaultButton, true, false, 80, 20);
            _callback = Callback;

            /*
             * onUp = OnClick;
             *
             * onDown = null;
             * onOut = null;
             * onOver = null;
             */
            SoundOver = null;
            SoundOut  = null;
            SoundDown = null;
            SoundUp   = null;

            Status       = Normal;
            _onToggle    = false;
            _pressed     = false;
            _initialized = false;
        }
Example #4
0
        //This is the constructor for the enemy class.  Because we are
        //recycling enemies, we don't want our constructor to have any
        //required parameters.
        public Enemy() : base()
        {
            loadRotatedGraphic(ImgBot, 64, 0, false, true);

            //We want the enemy's "hit box" or actual size to be
            //smaller than the enemy graphic itself, just by a few pixels.
            Width  = 12;
            Height = 12;
            centerOffsets();

            //Here we are setting up the jet particles
            // that shoot out the back of the ship.
            _jets = new FlxEmitter();
            _jets.setRotation();
            //_jets.MakeParticles(ImgJet,15,0,false,0);

            //These parameters help control the ship's
            //speed and direction during the update() loop.
            MaxAngular      = 120;
            AngularDrag     = 400;
            Drag.X          = 35;
            _thrust         = 0;
            _playerMidpoint = new FlxPoint();

            _sfxExplode = new FlxSound().loadEmbedded(SndExplode, false, false);
            _sfxHit     = new FlxSound().loadEmbedded(SndHit, false, false);
            _sfxJet     = new FlxSound().loadEmbedded(SndJet, false, false);
        }
Example #5
0
 /**
  * Instantiate a new particle.  Like <code>FlxSprite</code>, all meaningful creation
  * happens during <code>loadGraphic()</code> or <code>makeGraphic()</code> or whatever.
  */
 public FlxParticle()
     : base()
 {
     lifespan = 0;
     friction = 500;
     rotateBy = 0;
     minSpeed = new FlxPoint();
     maxSpeed = new FlxPoint();
     particleRect = null;
 }
Example #6
0
 public FlxBasic()
 {
     ID = -1;
     exists = true;
     active = true;
     visible = true;
     alive = true;
     ignoreDrawDebug = false;
     position = new FlxPoint();
 }
Example #7
0
 public void shoot(FlxPoint Location, float Angle)
 {
     _sfxShoot.play(true);
     base.reset(Location.X - Width / 2, Location.Y - Height / 2);
     FlxU.rotatePoint(0, (int)speed, 0, 0, Angle, _tagPoint);
     Velocity.X = _tagPoint.X;
     Velocity.Y = _tagPoint.Y;
     Solid      = (true);
     play("idle");
 }
Example #8
0
        //Called by flixel to help clean up memory.

        public override void destroy()
        {
            base.destroy();

            _player  = null;
            _bullets = null;
            _gibs    = null;

            _jets.destroy();
            _jets = null;

            _playerMidpoint = null;
        }
Example #9
0
        public Player(int X = 0, int Y = 0)
            : base(X, Y)
        {
            maxVelocity = new FlxPoint(100, 100);
            drag = new FlxPoint(500, 500);
            makeGraphic(40, 40, FlxColor.CADETBLUE);

            _currPos = new FlxPoint(x, y);
            _lastPos = new FlxPoint(x, y);
            _nodes = new List<FlxPoint>();
            _nodes.Add(_lastPos);
            _nodes.Add(_currPos);
            _path = new FlxPath(_nodes);

            footsteps = new FlxEmitter(x + width / 2, y + height / 2, 0, this);
            footsteps.makeParticles(FlxG.content.Load<Texture2D>("footsteps"), true, 25, 0f, 0f);
            footsteps.setXSpeed();
            footsteps.setYSpeed();

            _indoors = false;
        }
Example #10
0
        public FlxCamera(float X, float Y, float Width, float Height, float Zoom = 1.0f)
            : base()
        {
            x = X;
            y = Y;
            width = Width;
            height = Height;
            defaultZoom = 1.0f;
            rotating = 0.0f;
            scroll = new FlxPoint();
            _point = new FlxPoint();
            target = null;
            deadzone = null;
            bounds = null;
            zooming = Zoom;

            _fxShakeIntensity = 0;
            _fxShakeDuration = 0;
            _fxShakeComplete = null;
            _fxShakeOffset = new FlxPoint();
            _fxShakeDirection = 0;
        }
Example #11
0
        /// <summary>
        /// Check to see if a point in 2D world space overlaps this FlxObject
        /// </summary>
        /// <param name="Point">The point in world space you want to check</param>
        /// <param name="InScreenSpace">Whether to take scroll factors into account.</param>
        /// <param name="Camera">Which Camera - currently only one exists</param>
        /// <returns></returns>
        public virtual bool overlapsPoint(FlxPoint Point, bool InScreenSpace = false, FlxCamera Camera = null)
        {
            if (!InScreenSpace)
                return (Point.x > x) && (Point.x < x + width) && (Point.y > y) && (Point.y < y + height);

            if (Camera == null)
                Camera = FlxG.camera;
            float X = Point.x - Camera.scroll.x;
            float Y = Point.y - Camera.scroll.y;
            getScreenXY(_point, Camera);
            return (X > _point.x) && (X < _point.x + width) && (Y > _point.y) && (Y < _point.y + height);
        }
Example #12
0
 /// <summary>
 /// Call this to figure out the on-screen position of the object
 /// </summary>
 /// <param name="Point">Take a FlxPoint object and assign the post-scrolled X and Y values of this object to it</param>
 /// <param name="Camera">Which Camera - currently only one exists</param>
 /// <returns></returns>
 public FlxPoint getScreenXY(FlxPoint Point=null, FlxCamera Camera=null)
 {
     if(Point == null)
         Point = new FlxPoint();
     if(Camera == null)
         Camera = FlxG.camera;
     Point.x = x - (Camera.scroll.x*scrollFactor.x);
     Point.y = y - (Camera.scroll.y*scrollFactor.y);
     Point.x += (Point.x > 0)?0.0000001f:-0.0000001f;
     Point.y += (Point.y > 0)?0.0000001f:-0.0000001f;
     return Point;
 }
Example #13
0
 /// <summary>
 /// Retrieve midpoint of this object in world coordinates
 /// </summary>
 /// <param name="Point"></param>
 /// <returns></returns>
 public FlxPoint getMidpoint(FlxPoint Point=null)
 {
     if(Point == null)
         Point = new FlxPoint();
     Point.x = x + (width / 2);
     Point.y = y + (height / 2);
     return Point;
 }
Example #14
0
 /// <summary>
 /// Override to null out variables manually
 /// </summary>
 public override void destroy()
 {
     velocity = null;
     acceleration = null;
     drag = null;
     maxVelocity = null;
     scrollFactor = null;
     _point = null;
     _rect = null;
     last = null;
     //cameras = null;
     if (path != null)
         path.destroy();
     path = null;
 }
Example #15
0
        /// <summary>
        /// Instantiates a <code>FlxObject</code>
        /// </summary>
        /// <param name="X">X-coordinate of the object in space</param>
        /// <param name="Y">y-coordinate of the object in space</param>
        /// <param name="Width">Desired width of the rectangle</param>
        /// <param name="Height">Desired height of the rectangle</param>
        public FlxObject(float X = 0, float Y = 0, float Width = 0, float Height = 0)
            : base()
        {
            x = X;
            y = Y;
            last = new FlxPoint(x, y);
            width = Width;
            height = Height;
            mass = 1.0f;
            elasticity = 0.0f;

            health = 1;

            immovable = false;
            moves = true;

            touching = NONE;
            wasTouching = NONE;
            allowCollisions = ANY;

            velocity = new FlxPoint();
            acceleration = new FlxPoint();
            drag = new FlxPoint();
            maxVelocity = new FlxPoint(10000, 10000);

            angle = 0;
            angularVelocity = 0;
            angularAcceleration = 0;
            angularDrag = 0;
            maxAngular = 10000;

            scrollFactor = new FlxPoint(1, 1);
            _flicker = false;
            _flickerTimer = 0;

            _point = new FlxPoint();
            _rect = new FlxRect();

            path = null;
            pathSpeed = 0;
            pathAngle = 0;
        }
Example #16
0
        /**
         * Basic button update logic
         */
        protected void UpdateButton()
        {
            if (Status == Pressed)
            {
                Status = Normal;
            }

            // Figure out if the button is Highlighted or Pressed or what
            // (ignore checkbox behavior for now).

            if (FlxG.mouse.cursor.Visible)
            {
                if (Cameras == null)
                {
                    Cameras = FlxG.cameras;
                }
                FlxCamera Camera;
                int       i         = 0;
                int       l         = Cameras.Count;
                int       pointerId = 0;
                //int totalPointers = FlxG.mouse.ActivePointers + 1;
                int     totalPointers = 2;
                Boolean offAll        = true;
                while (i < l)
                {
                    Camera = Cameras[i++];
                    while (pointerId < totalPointers)
                    {
                        FlxPoint p = new FlxPoint(FlxG.mouse.cursor.X, FlxG.mouse.cursor.Y);
                        if (overlapsPoint(p, true, Camera))
                        {
                            offAll = false;
                            if (FlxG.mouse.pressed())
                            {
                                Status = Pressed;
                                //if(FlxG.mouse.justPressed(pointerId))
                                if (FlxG.mouse.justPressed())
                                {
                                    /*
                                     * if(OnDown != null)
                                     * {
                                     *      OnDown.Callback();
                                     * }
                                     * if(SoundDown != null)
                                     *      SoundDown.Play(true);
                                     */
                                }
                            }

                            if (Status == Normal)
                            {
                                Status = Highlight;

                                /*
                                 * if(OnOver != null)
                                 *      OnOver.Callback();
                                 * if(SoundOver != null)
                                 *      SoundOver.Play(true);
                                 */
                            }
                        }
                        ++pointerId;
                    }
                }
                if (offAll)
                {
                    if (Status != Normal)
                    {
                        /*
                         * if(OnOut != null)
                         *      OnOut.Callback();
                         *
                         * if(SoundOut != null)
                         *      SoundOut.Play(true);
                         */
                    }
                    Status = Normal;
                }
            }

            // Then if the Label and/or the Label offset exist,
            // position them to match the button.
            if (Label != null)
            {
                Label.X = X;
                Label.Y = Y;
            }
            if (LabelOffset != null)
            {
                Label.X += LabelOffset.X;
                Label.Y += LabelOffset.Y;
            }

            // Then pick the appropriate frame of animation
            if ((Status == Highlight) && (_onToggle /*|| FlxG.mobile*/))
            {
                Frame = Normal;
            }
            else
            {
                Frame = Status;
            }
        }
Example #17
0
        public override void destroy()
        {
            if(_animations != null)
            {
                FlxAnim a;
                int i = 0;
                int l = _animations.Count;
                while(i < l)
                {
                    a = _animations[i++];
                    if(a != null)
                        a.destroy();
                }
                _animations = null;
            }

            offset = null;
            origin = null;
            scale = null;
            _curAnim = null;
            _callback = null;
        }
Example #18
0
        /**
         * Find a path through the tilemap.  Any tile with any collision flags set is treated as impassable.
         * If no path is discovered then a null reference is returned.
         *
         * @param	Start		The start point in world coordinates.
         * @param	End			The end point in world coordinates.
         * @param	Simplify	Whether to run a basic simplification algorithm over the path data, removing extra points that are on the same line.  Default value is true.
         * @param	RaySimplify	Whether to run an extra raycasting simplification algorithm over the remaining path data.  This can result in some close corners being cut, and should be used with care if at all (yet).  Default value is false.
         *
         * @return	A <code>FlxPath</code> from the start to the end.  If no path could be found, then a null reference is returned.
         */
        public FlxPath findPath(FlxPoint Start, FlxPoint End, bool Simplify=true, bool RaySimplify=false)
        {
            //figure out what tile we are starting and ending on.
            int startIndex = (int)((Start.y-y)/_tileHeight) * widthInTiles + (int)((Start.x-x)/_tileWidth);
            int endIndex = (int)((End.y-y)/_tileHeight) * widthInTiles + (int)((End.x-x)/_tileWidth);

            //check that the start and end are clear.
            if( ((_tileObjects[_data[startIndex]] as FlxTile).allowCollisions > 0) ||
                ((_tileObjects[_data[endIndex]] as FlxTile).allowCollisions > 0) )
                return null;

            //figure out how far each of the tiles is from the starting tile
            List<int> distances = computePathDistance(startIndex,endIndex);
            if(distances == null)
                return null;

            //then count backward to find the shortest path.
            List<FlxPoint> points = new List<FlxPoint>();
            walkPath(distances,endIndex,points);

            //reset the start and end points to be exact
            FlxPoint node;
            node = points[points.Count-1] as FlxPoint;
            node.x = Start.x;
            node.y = Start.y;
            node = points[0] as FlxPoint;
            node.x = End.x;
            node.y = End.y;

            //some simple path cleanup options
            if(Simplify)
                simplifyPath(points);
            if(RaySimplify)
                raySimplifyPath(points);

            //finally load the remaining points into a new path object and return it
            FlxPath path = new FlxPath();
            int i = points.Count - 1;
            while(i >= 0)
            {
                node = points[i--] as FlxPoint;
                if(node != null)
                    path.addPoint(node,true);
            }
            return path;
        }
Example #19
0
 /**
  * Clean up memory.
  */
 public override void destroy()
 {
     minParticleSpeed = null;
     maxParticleSpeed = null;
     particleDrag = null;
     particleClass = null;
     _point = null;
     base.destroy();
 }
Example #20
0
        // overlapsPoint
        public override Boolean overlapsPoint(FlxPoint Point, Boolean InScreenSpace = false, FlxCamera Camera = null)
        {
            if (!InScreenSpace)
                return (_tileObjects[_data[(int)(((Point.y - y) / _tileHeight) * widthInTiles + (Point.x - x) / _tileWidth)]] as FlxTile).allowCollisions > 0;

            if (Camera == null)
                Camera = FlxG.camera;
            Point.x = Point.x - Camera.scroll.x;
            Point.y = Point.y - Camera.scroll.y;
            getScreenXY(_point, Camera);
            return (_tileObjects[_data[(int)(((Point.y - _point.y) / _tileHeight) * widthInTiles + (Point.x - _point.x) / _tileWidth)]] as FlxTile).allowCollisions > 0;
        }
Example #21
0
 /// <summary>
 /// Shift the camera's focus onto a specific point in the game-world.
 /// </summary>
 /// <param name="Point"></param>
 public void focusOn(FlxPoint Point)
 {
     Point.x += (Point.x > 0) ? (int)0.0000001 : (int)-0.0000001;
     Point.y += (Point.y > 0) ? (int)0.0000001 : (int)-0.0000001;
     scroll = new FlxPoint(Point.x - width * (int)0.5, Point.y - height * (int)0.5);
 }
Example #22
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;
        }
Example #23
0
        // overlapsWithCallBack
        public Boolean overlapsWithCallback(FlxObject Object, Func<FlxObject, FlxObject, Boolean> Callback=null, Boolean FlipCallbackParams=false, FlxPoint Position=null)
        {
            Boolean results = false;

            float X = x;
            float Y = 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;
        }
Example #24
0
 /// <summary>
 /// Override this to null out variables or manually call <code>destroy()</code> on class members.  Dont forget to call <code>base.destroy()</code>
 /// </summary>
 public virtual void destroy()
 {
     position = null;
 }
Example #25
0
 /**
  * Creates a new <code>FlxEmitter</code> object at a specific position.
  * Does NOT automatically generate or attach particles!
  *
  * @param	X		The X position of the emitter.
  * @param	Y		The Y position of the emitter.
  * @param	Size	Optional, specifies a maximum capacity for this emitter.
  */
 public FlxEmitter(float X=0, float Y=0, uint Size=0, FlxObject Target=null)
     : base(Size)
 {
     //super(Size);
     x = X;
     y = Y;
     width = 0;
     height = 0;
     minParticleSpeed = new FlxPoint(-100,-100);
     maxParticleSpeed = new FlxPoint(100,100);
     minRotation = -360;
     maxRotation = 360;
     gravity = 0;
     particleClass = null;
     particleDrag = new FlxPoint();
     frequency = 0.1f;
     lifespan = 3;
     bounce = 0;
     _quantity = 0;
     _counter = 0;
     _explode = true;
     on = false;
     _point = new FlxPoint();
     target = Target;
 }