Beispiel #1
0
 protected override void Dispose(bool disposing)
 {
     base.Dispose(disposing);
     DPad.Dispose();
     Actions.Dispose();
     DPad        = null;
     Actions     = null;
     ButtonA     = null;
     ButtonB     = null;
     ButtonC     = null;
     ButtonX     = null;
     ButtonY     = null;
     ButtonLeft  = null;
     ButtonRight = null;
     ButtonUp    = null;
     ButtonDown  = null;
 }
Beispiel #2
0
        protected override void Create()
        {
            //VisibleHitbox = true;
            int screenMiddleX = (int)Math.Floor(FlxG.Width / 2f);
            int screenMiddleY = (int)Math.Floor(FlxG.Height / 2f);

            _snakeHead = new FlxSprite(screenMiddleX - BLOCK_SIZE * 2, screenMiddleY);
            _snakeHead.MakeGraphic(BLOCK_SIZE - 2, BLOCK_SIZE - 2, Color.Lime);
            _snakeHead.DebugColor = Color.Yellow;
            OffsetSprite(_snakeHead);

            _headPositions = new List <Vector2>
            {
                new Vector2(_snakeHead.X, _snakeHead.Y)
            };

            _snakeBody = new FlxSpriteGroup();
            Add(_snakeBody);

            for (int i = 0; i < 3; i++)
            {
                AddSegment();
                MoveSnake();
            }

            Add(_snakeHead);

            _fruit = new FlxSprite();
            _fruit.MakeGraphic(BLOCK_SIZE - 2, BLOCK_SIZE - 2, Color.Red);
            RandomizeFruitPosition();
            OffsetSprite(_fruit);
            Add(_fruit);

            _scoreText = new FlxText(0, 0, 200, "Score: " + _score);
            Add(_scoreText);

            ResetTimer();

            _gameOverSound = Game.Content.Load <SoundEffect>(FlxAssets.SOUND_FLIXEL);
            _beepSound     = Game.Content.Load <SoundEffect>(FlxAssets.SOUND_BEEP);
        }
Beispiel #3
0
        /// <summary>
        /// Create a gamepad which contains 4 directional buttons and 4 action buttons.
        /// </summary>
        /// <param name="dPad">The D-Pad mode. `FULL` for example.</param>
        /// <param name="action">The action buttons mode. `A_B_C` for example.</param>
        public FlxVirtualPad(FlxDPadMode?dPad = null, FlxActionMode?action = null)
        {
            ScrollFactor = Vector2.Zero;

            if (dPad == null)
            {
                dPad = FlxDPadMode.FULL;
            }
            if (!action.HasValue)
            {
                action = FlxActionMode.A_B_C;
            }

            DPad = new FlxSpriteGroup();
            DPad.ScrollFactor = Vector2.Zero;

            Actions = new FlxSpriteGroup();
            Actions.ScrollFactor = Vector2.Zero;

            switch (dPad.Value)
            {
            case FlxDPadMode.UP_DOWN:
                DPad.Add(Add(ButtonUp   = CreateButton(0, FlxG.Height - 85, 44, 45, "up")));
                DPad.Add(Add(ButtonDown = CreateButton(0, FlxG.Height - 45, 44, 45, "down")));
                break;

            case FlxDPadMode.LEFT_RIGHT:
                DPad.Add(Add(ButtonLeft  = CreateButton(0, FlxG.Height - 45, 44, 45, "left")));
                DPad.Add(Add(ButtonRight = CreateButton(42, FlxG.Height - 45, 44, 45, "right")));
                break;

            case FlxDPadMode.UP_LEFT_RIGHT:
                DPad.Add(Add(ButtonUp    = CreateButton(35, FlxG.Height - 81, 44, 45, "up")));
                DPad.Add(Add(ButtonLeft  = CreateButton(0, FlxG.Height - 45, 44, 45, "left")));
                DPad.Add(Add(ButtonRight = CreateButton(69, FlxG.Height - 45, 44, 45, "right")));
                break;

            case FlxDPadMode.FULL:
                DPad.Add(Add(ButtonUp    = CreateButton(35, FlxG.Height - 116, 44, 45, "up")));
                DPad.Add(Add(ButtonLeft  = CreateButton(0, FlxG.Height - 81, 44, 45, "left")));
                DPad.Add(Add(ButtonRight = CreateButton(69, FlxG.Height - 81, 44, 45, "right")));
                DPad.Add(Add(ButtonDown  = CreateButton(35, FlxG.Height - 45, 44, 45, "down")));
                break;

            case FlxDPadMode.NONE:
                break;
            }

            switch (action)
            {
            case FlxActionMode.A:
                Actions.Add(Add(ButtonA = CreateButton(FlxG.Width - 44, FlxG.Height - 45, 44, 45, "a")));
                break;

            case FlxActionMode.A_B:
                Actions.Add(Add(ButtonA = CreateButton(FlxG.Width - 44, FlxG.Height - 45, 44, 45, "a")));
                Actions.Add(Add(ButtonB = CreateButton(FlxG.Width - 86, FlxG.Height - 45, 44, 45, "b")));
                break;

            case FlxActionMode.A_B_C:
                Actions.Add(Add(ButtonA = CreateButton(FlxG.Width - 128, FlxG.Height - 45, 44, 45, "a")));
                Actions.Add(Add(ButtonB = CreateButton(FlxG.Width - 86, FlxG.Height - 45, 44, 45, "b")));
                Actions.Add(Add(ButtonC = CreateButton(FlxG.Width - 44, FlxG.Height - 45, 44, 45, "c")));
                break;

            case FlxActionMode.A_B_X_Y:
                Actions.Add(Add(ButtonY = CreateButton(FlxG.Width - 86, FlxG.Height - 85, 44, 45, "y")));
                Actions.Add(Add(ButtonX = CreateButton(FlxG.Width - 44, FlxG.Height - 85, 44, 45, "x")));
                Actions.Add(Add(ButtonB = CreateButton(FlxG.Width - 86, FlxG.Height - 45, 44, 45, "b")));
                Actions.Add(Add(ButtonA = CreateButton(FlxG.Width - 44, FlxG.Height - 45, 44, 45, "a")));
                break;

            case FlxActionMode.NONE:
                break;
            }
        }