Ejemplo n.º 1
0
 //Draws screen prompts and messages
 public void Draw( SpriteBatch theSpriteBatch, Player player )
 {
     //Score
     theSpriteBatch.DrawString ( _lucidaConsole, "Score: " + player.GetPoints ( ).ToString ( ), new Vector2 ( 10, 10 ), Color.White );
     //Location
     theSpriteBatch.DrawString ( _lucidaConsole, "X: " + ( int ) player.ship.localPosition.X, new Vector2 ( 10, 30 ), Color.White );
     theSpriteBatch.DrawString ( _lucidaConsole, "Y: " + ( int ) player.ship.localPosition.Y, new Vector2 ( 10, 50 ), Color.White );
 }
Ejemplo n.º 2
0
        public void SendPlayerAddPoints( Player player )
        {
            NetOutgoingMessage outmsg = _server.CreateMessage ( );

            outmsg = WriteMessageHeaders ( outmsg, NetMessageDataTypes.PlayerAddPoints, player.playerNumber );
            outmsg.Write ( player.GetPoints ( ) );

            TrySendMessage ( outmsg );
        }
Ejemplo n.º 3
0
        public void SendNewConnectionsLocalPlayer( NetConnection playerConnection, Player player )
        {
            NetOutgoingMessage outmsg = _server.CreateMessage ( );

            outmsg = WriteMessageHeaders ( outmsg, NetMessageDataTypes.NewLocalPlayer, player.playerNumber );
            outmsg.Write ( player.Name );
            outmsg.Write ( player.shipColor );

            TrySendMessage ( outmsg, playerConnection );
        }
Ejemplo n.º 4
0
        public void SendPlayerInfo(NetConnection recipientConnection, Player requestedPlayer )
        {
            NetOutgoingMessage outmsg = _server.CreateMessage ( );

            outmsg.Write ( ( byte ) NetMessageDataTypes.RequestPlayerInfo );
            outmsg.Write ( requestedPlayer.playerNumber );
            outmsg.Write ( requestedPlayer.Name );
            outmsg.Write ( requestedPlayer.shipColor );

            TrySendMessage ( outmsg );
        }
Ejemplo n.º 5
0
        private static void CheckBulletIntersections(Player shooter)
        {
            for ( int i=0; i < shooter.bullets.Length; i++ )
            {
                if ( shooter.bullets[i].isActive )
                {
                    //should be a while loop
                    foreach ( Player otherPlayer in currentPlayers.Values )
                    {
                        if ( shooter.playerNumber != otherPlayer.playerNumber )
                        {
                            if ( otherPlayer.ship.isActive )
                            {
                                if ( shooter.bullets[i].BoundingBox.Intersects ( otherPlayer.ship.BoundingBox ) )
                                {
                                    Console.WriteLine ( "Player {0} killed Player {1}", shooter.playerNumber, otherPlayer.playerNumber );

                                    otherPlayer.ship.isActive = false;
                                    shooter.bullets[i].isActive = false;
                                    otherPlayer.WasDestroyed = true;

                                    //Player destroyed message
                                    netDataManager.SendPlayerDestroyed ( otherPlayer.playerNumber, shooter.playerNumber );

                                    //Player score message
                                    shooter.AddPoints ( 1000 ); //add this to queue
                                    netDataManager.SendPlayerAddPoints ( shooter );

                                    break;
                                }
                            }
                        }
                    }
                }
            }
        }
Ejemplo n.º 6
0
        public void WriteNewConnectionsOtherPlayer( Player player )
        {
            NetOutgoingMessage outmsg = _server.CreateMessage ( );
            outmsg = WriteMessageHeaders ( outmsg, NetMessageDataTypes.NewOtherPlayer, player.playerNumber );
            outmsg.Write ( player.Name );
            outmsg.Write ( player.shipColor );

            //send?
        }
Ejemplo n.º 7
0
        public void SendPlayerShipPositionUpdate( Player player )
        {
            NetOutgoingMessage outmsg = _server.CreateMessage ( );

            outmsg = WriteMessageHeaders ( outmsg, NetMessageDataTypes.PlayerShipPosition, player.playerNumber );
            outmsg.Write ( player.ship.localPosition );
            outmsg.Write ( player.ship.localRotationAngle );
            outmsg.Write ( player.ship.localDirection );
            outmsg.Write ( player.ship.localVelocity );

            TrySendMessage ( outmsg );
        }
