|
@@ -18,29 +18,17 @@ namespace NetRumble
|
|
/// </summary>
|
|
/// </summary>
|
|
public class LobbyScreen : MenuScreen, IDisposable
|
|
public class LobbyScreen : MenuScreen, IDisposable
|
|
{
|
|
{
|
|
-
|
|
|
|
-
|
|
|
|
/// <summary>
|
|
/// <summary>
|
|
/// The instructions shown to the player at the bottom of the lobby screen.
|
|
/// The instructions shown to the player at the bottom of the lobby screen.
|
|
/// </summary>
|
|
/// </summary>
|
|
- const string instructions =
|
|
|
|
|
|
+ const string instructions =
|
|
"Press X to mark/unmark ready, LB/RB to toggle color, LT/RT to toggle ship";
|
|
"Press X to mark/unmark ready, LB/RB to toggle color, LT/RT to toggle ship";
|
|
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
/// <summary>
|
|
/// <summary>
|
|
/// The primary object for this game.
|
|
/// The primary object for this game.
|
|
/// </summary>
|
|
/// </summary>
|
|
private World world;
|
|
private World world;
|
|
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
/// <summary>
|
|
/// <summary>
|
|
/// The network session for this game.
|
|
/// The network session for this game.
|
|
/// </summary>
|
|
/// </summary>
|
|
@@ -50,7 +38,7 @@ namespace NetRumble
|
|
/// The packet writer used to send data from this screen.
|
|
/// The packet writer used to send data from this screen.
|
|
/// </summary>
|
|
/// </summary>
|
|
private PacketWriter packetWriter = new PacketWriter();
|
|
private PacketWriter packetWriter = new PacketWriter();
|
|
-
|
|
|
|
|
|
+
|
|
/// <summary>
|
|
/// <summary>
|
|
/// Event handler for the session-ended event.
|
|
/// Event handler for the session-ended event.
|
|
/// </summary>
|
|
/// </summary>
|
|
@@ -66,11 +54,6 @@ namespace NetRumble
|
|
/// </summary>
|
|
/// </summary>
|
|
EventHandler<GamerJoinedEventArgs> gamerJoinedHandler;
|
|
EventHandler<GamerJoinedEventArgs> gamerJoinedHandler;
|
|
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
/// <summary>
|
|
/// <summary>
|
|
/// Constructs a new LobbyScreen object.
|
|
/// Constructs a new LobbyScreen object.
|
|
/// </summary>
|
|
/// </summary>
|
|
@@ -100,7 +83,6 @@ namespace NetRumble
|
|
networkSession_SessionEnded);
|
|
networkSession_SessionEnded);
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
|
|
/// <summary>
|
|
/// <summary>
|
|
/// Load graphics content for the game.
|
|
/// Load graphics content for the game.
|
|
/// </summary>
|
|
/// </summary>
|
|
@@ -109,7 +91,7 @@ namespace NetRumble
|
|
base.LoadContent();
|
|
base.LoadContent();
|
|
|
|
|
|
// create the world object
|
|
// create the world object
|
|
- world = new World(ScreenManager.GraphicsDevice, ScreenManager.Content,
|
|
|
|
|
|
+ world = new World(ScreenManager.GraphicsDevice, ScreenManager.Content,
|
|
networkSession);
|
|
networkSession);
|
|
|
|
|
|
// set the networking events
|
|
// set the networking events
|
|
@@ -118,11 +100,6 @@ namespace NetRumble
|
|
networkSession.SessionEnded += sessionEndedHandler;
|
|
networkSession.SessionEnded += sessionEndedHandler;
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
/// <summary>
|
|
/// <summary>
|
|
/// Updates the lobby. This method checks the GameScreen.IsActive
|
|
/// Updates the lobby. This method checks the GameScreen.IsActive
|
|
/// property, so the game will stop updating when the pause menu is active,
|
|
/// property, so the game will stop updating when the pause menu is active,
|
|
@@ -201,7 +178,7 @@ namespace NetRumble
|
|
// update the menu entry text
|
|
// update the menu entry text
|
|
if (otherScreenHasFocus == false)
|
|
if (otherScreenHasFocus == false)
|
|
{
|
|
{
|
|
- if ((networkSession.LocalGamers.Count > 0) &&
|
|
|
|
|
|
+ if ((networkSession.LocalGamers.Count > 0) &&
|
|
(networkSession.SessionState == NetworkSessionState.Lobby))
|
|
(networkSession.SessionState == NetworkSessionState.Lobby))
|
|
{
|
|
{
|
|
if (!networkSession.LocalGamers[0].IsReady)
|
|
if (!networkSession.LocalGamers[0].IsReady)
|
|
@@ -227,10 +204,10 @@ namespace NetRumble
|
|
MenuEntries[0] = "Game starting...";
|
|
MenuEntries[0] = "Game starting...";
|
|
}
|
|
}
|
|
// if the game is playing and the world is initialized, then start up
|
|
// if the game is playing and the world is initialized, then start up
|
|
- if ((networkSession.SessionState == NetworkSessionState.Playing) &&
|
|
|
|
|
|
+ if ((networkSession.SessionState == NetworkSessionState.Playing) &&
|
|
(world != null) && world.Initialized)
|
|
(world != null) && world.Initialized)
|
|
{
|
|
{
|
|
- GameplayScreen gameplayScreen =
|
|
|
|
|
|
+ GameplayScreen gameplayScreen =
|
|
new GameplayScreen(networkSession, world);
|
|
new GameplayScreen(networkSession, world);
|
|
gameplayScreen.ScreenManager = this.ScreenManager;
|
|
gameplayScreen.ScreenManager = this.ScreenManager;
|
|
ScreenManager.AddScreen(gameplayScreen);
|
|
ScreenManager.AddScreen(gameplayScreen);
|
|
@@ -240,7 +217,6 @@ namespace NetRumble
|
|
base.Update(gameTime, otherScreenHasFocus, coveredByOtherScreen);
|
|
base.Update(gameTime, otherScreenHasFocus, coveredByOtherScreen);
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
|
|
/// <summary>
|
|
/// <summary>
|
|
/// Lets the game respond to player input. Unlike the Update method,
|
|
/// Lets the game respond to player input. Unlike the Update method,
|
|
/// this will only be called when the gameplay screen is active.
|
|
/// this will only be called when the gameplay screen is active.
|
|
@@ -258,7 +234,7 @@ namespace NetRumble
|
|
// update the ready state
|
|
// update the ready state
|
|
if (input.MarkReady)
|
|
if (input.MarkReady)
|
|
{
|
|
{
|
|
- networkSession.LocalGamers[0].IsReady =
|
|
|
|
|
|
+ networkSession.LocalGamers[0].IsReady =
|
|
!networkSession.LocalGamers[0].IsReady;
|
|
!networkSession.LocalGamers[0].IsReady;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -281,7 +257,7 @@ namespace NetRumble
|
|
}
|
|
}
|
|
if (input.ShipModelChangeUp)
|
|
if (input.ShipModelChangeUp)
|
|
{
|
|
{
|
|
- playerData.ShipVariation =
|
|
|
|
|
|
+ playerData.ShipVariation =
|
|
(byte)((playerData.ShipVariation + 1) % 4);
|
|
(byte)((playerData.ShipVariation + 1) % 4);
|
|
playerDataChanged = true;
|
|
playerDataChanged = true;
|
|
}
|
|
}
|
|
@@ -302,7 +278,8 @@ namespace NetRumble
|
|
{
|
|
{
|
|
packetWriter.Write((int)World.PacketTypes.PlayerData);
|
|
packetWriter.Write((int)World.PacketTypes.PlayerData);
|
|
playerData.Serialize(packetWriter);
|
|
playerData.Serialize(packetWriter);
|
|
- networkSession.LocalGamers[0].SendData(packetWriter,
|
|
|
|
|
|
+
|
|
|
|
+ networkSession.LocalGamers[0].SendData(packetWriter,
|
|
SendDataOptions.ReliableInOrder);
|
|
SendDataOptions.ReliableInOrder);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -311,13 +288,11 @@ namespace NetRumble
|
|
base.HandleInput(input);
|
|
base.HandleInput(input);
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
|
|
/// <summary>
|
|
/// <summary>
|
|
/// Responds to user menu selections.
|
|
/// Responds to user menu selections.
|
|
/// </summary>
|
|
/// </summary>
|
|
protected override void OnSelectEntry(int entryIndex) { }
|
|
protected override void OnSelectEntry(int entryIndex) { }
|
|
|
|
|
|
-
|
|
|
|
/// <summary>
|
|
/// <summary>
|
|
/// Force the end of a network session so that a new one can be joined.
|
|
/// Force the end of a network session so that a new one can be joined.
|
|
/// </summary>
|
|
/// </summary>
|
|
@@ -330,7 +305,6 @@ namespace NetRumble
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
|
|
/// <summary>
|
|
/// <summary>
|
|
/// Exit this screen.
|
|
/// Exit this screen.
|
|
/// </summary>
|
|
/// </summary>
|
|
@@ -345,7 +319,6 @@ namespace NetRumble
|
|
base.ExitScreen();
|
|
base.ExitScreen();
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
|
|
/// <summary>
|
|
/// <summary>
|
|
/// Screen-specific update to gamer rich presence.
|
|
/// Screen-specific update to gamer rich presence.
|
|
/// </summary>
|
|
/// </summary>
|
|
@@ -371,10 +344,6 @@ namespace NetRumble
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
/// <summary>
|
|
/// <summary>
|
|
/// Draw the lobby screen.
|
|
/// Draw the lobby screen.
|
|
/// </summary>
|
|
/// </summary>
|
|
@@ -384,17 +353,17 @@ namespace NetRumble
|
|
// draw in four columns
|
|
// draw in four columns
|
|
Vector2[] columnPositions = new Vector2[4];
|
|
Vector2[] columnPositions = new Vector2[4];
|
|
columnPositions[0] = new Vector2(
|
|
columnPositions[0] = new Vector2(
|
|
- ScreenManager.GraphicsDevice.Viewport.Width * 0.2f,
|
|
|
|
- ScreenManager.GraphicsDevice.Viewport.Height * 0.70f);
|
|
|
|
|
|
+ ScreenManager.BASE_BUFFER_WIDTH * 0.2f,
|
|
|
|
+ ScreenManager.BASE_BUFFER_HEIGHT * 0.70f);
|
|
columnPositions[1] = new Vector2(
|
|
columnPositions[1] = new Vector2(
|
|
- ScreenManager.GraphicsDevice.Viewport.Width * 0.4f,
|
|
|
|
- ScreenManager.GraphicsDevice.Viewport.Height * 0.70f);
|
|
|
|
|
|
+ ScreenManager.BASE_BUFFER_WIDTH * 0.4f,
|
|
|
|
+ ScreenManager.BASE_BUFFER_HEIGHT * 0.70f);
|
|
columnPositions[2] = new Vector2(
|
|
columnPositions[2] = new Vector2(
|
|
- ScreenManager.GraphicsDevice.Viewport.Width * 0.6f,
|
|
|
|
- ScreenManager.GraphicsDevice.Viewport.Height * 0.70f);
|
|
|
|
|
|
+ ScreenManager.BASE_BUFFER_WIDTH * 0.6f,
|
|
|
|
+ ScreenManager.BASE_BUFFER_HEIGHT * 0.70f);
|
|
columnPositions[3] = new Vector2(
|
|
columnPositions[3] = new Vector2(
|
|
- ScreenManager.GraphicsDevice.Viewport.Width * 0.8f,
|
|
|
|
- ScreenManager.GraphicsDevice.Viewport.Height * 0.70f);
|
|
|
|
|
|
+ ScreenManager.BASE_BUFFER_WIDTH * 0.8f,
|
|
|
|
+ ScreenManager.BASE_BUFFER_HEIGHT * 0.70f);
|
|
|
|
|
|
ScreenManager.SpriteBatch.Begin();
|
|
ScreenManager.SpriteBatch.Begin();
|
|
|
|
|
|
@@ -403,18 +372,18 @@ namespace NetRumble
|
|
{
|
|
{
|
|
for (int i = 0; i < networkSession.AllGamers.Count; i++)
|
|
for (int i = 0; i < networkSession.AllGamers.Count; i++)
|
|
{
|
|
{
|
|
- world.DrawPlayerData((float)gameTime.TotalGameTime.TotalSeconds,
|
|
|
|
- networkSession.AllGamers[i], columnPositions[i % 4],
|
|
|
|
|
|
+ world.DrawPlayerData((float)gameTime.TotalGameTime.TotalSeconds,
|
|
|
|
+ networkSession.AllGamers[i], columnPositions[i % 4],
|
|
ScreenManager.SpriteBatch, true);
|
|
ScreenManager.SpriteBatch, true);
|
|
- columnPositions[i % 4].Y +=
|
|
|
|
- ScreenManager.GraphicsDevice.Viewport.Height * 0.03f;
|
|
|
|
|
|
+ columnPositions[i % 4].Y +=
|
|
|
|
+ ScreenManager.BASE_BUFFER_HEIGHT * 0.03f;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
// draw the instructions
|
|
// draw the instructions
|
|
- ScreenManager.SpriteBatch.DrawString(ScreenManager.Font, instructions,
|
|
|
|
- new Vector2(ScreenManager.TitleSafeArea.X,
|
|
|
|
- ScreenManager.TitleSafeArea.Y + ScreenManager.TitleSafeArea.Height -
|
|
|
|
|
|
+ ScreenManager.SpriteBatch.DrawString(ScreenManager.Font, instructions,
|
|
|
|
+ new Vector2(ScreenManager.TitleSafeArea.X,
|
|
|
|
+ ScreenManager.TitleSafeArea.Y + ScreenManager.TitleSafeArea.Height -
|
|
ScreenManager.Font.LineSpacing), Color.White);
|
|
ScreenManager.Font.LineSpacing), Color.White);
|
|
|
|
|
|
ScreenManager.SpriteBatch.End();
|
|
ScreenManager.SpriteBatch.End();
|
|
@@ -422,8 +391,6 @@ namespace NetRumble
|
|
base.Draw(gameTime);
|
|
base.Draw(gameTime);
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
|
|
-
|
|
|
|
/// <summary>
|
|
/// <summary>
|
|
/// When the user cancels the main menu, ask if they want to exit the sample.
|
|
/// When the user cancels the main menu, ask if they want to exit the sample.
|
|
/// </summary>
|
|
/// </summary>
|
|
@@ -445,11 +412,6 @@ namespace NetRumble
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
/// <summary>
|
|
/// <summary>
|
|
/// Handle the end of the network session.
|
|
/// Handle the end of the network session.
|
|
/// </summary>
|
|
/// </summary>
|
|
@@ -471,7 +433,6 @@ namespace NetRumble
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
|
|
/// <summary>
|
|
/// <summary>
|
|
/// Handle the start of the game session.
|
|
/// Handle the start of the game session.
|
|
/// </summary>
|
|
/// </summary>
|
|
@@ -483,8 +444,7 @@ namespace NetRumble
|
|
world.GenerateWorld();
|
|
world.GenerateWorld();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-
|
|
|
|
-
|
|
|
|
|
|
+
|
|
/// <summary>
|
|
/// <summary>
|
|
/// Handle a new player joining the session.
|
|
/// Handle a new player joining the session.
|
|
/// </summary>
|
|
/// </summary>
|
|
@@ -510,17 +470,13 @@ namespace NetRumble
|
|
{
|
|
{
|
|
packetWriter.Write((int)World.PacketTypes.PlayerData);
|
|
packetWriter.Write((int)World.PacketTypes.PlayerData);
|
|
playerData.Serialize(packetWriter);
|
|
playerData.Serialize(packetWriter);
|
|
- networkSession.LocalGamers[0].SendData(packetWriter,
|
|
|
|
|
|
+
|
|
|
|
+ networkSession.LocalGamers[0].SendData(packetWriter,
|
|
SendDataOptions.ReliableInOrder, e.Gamer);
|
|
SendDataOptions.ReliableInOrder, e.Gamer);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
/// <summary>
|
|
/// <summary>
|
|
/// Finalizes the LobbyScreen object, calls Dispose(false)
|
|
/// Finalizes the LobbyScreen object, calls Dispose(false)
|
|
/// </summary>
|
|
/// </summary>
|
|
@@ -529,7 +485,6 @@ namespace NetRumble
|
|
Dispose(false);
|
|
Dispose(false);
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
|
|
/// <summary>
|
|
/// <summary>
|
|
/// Disposes the LobbyScreen object.
|
|
/// Disposes the LobbyScreen object.
|
|
/// </summary>
|
|
/// </summary>
|
|
@@ -539,7 +494,6 @@ namespace NetRumble
|
|
GC.SuppressFinalize(this);
|
|
GC.SuppressFinalize(this);
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
|
|
/// <summary>
|
|
/// <summary>
|
|
/// Disposes this object.
|
|
/// Disposes this object.
|
|
/// </summary>
|
|
/// </summary>
|
|
@@ -565,7 +519,5 @@ namespace NetRumble
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-
|
|
|
|
-
|
|
|
|
}
|
|
}
|
|
-}
|
|
|
|
|
|
+}
|