//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 ); }
public void SendPlayerAddPoints( Player player ) { NetOutgoingMessage outmsg = _server.CreateMessage ( ); outmsg = WriteMessageHeaders ( outmsg, NetMessageDataTypes.PlayerAddPoints, player.playerNumber ); outmsg.Write ( player.GetPoints ( ) ); TrySendMessage ( outmsg ); }
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 ); }
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 ); }
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; } } } } } } }
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? }
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 ); }
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; } } }
private static void PlayerRequestsReset( Player player ) { Console.WriteLine ( "Player {0} has been reset.", player.playerNumber ); player.ResetShip ( ); netDataManager.SendPlayerReactivated ( player.playerNumber ); }
private static void PlayerShoot( Player player) { player.ShootBullet ( ); netDataManager.SendPlayerShoot ( player.playerNumber ); }
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 ); }
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 ); }
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 ); } } }
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 ); }
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 ); }