Esempio n. 1
0
        public KeyValuePair <FourDirectionNode, bool> MeaningfulGet(Direction direction)
        {
            FourDirectionNode ret = null;
            bool meaningful       = false;

            switch (direction)
            {
            case Direction.Down:
                ret        = Down == null ? this : Down;
                meaningful = Down != null;
                break;

            case Direction.Up:
                ret        = Up == null ? this : Up;
                meaningful = Up != null;
                break;

            case Direction.Left:
                ret        = Left == null ? this : Left;
                meaningful = Left != null;
                break;

            case Direction.Right:
                ret        = Right == null ? this : Right;
                meaningful = Right != null;
                break;

            case Direction.None:
                ret = this;
                break;
            }
            return(new KeyValuePair <FourDirectionNode, bool>(ret, meaningful));
        }
Esempio n. 2
0
 private Character CharacterFromNode(FourDirectionNode n)
 {
     if (n == _n02)
     {
         return(Character.Blue);
     }
     if (n == _n03)
     {
         return(Character.Red);
     }
     if (n == _n04)
     {
         return(Character.Yellow);
     }
     if (n == _n05)
     {
         return(Character.Green);
     }
     if (n == _n06)
     {
         return(Character.Grey);
     }
     if (n == _n07)
     {
         return(Character.White);
     }
     return(Character.None);
 }
Esempio n. 3
0
 public void Set(FourDirectionNode up, FourDirectionNode down, FourDirectionNode left, FourDirectionNode right)
 {
     Up    = up;
     Down  = down;
     Left  = left;
     Right = right;
 }
Esempio n. 4
0
        private int PlayersOnNode(FourDirectionNode node)
        {
            int r = 0;

            r += _player1SelectionNode == node ? 1 : 0;
            r += _player2SelectionNode == node ? 1 : 0;
            r += _player3SelectionNode == node ? 1 : 0;
            r += _player4SelectionNode == node ? 1 : 0;
            return(r);
        }
Esempio n. 5
0
        private Position GetMarkerPositionFromNode(FourDirectionNode node)
        {
            Position ret = _p00;

            ret = node == _n02 ? _p02 : ret;
            ret = node == _n03 ? _p03 : ret;
            ret = node == _n04 ? _p04 : ret;
            ret = node == _n05 ? _p05 : ret;
            ret = node == _n06 ? _p06 : ret;
            ret = node == _n07 ? _p07 : ret;
            return(ret);
        }
