Example #1
0
        protected override void Create()
        {
            FlxG.Mouse.Visible = true;

            _bat = new FlxSprite(180, 220);
            _bat.MakeGraphic(40, 6, Color.Magenta);
            _bat.Immovable = true;

            _ball = new FlxSprite(180, 160);
            _ball.MakeGraphic(6, 6, Color.Magenta);

            _ball.Elasticity  = 1;
            _ball.MaxVelocity = new Vector2(200, 200);
            _ball.Velocity.Y  = 200;

            _walls = new FlxGroup();

            _leftWall = new FlxSprite(0, 0);
            _leftWall.MakeGraphic(10, 240, Color.Gray);
            _leftWall.Immovable = true;
            _walls.Add(_leftWall);

            _rightWall = new FlxSprite(310, 0);
            _rightWall.MakeGraphic(10, 240, Color.Gray);
            _rightWall.Immovable = true;
            _walls.Add(_rightWall);

            _topWall = new FlxSprite(0, 0);
            _topWall.MakeGraphic(320, 10, Color.Gray);
            _topWall.Immovable = true;
            _walls.Add(_topWall);

            _bottomWall = new FlxSprite(0, 239);
            _bottomWall.MakeGraphic(320, 10, Color.Transparent);
            _bottomWall.Immovable = true;
            _walls.Add(_bottomWall);

            _bricks = new FlxGroup();
            int bx = 10;
            int by = 30;

            Color[] brickColors = { new Color(208,  58, 209), new Color(247,  83, 82),
                                    new Color(253, 128,  20), new Color(255, 144, 36),
                                    new Color(5,   179,  32), new Color(109, 101, 246) };
            for (int y = 0; y < 6; y++)
            {
                for (int x = 0; x < 20; x++)
                {
                    FlxSprite tempBrick = new FlxSprite(bx, by);
                    tempBrick.MakeGraphic(15, 15, brickColors[y]);
                    tempBrick.Immovable = true;
                    _bricks.Add(tempBrick);
                    bx += 15;
                }
                bx  = 10;
                by += 15;
            }

            Add(_walls);
            Add(_bat);
            Add(_ball);
            Add(_bricks);
        }