/// <summary> /// Changes the currently selected ship. /// </summary> /// <param name="info">Info of the player changing ship selection.</param> /// <param name="left">True if selecting the ship to the left.</param> async void ShiftSelection(SelectionDrawInfo info, bool left) { if (info.ShiftingSelection) { return; } SoundManager.PlaySound("Select01"); info.ShiftingSelection = true; // Calcula próxima nave, de acordo com direção pressionada var oldOption = info == _p1Info ? _result.Player1Selection : _result.Player2Selection; var nextOption = _ships[(_ships.IndexOf(oldOption) + (left ? -1 : 1)).Mod(_ships.Count)]; // Troca a nave selecionada pelo jogador if (info == _p1Info) { _result.Player1Selection = nextOption; } else { _result.Player2Selection = nextOption; } // Realiza animação de transição await TaskEx.WhenAll( // Anima zoom in, de nave selecionada FloatAnimation(300, 1, 2, v => info.IconScales[nextOption] = new Vector2(v), easingFunction : Sinusoidal.EaseOut), // Anima zoom out, de nave desselecionada FloatAnimation(100, 2, 1, v => info.IconScales[oldOption] = new Vector2(v)), // Anima deslocamento para direita/esquerda FloatAnimation(100, _spacing *(left ? -1 : +1), 0, v => info.DrawShift = (int)v) ); info.ShiftingSelection = false; }
/// <summary> /// Checks the player input and execute its actions. /// </summary> /// <param name="info">Player info.</param> /// <param name="input">Player input.</param> void CheckPlayerInput(SelectionDrawInfo info, PlayerInput input) { if (input.Right) { ShiftSelection(info, left: false); } else if (input.Left) { ShiftSelection(info, left: true); } }
public GamePlaySetup(MainGame game) : base(game) { _ships = LoadShips().ToList(); _spacing = GraphicsDevice.PresentationParameters.BackBufferWidth / Math.Min(_ships.Count, MaxVisibleShips); _result = new Result { Player1Selection = _ships[0], Player2Selection = _ships[_ships.Count / 2] }; _p1Info = new SelectionDrawInfo { IconScales = GetDefaultScales(_result.Player1Selection) }; _p2Info = new SelectionDrawInfo { IconScales = GetDefaultScales(_result.Player2Selection) }; }
/// <summary> /// Draw the ship selection for the specified player at the specified position. /// </summary> /// <param name="selection">Current player selection.</param> /// <param name="drawInfo">Current player draw info.</param> /// <param name="y">The y position on the screen where the selection will be drawn.</param> void DrawPlayerSelection(ShipDescription selection, SelectionDrawInfo drawInfo, int y) { SpriteBatch.DrawString(_bigFont, selection.Name, new Vector2(Game.Window.ClientBounds.Width / 2, y), new Color(Color.White, _descriptionOpacity), HorizontalAlign.Center); int sideShips = Math.Min(_ships.Count, MaxVisibleShips) - 2; int width = (sideShips * 2 + 1) * _spacing; int x = (Game.Window.ClientBounds.Width - width) / 2 + _spacing / 2; var option = _ships.IndexOf(selection); for (int i = option - sideShips; i <= option + sideShips; i++, x += _spacing) { var ship = _ships[i.Mod(_ships.Count)]; SpriteBatch.Draw(ship.Texture, position: new Vector2(x + drawInfo.DrawShift, y + 110), scale: drawInfo.IconScales[ship], origin: new Vector2(ship.Texture.Width / 2, ship.Texture.Height / 2)); } #region Stats int statsY = y + 180; var leftStats = new Dictionary <string, object> { { "Special", selection.SpecialAttack.Name }, { "Speed", selection.MaxSpeed } }; var rightStats = new Dictionary <string, object> { { "Mass", selection.Mass }, { "Fuel Duration", selection.FuelDuration.ToString("%s") }, }; var leftStatsString = string.Join("\r\n", leftStats.Select(k => k.Key + ": " + k.Value)); var rightStatsString = string.Join("\r\n", rightStats.Select(k => k.Key + ": " + k.Value)); var statsColor = new Color(Color.Gray, 0.6f); SpriteBatch.DrawString(_smallFont, leftStatsString, new Vector2(_statsX + 40, statsY), statsColor); SpriteBatch.DrawString(_smallFont, rightStatsString, new Vector2(_statsX + 420, statsY), statsColor); #endregion }