Esempio n. 6
0
        private void DoControllerActions(ControllerState controller)
        {
            if (_keyDebug)
            {
                if (_player1SelectionNode == null)
                {
                    _player1SelectionNode       = _selectionNodes.RandomItem();
                    _player1LastSelectionUpdate = GetMs();
                }
                if (_player2SelectionNode == null)
                {
                    _player2SelectionNode       = _selectionNodes.RandomItem();
                    _player2LastSelectionUpdate = GetMs();
                }
                if (_player3SelectionNode == null)
                {
                    _player3SelectionNode       = _selectionNodes.RandomItem();
                    _player3LastSelectionUpdate = GetMs();
                }
                if (_player4SelectionNode == null)
                {
                    _player4SelectionNode       = _selectionNodes.RandomItem();
                    _player4LastSelectionUpdate = GetMs();
                }
                Direction sent = Direction.None;
                if (Program.Keyboard.WasKeyPressed(Keys.Up))
                {
                    sent = Direction.Up;
                }
                if (Program.Keyboard.WasKeyPressed(Keys.Down))
                {
                    sent = Direction.Down;
                }
                if (Program.Keyboard.WasKeyPressed(Keys.Right))
                {
                    sent = Direction.Right;
                }
                if (Program.Keyboard.WasKeyPressed(Keys.Left))
                {
                    sent = Direction.Left;
                }
                switch (_dbgPlayer)
                {
                case 0:
                    KeyValuePair <FourDirectionNode, bool> p1sn = _player1SelectionNode.MeaningfulGet(sent);
                    _player1SelectionNode = p1sn.Key;
                    if (p1sn.Value)
                    {
                        _player1LastSelectionUpdate = GetMs();
                    }
                    break;

                case 1:
                    KeyValuePair <FourDirectionNode, bool> p2sn = _player2SelectionNode.MeaningfulGet(sent);
                    _player2SelectionNode = p2sn.Key;
                    if (p2sn.Value)
                    {
                        _player2LastSelectionUpdate = GetMs();
                    }
                    break;

                case 2:
                    KeyValuePair <FourDirectionNode, bool> p3sn = _player3SelectionNode.MeaningfulGet(sent);
                    _player3SelectionNode = p3sn.Key;
                    if (p3sn.Value)
                    {
                        _player3LastSelectionUpdate = GetMs();
                    }
                    break;

                case 3:
                    KeyValuePair <FourDirectionNode, bool> p4sn = _player4SelectionNode.MeaningfulGet(sent);
                    _player4SelectionNode = p4sn.Key;
                    if (p4sn.Value)
                    {
                        _player4LastSelectionUpdate = GetMs();
                    }
                    break;
                }
            }
            if (!controller.IsConnected)
            {
                return;
            }
            if (_currentScreen == Screen.CharachterSelect)
            {
                Character chr = Character.None;
                switch (controller.AssociatedPlayer)
                {
                case PlayerIndex.One:
                    chr = _p1Char;
                    // insert create player character here
                    break;

                case PlayerIndex.Two:
                    chr = _p2Char;
                    break;

                case PlayerIndex.Three:
                    chr = _p3Char;
                    break;

                case PlayerIndex.Four:
                    chr = _p4Char;
                    break;
                }
                if (chr != Character.None)
                {
                    if (controller.IsButtonDown(Buttons.B))
                    {
                        Console.WriteLine($"Deselected {chr}");
                        _playersMadeDescision -= 1;
                        switch (controller.AssociatedPlayer)
                        {
                        case PlayerIndex.One:
                            _p1Char = Character.None;
                            break;

                        case PlayerIndex.Two:
                            _p2Char = Character.None;
                            break;

                        case PlayerIndex.Three:
                            _p3Char = Character.None;
                            break;

                        case PlayerIndex.Four:
                            _p4Char = Character.None;
                            break;
                        }
                    }
                }
                else
                {
                    if (controller.WasButtonPressed(Buttons.A))
                    {
                        Character c;
                        switch (controller.AssociatedPlayer)
                        {
                        case PlayerIndex.One:
                            c = CharacterFromNode(_player1SelectionNode);
                            if (!AlreadySelectedCharachter(c))
                            {
                                Console.WriteLine("Selected " + c);
                                _playersMadeDescision += 1;
                                _p1Char           = c;
                                _testp1.Character = c;
                            }
                            break;

                        case PlayerIndex.Two:
                            c = CharacterFromNode(_player2SelectionNode);
                            {
                                Console.WriteLine("Selected " + c);
                                _playersMadeDescision += 1;
                                _p2Char           = c;
                                _testp2.Character = c;
                            }
                            break;

                        case PlayerIndex.Three:
                            c = CharacterFromNode(_player3SelectionNode);
                            {
                                Console.WriteLine("Selected " + c);
                                _playersMadeDescision += 1;
                                _p3Char           = c;
                                _testp3.Character = c;
                            }
                            break;

                        case PlayerIndex.Four:
                            c = CharacterFromNode(_player4SelectionNode);
                            {
                                Console.WriteLine("Selected " + c);
                                _playersMadeDescision += 1;
                                _p4Char           = c;
                                _testp4.Character = c;
                            }
                            break;
                        }
                    }
                    Direction sent = Direction.None;
                    if (controller.LeftThumbstickDirectionChanged(Direction.Right) || controller.WasButtonPressed(Buttons.DPadRight))
                    {
                        sent = Direction.Right;
                    }
                    if (controller.LeftThumbstickDirectionChanged(Direction.Left) || controller.WasButtonPressed(Buttons.DPadLeft))
                    {
                        sent = Direction.Left;
                    }
                    if (controller.LeftThumbstickDirectionChanged(Direction.Up) || controller.WasButtonPressed(Buttons.DPadUp))
                    {
                        sent = Direction.Up;
                    }
                    if (controller.LeftThumbstickDirectionChanged(Direction.Down) || controller.WasButtonPressed(Buttons.DPadDown))
                    {
                        sent = Direction.Down;
                    }
                    switch (controller.AssociatedPlayer)
                    {
                    case PlayerIndex.One:
                        KeyValuePair <FourDirectionNode, bool> p1sn = _player1SelectionNode.MeaningfulGet(sent);
                        _player1SelectionNode = p1sn.Key;
                        if (p1sn.Value)
                        {
                            _player1LastSelectionUpdate = GetMs();
                        }
                        break;

                    case PlayerIndex.Two:
                        KeyValuePair <FourDirectionNode, bool> p2sn = _player2SelectionNode.MeaningfulGet(sent);
                        _player2SelectionNode = p2sn.Key;
                        if (p2sn.Value)
                        {
                            _player2LastSelectionUpdate = GetMs();
                        }
                        break;

                    case PlayerIndex.Three:
                        KeyValuePair <FourDirectionNode, bool> p3sn = _player3SelectionNode.MeaningfulGet(sent);
                        _player3SelectionNode = p3sn.Key;
                        if (p3sn.Value)
                        {
                            _player3LastSelectionUpdate = GetMs();
                        }
                        break;

                    case PlayerIndex.Four:
                        KeyValuePair <FourDirectionNode, bool> p4sn = _player4SelectionNode.MeaningfulGet(sent);
                        _player4SelectionNode = p4sn.Key;
                        if (p4sn.Value)
                        {
                            _player4LastSelectionUpdate = GetMs();
                        }
                        break;
                    }
                }
            }
            if (_currentScreen == Screen.Battle)
            {
                if (controller.WasButtonPressed(Buttons.DPadDown))
                {
                    CameraZoom -= 0.1;
                }
                if (controller.WasButtonPressed(Buttons.DPadUp))
                {
                    CameraZoom += 0.1;
                }
                if (controller.AssociatedPlayer == _testp1.AssociatedPlayer)
                {
                    _testp1.Update(Timing.UpdateTiming.Dt, GetDirectionalLimiters(_testp1), controller);
                }
                else if (controller.AssociatedPlayer == _testp2.AssociatedPlayer)
                {
                    _testp2.Update(Timing.UpdateTiming.Dt, GetDirectionalLimiters(_testp2), controller);
                }
            }
        }
