Inheritance: FlxObject
Esempio n. 1
0
        public FlxTile(FlxTilemap Tilemap, int Tx, int Ty, int Index, int Width, int Height, Boolean Visible, uint AllowCollisions)
            : base(0, 0, Width, Height)
        {
            immovable = true;
            moves = false;
            callback = null;

            if (width > height)
                tileSize = width;
            else
                tileSize = height;

            tilemap = Tilemap;
            tileGraphic = tilemap.tileGraphic;
            index = Index;
            visible = Visible;
            allowCollisions = AllowCollisions;

            mapIndex = 0;

            tileGraphicSectionToDraw = new Rectangle((int)index * (int)tileSize, 0, (int)width, (int)height);
            drawPosition = new Vector2(Tx * Width, Ty * Height);

            //if(Convert.ToBoolean(allowCollisions))
            //    FlxG.log("my tile index: " + index +", coll: "+allowCollisions);

            ID = 2;
        }
Esempio n. 2
0
        public FlxTile(FlxTilemap Tilemap, int Tx, int Ty, int Index, int Width, int Height, Boolean Visible, uint AllowCollisions)
            : base(0, 0, Width, Height)
        {
            Immovable = true;
            Moves     = false;
            callback  = null;

            if (base.Width > base.Height)
            {
                tileSize = base.Width;
            }
            else
            {
                tileSize = base.Height;
            }

            tilemap     = Tilemap;
            tileGraphic = tilemap.tileGraphic;
            index       = Index;
            ((FlxBasic)this).Visible = Visible;
            base.AllowCollisions     = AllowCollisions;

            mapIndex = 0;

            tileGraphicSectionToDraw = new Rectangle((int)index * (int)tileSize, 0, (int)base.Width, (int)base.Height);
            drawPosition             = new Vector2(Tx * Width, Ty * Height);

            //if(Convert.ToBoolean(allowCollisions))
            //    FlxG.log("my tile index: " + index +", coll: "+allowCollisions);

            ID = 2;
        }
Esempio n. 3
0
        /// <summary>
        /// Checks to see if this FlxObject were located at the given position
        /// </summary>
        /// <param name="X">X position you want to check</param>
        /// <param name="Y">Y position you want to check</param>
        /// <param name="ObjectOrGroup">The object or group being tested</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 overlapsAt(float X, float Y, FlxBasic ObjectOrGroup, bool InScreenSpace = false, FlxCamera Camera = null)
        {
            if (ObjectOrGroup is FlxGroup)
            {
                bool results = false;
                int  i = 0; List <FlxBasic> members = new List <FlxBasic>();
                members = (ObjectOrGroup as FlxGroup).members;
                uint length = (uint)members.Count;
                while (i < length)
                {
                    if (overlapsAt(X, Y, members[i++], InScreenSpace, Camera))
                    {
                        results = true;
                    }
                }
                return(results);
            }

            if (ObjectOrGroup is FlxTilemap)
            {
                FlxTilemap tilemap = ObjectOrGroup as FlxTilemap;
                return(tilemap.overlapsAt(tilemap.x - (X - x), tilemap.y - (Y - y), this, InScreenSpace, Camera));
            }

            FlxObject Object = ObjectOrGroup as FlxObject;

            if (!InScreenSpace)
            {
                return((Object.x + Object.width > X) && (Object.x < X + width) &&
                       (Object.y + Object.height > Y) && (Object.y < Y + height));
            }

            if (Camera == null)
            {
                Camera = FlxG.camera;
            }
            FlxPoint objectScreenPos = Object.getScreenXY(null, 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((objectScreenPos.x + Object.width > _point.x) && (objectScreenPos.x < _point.x + width) &&
                   (objectScreenPos.y + Object.height > _point.y) && (objectScreenPos.y < _point.y + height));
        }
Esempio n. 4
0
        public override void create()
        {
            base.create();

            FlxG.bgColor = Color.LightGray;

            //Design your platformer level with 1s and 0s (at 40x30 to fill 320x240 screen)
            int [] data = {
                    1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
                    1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1,
                    1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1,
                    1, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1,
                    1, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1,
                    1, 0, 0, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1,
                    1, 0, 0, 0, 1, 1, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1,
                    1, 0, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 1,
                    1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1,
                    1, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1,
                    1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1,
                    1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1,
                    1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1,
                    1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 1,
                    1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1,
                    1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1,
                    1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1,
                    1, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1,
                    1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 1,
                    1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 1,
                    1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 0, 0, 1,
                    1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
                    1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
                    1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1,
                    1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1,
                    1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1,
                    1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1,
                    1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 1, 1, 1, 1, 1, 0, 1, 0, 1, 1, 1, 1, 1, 0, 0, 0, 1, 1, 1, 1, 0, 1,
                    1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 1,
                    1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1
                    };

            level = new FlxTilemap();

            exit = new FlxSprite(35 * 8 + 1, 25 * 8);
            exit.makeGraphic(14, 16, new Color(3f, 3f, 3f ));
            exit.exists = false;
            add(exit);

            coins = new FlxGroup();
            //Top left coins
            createCoin(18, 4);
            createCoin(12, 4);
            createCoin(9, 4);
            createCoin(8, 11);
            createCoin(1, 7);
            createCoin(3, 4);
            createCoin(5, 2);
            createCoin(15, 11);
            createCoin(16, 11);

            //Bottom left coins
            createCoin(3, 16);
            createCoin(4, 16);
            createCoin(1, 23);
            createCoin(2, 23);
            createCoin(3, 23);
            createCoin(4, 23);
            createCoin(5, 23);
            createCoin(12, 26);
            createCoin(13, 26);
            createCoin(17, 20);
            createCoin(18, 20);

            //Top right coins
            createCoin(21, 4);
            createCoin(26, 2);
            createCoin(29, 2);
            createCoin(31, 5);
            createCoin(34, 5);
            createCoin(36, 8);
            createCoin(33, 11);
            createCoin(31, 11);
            createCoin(29, 11);
            createCoin(27, 11);
            createCoin(25, 11);
            createCoin(36, 14);

            //Bottom right coins
            createCoin(38, 17);
            createCoin(33, 17);
            createCoin(28, 19);
            createCoin(25, 20);
            createCoin(18, 26);
            createCoin(22, 26);
            createCoin(26, 26);
            createCoin(30, 26);
            add(coins);

            //Create player (a red box)
            player = new FlxSprite(FlxG.width / 2 - 5);
            player.makeGraphic(10, 12, new Color (170, 17, 17));
            player.maxVelocity.x = 80;
            player.maxVelocity.y = 200;
            player.acceleration.y = 200;
            player.drag.x = player.maxVelocity.x * 4;
            add(player);

            score = new FlxText(2, 2, 80);
            //score.shadow = 0xff000000;
            score.shadow = Color.Black;
            score.text = "SCORE: " + (coins.countDead() * 100);
            add(score);

            status = new FlxText(FlxG.width - 160 - 2, 2, 160);
            //status.shadow = 0xff000000;
            //status.alignment = "right";
            switch (FlxG.score)
            {
                case 0: status.text = "Collect coins."; break;
                case 1: status.text = "Aww, you died!"; break;
            }
            add(status);
        }