Ejemplo n.º 8
0
 private static void UpdatePlayerInput( Player player, List<PlayerInputType> playerInputs )
 {
     PlayerInputType[] inputs = playerInputs.ToArray ( );
     for ( int i = 0; i < inputs.Length; i++ )
     {
         switch ( inputs[i] )
         {
             case PlayerInputType.TurnLeft:
                 player.ship.TurnLeft ( );
                 break;
             case PlayerInputType.TurnRight:
                 player.ship.TurnRight ( );
                 break;
             case PlayerInputType.MoveForward:
                 player.ship.MoveForward ( );
                 break;
             case PlayerInputType.Shoot:
                 PlayerShoot ( player);
                 break;
             case PlayerInputType.ResetShip:
                 PlayerRequestsReset ( player );
                 break;
             case PlayerInputType.AfterBurner:
                 player.AfterBurner ( );
                 break;
         }
     }
 }
Ejemplo n.º 9
0
 private static void PlayerRequestsReset( Player player )
 {
     Console.WriteLine ( "Player {0} has been reset.", player.playerNumber );
     player.ResetShip ( );
     netDataManager.SendPlayerReactivated ( player.playerNumber );
 }
Ejemplo n.º 10
0
 private static void PlayerShoot( Player player)
 {
     player.ShootBullet ( );
     netDataManager.SendPlayerShoot ( player.playerNumber );
 }
Ejemplo n.º 11
0
        private static void PlayerConnected(NetIncomingMessage msg)
        {
            //console messages.
            Console.WriteLine ( msg.SenderEndPoint.Address.ToString ( ) + " joined." );

            numberOfConnectedPlayers++;
            byte playerNumber = numberOfConnectedPlayers;

            NetIncomingMessage clientHailMsg = msg.SenderConnection.RemoteHailMessage;
            string playerName = clientHailMsg.ReadString ( );
            if ( playerName == "" )
            {
                playerName = "Player " + playerNumber;
            }
            string playerShipColor = clientHailMsg.ReadString ( );

            Player newPlayer = new Player(playerNumber,playerName,playerShipColor);
            newPlayer.ship.localPosition.X = GameConstants.PlayerStartingX;
            newPlayer.ship.localPosition.Y = GameConstants.PlayerStartingY;
            currentPlayers.Add ( newPlayer.playerNumber, newPlayer );
            server.GetConnection ( msg.SenderEndPoint ).Tag = newPlayer;

            //Send the connection their player information
            netDataManager.SendNewConnectionsLocalPlayer (msg.SenderConnection, newPlayer );
            //server.Recycle ( msg );
        }
Ejemplo n.º 12
0
        private static void GameOver( )
        {
            Player[] playersCopy = new Player[currentPlayers.Count];
            currentPlayers.Values.CopyTo(playersCopy,0);

            List <Player> results = playersCopy.OrderByDescending ( player => player.GetPoints ( ) ).ToList<Player>();

            netDataManager.SendRoundEndMessage ( results );
        }
Ejemplo n.º 13
0
        private void CreateOtherPlayer( NetIncomingMessage msg, byte playerNumber )
        {
            if ( localPlayer != null && playerNumber != localPlayer.playerNumber )
            {
                //check to see if we have this player info
                if ( GetPlayerByPlayerNumber ( playerNumber ) == null )
                {
                    string name = msg.ReadString ( );
                    string color = msg.ReadString ( );
                    Player otherPlayer = new Player ( playerNumber, name, color );
                    otherPlayers.Add ( playerNumber, otherPlayer );

                    _client.Recycle ( msg );
                }
            }
        }
Ejemplo n.º 14
0
        private void CreateLocalPlayer( NetIncomingMessage msg, byte playerNumber )
        {
            string name = msg.ReadString ( );
            string color = msg.ReadString ( );
            localPlayer = new Player ( playerNumber, name, color );
            localPlayer.ship.localPosition = new Vector2 ( GameConstants.PlayerStartingX, GameConstants.PlayerStartingY );

            _client.Recycle ( msg );
        }
Ejemplo n.º 15
0
 public void SendMousePosition( Player player, Vector2 mouseWorldPosition )
 {
     NetOutgoingMessage outmsg = _client.CreateMessage ( );
     outmsg.Write ( ( byte ) NetMessageDataTypes.PlayerMousePosition );
     outmsg.Write ( player.playerNumber );
     outmsg.Write ( mouseWorldPosition );
     _client.SendMessage ( outmsg, NetDeliveryMethod.Unreliable );
 }