Esempio n. 7
0
        protected override void Update(GameTime gameTime)
        {
            Timing.UpdateTiming.Update();
            AudioController.Update(Timing.UpdateTiming.Dt);

            Program.Keyboard = Keyboard.GetState();
            Program.Mouse    = Mouse.GetState();
            Program.Gt       = gameTime;

            if (Program.Keyboard.IsKeyDown(Keys.Escape))
            {
                Exit();
            }

            List <GameObject>      garbage           = new List <GameObject>();
            List <OwnershipObject> removedOwnerships = new List <OwnershipObject>();

            foreach (GameObject obj in Objects)
            {
                if (obj.Enabled)
                {
                    obj.Update(Timing.UpdateTiming.Dt);
                }
                else
                {
                    garbage.Add(obj);
                }
            }
            foreach (GameObject obj in Overlay)
            {
                if (obj.Enabled)
                {
                    obj.Update(Timing.UpdateTiming.Dt);
                }
                else
                {
                    garbage.Add(obj);
                }
            }
            foreach (GameObject obj in UI)
            {
                if (obj.Enabled)
                {
                    obj.Update(Timing.UpdateTiming.Dt);
                }
                else
                {
                    garbage.Add(obj);
                }
            }

            foreach (GameObject obj in garbage)
            {
                Objects.Remove(obj);
                Overlay.Remove(obj);
                UI.Remove(obj);
            }

            foreach (OwnershipObject ow in Ownerships)
            {
                if (!Objects.Contains(ow.Object) && !UI.Contains(ow.Object) && !Overlay.Contains(ow.Object))
                {
                    removedOwnerships.Add(ow);
                }
            }

            foreach (OwnershipObject ow in removedOwnerships)
            {
                Ownerships.Remove(ow);
            }

            if (_intro.ActionFinished && _currentScreen == Screen.Intro)
            {
                Console.WriteLine("Menu");
                _currentScreen = Screen.Menu;
                _playButton.AutoFitCollider = true;
                _playButton.WrapInCollider(true);
                Objects.Add(_playButton);
                Objects.Remove(_intro);
            }

            if (((_playButton.Clicked && _keyDebug) || WasReleased(Buttons.A)) && _currentScreen == Screen.Menu)
            {
                _currentScreen = Screen.CharachterSelect;
                Console.WriteLine("CharachterSelect");
                Objects.Add(_charSelBg1);
                Objects.Add(_charSelBg2);
                Objects.Add(_charSelFg1);
                if (_keyDebug)
                {
                    Objects.Add(_charSelP1Marker);
                    Objects.Add(_charSelP2Marker);
                    Objects.Add(_charSelP3Marker);
                    Objects.Add(_charSelP4Marker);
                }
                else
                {
                    if (Program.Controller1.IsConnected)
                    {
                        Objects.Add(_charSelP1Marker);
                        _player1SelectionNode = _selectionNodes.RandomItem();
                    }
                    if (Program.Controller2.IsConnected)
                    {
                        Objects.Add(_charSelP2Marker);
                        _player2SelectionNode = _selectionNodes.RandomItem();
                    }
                    if (Program.Controller3.IsConnected)
                    {
                        Objects.Add(_charSelP3Marker);
                        _player3SelectionNode = _selectionNodes.RandomItem();
                    }
                    if (Program.Controller4.IsConnected)
                    {
                        Objects.Add(_charSelP4Marker);
                        _player4SelectionNode = _selectionNodes.RandomItem();
                    }
                }
                Objects.Remove(_playButton);
            }

            if (_currentScreen == Screen.CharachterSelect)
            {
                if (_playersMadeDescision == Program.ConnectedPlayers())
                {
                    _currentScreen = Screen.Battle;
                    Console.WriteLine("Battle");
                    Objects.Remove(_charSelBg1);
                    Objects.Remove(_charSelBg2);
                    Objects.Remove(_charSelFg1);
                    Objects.Remove(_charSelP1Marker);
                    Objects.Remove(_charSelP2Marker);
                    Objects.Remove(_charSelP3Marker);
                    Objects.Remove(_charSelP4Marker);
                    BattleStart();
                }
                if (Program.Controller1.Connected())
                {
                    Objects.Add(_charSelP1Marker);
                    _player1SelectionNode       = _selectionNodes.RandomItem();
                    _player1LastSelectionUpdate = GetMs();
                }
                if (Program.Controller2.Connected())
                {
                    Objects.Add(_charSelP2Marker);
                    _player2SelectionNode       = _selectionNodes.RandomItem();
                    _player2LastSelectionUpdate = GetMs();
                }
                if (Program.Controller3.Connected())
                {
                    Objects.Add(_charSelP3Marker);
                    _player3SelectionNode       = _selectionNodes.RandomItem();
                    _player3LastSelectionUpdate = GetMs();
                }
                if (Program.Controller4.Connected())
                {
                    Objects.Add(_charSelP4Marker);
                    _player4SelectionNode       = _selectionNodes.RandomItem();
                    _player4LastSelectionUpdate = GetMs();
                }

                if (Program.Controller1.Disconnected())
                {
                    Objects.Remove(_charSelP1Marker);
                    _player1SelectionNode = null;
                }
                if (Program.Controller2.Disconnected())
                {
                    Objects.Remove(_charSelP2Marker);
                    _player2SelectionNode = null;
                }
                if (Program.Controller3.Disconnected())
                {
                    Objects.Remove(_charSelP3Marker);
                    _player3SelectionNode = null;
                }
                if (Program.Controller4.Disconnected())
                {
                    Objects.Remove(_charSelP4Marker);
                    _player4SelectionNode = null;
                }

                if (_keyDebug && Program.Keyboard.WasKeyPressed(Keys.Tab))
                {
                    _dbgPlayer += 1;
                    _dbgPlayer %= 4;
                    Console.WriteLine($"Current Player : {_dbgPlayer}");
                }
                if ((Program.Controller1.IsConnected || _keyDebug) && _player1SelectionNode != null)
                {
                    _charSelP1Marker.Position = GetMarkerPositionFromNode(_player1SelectionNode);
                }
                if ((Program.Controller2.IsConnected || _keyDebug) && _player2SelectionNode != null)
                {
                    _charSelP2Marker.Position = GetMarkerPositionFromNode(_player2SelectionNode);
                }
                if ((Program.Controller3.IsConnected || _keyDebug) && _player3SelectionNode != null)
                {
                    _charSelP3Marker.Position = GetMarkerPositionFromNode(_player3SelectionNode);
                }
                if ((Program.Controller4.IsConnected || _keyDebug) && _player4SelectionNode != null)
                {
                    _charSelP4Marker.Position = GetMarkerPositionFromNode(_player4SelectionNode);
                }
                _n02l = GetEquivalentPlayerNodesInLastAccessOrder(_n02);
                _n03l = GetEquivalentPlayerNodesInLastAccessOrder(_n03);
                _n04l = GetEquivalentPlayerNodesInLastAccessOrder(_n04);
                _n05l = GetEquivalentPlayerNodesInLastAccessOrder(_n05);
                _n06l = GetEquivalentPlayerNodesInLastAccessOrder(_n06);
                _n07l = GetEquivalentPlayerNodesInLastAccessOrder(_n07);

                List <List <PlayerNodeDataContainer> > nds = new List <List <PlayerNodeDataContainer> >();

                nds.Add(_n02l);
                nds.Add(_n03l);
                nds.Add(_n04l);
                nds.Add(_n05l);
                nds.Add(_n06l);
                nds.Add(_n07l);
                foreach (List <PlayerNodeDataContainer> nl in nds)
                {
                    if (nl.Count > 0)
                    {
                        int idp1 = nl.IndexOf(PlayerIndex.One);
                        int idp2 = nl.IndexOf(PlayerIndex.Two);
                        int idp3 = nl.IndexOf(PlayerIndex.Three);
                        int idp4 = nl.IndexOf(PlayerIndex.Four);
                        //Console.WriteLine($"{idp1}\t{idp2}\t{idp3}\t{idp4}");
                        Position p1ps = _charSelP1Marker.Position;
                        Position p2ps = _charSelP2Marker.Position;
                        Position p3ps = _charSelP3Marker.Position;
                        Position p4ps = _charSelP4Marker.Position;
                        _charSelP1Marker.Position = idp1 != -1 ? new Position(p1ps.X - (idp1 * 48), p1ps.Y) : p1ps;
                        _charSelP2Marker.Position = idp2 != -1 ? new Position(p2ps.X - (idp2 * 48), p2ps.Y) : p2ps;
                        _charSelP3Marker.Position = idp3 != -1 ? new Position(p3ps.X - (idp3 * 48), p3ps.Y) : p3ps;
                        _charSelP4Marker.Position = idp4 != -1 ? new Position(p4ps.X - (idp4 * 48), p4ps.Y) : p4ps;
                    }
                }
            }

            if (_currentScreen != Screen.Intro)
            {
                if (_keyDebug)
                {
                    DoControllerActions(Program.Controller1);
                }
                else
                {
                    DoControllerActions(Program.Controller1);
                    DoControllerActions(Program.Controller2);
                    DoControllerActions(Program.Controller3);
                    DoControllerActions(Program.Controller4);
                }
            }

            if (_currentScreen == Screen.Battle)
            {
                Camera = new Position(400 - _testp1.Position.X, 300 - _testp1.Position.Y);
            }

            _prev_player1SelectionNode = _player1SelectionNode;
            _prev_player2SelectionNode = _player2SelectionNode;
            _prev_player3SelectionNode = _player3SelectionNode;
            _prev_player4SelectionNode = _player4SelectionNode;
            Program.Controller1.UpdateState();
            Program.Controller2.UpdateState();
            Program.Controller3.UpdateState();
            Program.Controller4.UpdateState();
            Program.LastKeyboard = Program.Keyboard;
            base.Update(gameTime);
        }
Esempio n. 8
0
        private List <PlayerNodeDataContainer> GetEquivalentPlayerNodesInLastAccessOrder(FourDirectionNode node)
        {
            List <PlayerNodeDataContainer> ret = new List <PlayerNodeDataContainer>();

            if (_player1SelectionNode == node)
            {
                ret.Add(new PlayerNodeDataContainer(_player1LastSelectionUpdate, PlayerIndex.One));
            }
            if (_player2SelectionNode == node)
            {
                ret.Add(new PlayerNodeDataContainer(_player2LastSelectionUpdate, PlayerIndex.Two));
            }
            if (_player3SelectionNode == node)
            {
                ret.Add(new PlayerNodeDataContainer(_player3LastSelectionUpdate, PlayerIndex.Three));
            }
            if (_player4SelectionNode == node)
            {
                ret.Add(new PlayerNodeDataContainer(_player4LastSelectionUpdate, PlayerIndex.Four));
            }
            if (ret.Count > 0)
            {
                ret.OrderBy(f => f.LastSelectionUpdate);
                ret.Reverse();
            }
            return(ret);
        }