|
|
4 months ago | |
|---|---|---|
| .. | ||
| .vscode | 4 months ago | |
| Core | 4 months ago | |
| Peer2PeerMasterServer | 4 months ago | |
| Platforms | 4 months ago | |
| Peer2PeerSample.sln | 4 months ago | |
| README.md | 4 months ago | |
A MonoGame sample demonstrating peer-to-peer multiplayer networking using a simple tank game. This project showcases how to implement network sessions with multiple players sharing game state in real-time.
This sample implements a multiplayer tank game where players can:
The project uses the Lidgren.Network library for peer-to-peer networking and demonstrates MonoGame's networking capabilities.
Peer2PeerSample/
├── Core/ # Shared game logic and classes
│ ├── Peer2PeerSample.Core.csproj
│ ├── PeerToPeerGame.cs
│ └── ... (other shared files)
├── Platforms/
│ ├── Windows/
│ │ ├── Peer2PeerSample.Windows.csproj
│ │ └── Program.cs
│ ├── Desktop/
│ │ ├── Peer2PeerSample.DesktopGL.csproj
│ │ └── Program.cs
│ ├── Android/
│ │ ├── Peer2Peer.Android.csproj
│ │ └── MainActivity.cs
│ └── iOS/
│ ├── Peer2Peer.iOS.csproj
│ ├── Program.cs
│ └── AppDelegate.cs
├── Content/ # Pre-built .xnb assets
├── Resources/ # Android resources
├── Properties/ # AndroidManifest.xml, etc.
├── README.md
└── Peer2PeerSample.sln # Solution file referencing all projects
Peer2PeerSample.slnbuild-windows - Build Windows versionbuild-desktopgl - Build DesktopGL versionbuild-android - Build Android versionrun-windows - Build and run Windows versionrun-desktopgl - Build and run DesktopGL version# Build Windows version
dotnet build Peer2PeerSample.Windows.csproj
# Build DesktopGL version
dotnet build Peer2PeerSample.DesktopGL.csproj
# Build Android version
dotnet build Peer2Peer.Android.csproj
# Run Windows version
dotnet run --project Peer2PeerSample.Windows.csproj
# Run DesktopGL version
dotnet run --project Peer2PeerSample.DesktopGL.csproj
This project uses pre-built .xnb content files located in the Content/ folder:
Font.xnb - Sprite font for UI textTank.xnb - Tank textureTurret.xnb - Tank turret texturegamepad.png - Virtual gamepad for mobile platformsNo Content.mgcb file is needed as the project uses the existing compiled content directly.
├── PeerToPeerGame.cs # Main game class
├── Program.cs # Platform-specific entry points
├── Activity1.cs # Android activity
├── Tank.cs # Tank game object
├── Content/ # Game assets (.xnb files)
├── Properties/ # Platform manifests
│ └── AndroidManifest.xml
├── Resources/ # Android resources
├── Info.plist # iOS app info
└── *.csproj # Platform-specific projects
The game creates or joins network sessions automatically. Multiple instances can be run on the same machine or across different devices on the same network to test multiplayer functionality.