Skip to content

TanakAiko/multiplayer-fps

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

78 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

Multiplayer FPS - Maze Game

Rust Bevy Tokio

A multiplayer first-person maze game built with Rust, featuring procedurally generated mazes, real-time networking, and support for 10+ concurrent players.

๐Ÿ“ธ Screenshots

Player View Inside Map First-person view of a player navigating through the procedurally generated maze

๐ŸŽฎ Features

  • Multiplayer Support: Real-time UDP-based networking for 10+ concurrent players
  • Procedural Generation: Dynamically generated mazes with increasing difficulty
  • 3D Graphics: Built with Bevy ECS engine for smooth rendering and game logic
  • HUD System: Real-time display of FPS, player names, mini-map, and level information
  • Client Prediction: Latency compensation for smooth gameplay
  • Collision Detection: Physics-based movement and obstacle interaction

๐Ÿš€ Getting Started

Prerequisites

  • Rust (latest stable version)
  • Cargo

Installation

  1. Clone the repository:
git clone https://github.com/yourusername/multiplayer-fps.git
cd multiplayer-fps
  1. Build the project:
cargo build --release

Running the Game

Start the server:

cargo run --bin server

Start a client:

cargo run --bin client

You'll be prompted to enter:

  • Server IP address
  • Your player username

๐Ÿ“ฆ Dependencies

Core Libraries

Library Purpose
Bevy ECS game engine for entity management, 3D/2D rendering, and game logic
Tokio Async runtime for high-performance UDP network communication
Serde Data serialization/deserialization for network messages
Rand Procedural maze generation using algorithms like Prim or Recursive Backtracking
Crossbeam Thread-safe communication between networking and rendering subsystems

Optional Libraries

  • Quinn: QUIC protocol support for enhanced UDP with reliability guarantees
  • Petgraph: Graph analysis for complex maze generation and pathfinding

๐Ÿ—๏ธ Architecture

Project Structure

src/
โ”œโ”€โ”€ lib.rs                          # Library root
โ”œโ”€โ”€ bin/
โ”‚   โ”œโ”€โ”€ client.rs                   # Client entry point
โ”‚   โ””โ”€โ”€ server.rs                   # Server entry point
โ”œโ”€โ”€ client/
โ”‚   โ”œโ”€โ”€ mod.rs
โ”‚   โ”œโ”€โ”€ udp.rs                      # Client UDP networking
โ”‚   โ”œโ”€โ”€ components/                 # ECS components
โ”‚   โ”‚   โ”œโ”€โ”€ animation_component.rs
โ”‚   โ”‚   โ”œโ”€โ”€ bullet.rs
โ”‚   โ”‚   โ”œโ”€โ”€ camera_component.rs
โ”‚   โ”‚   โ”œโ”€โ”€ enemy_component.rs
โ”‚   โ”‚   โ”œโ”€โ”€ flag_component.rs
โ”‚   โ”‚   โ”œโ”€โ”€ player_component.rs
โ”‚   โ”‚   โ”œโ”€โ”€ rendering_component.rs
โ”‚   โ”‚   โ””โ”€โ”€ world_component.rs
โ”‚   โ”œโ”€โ”€ plugins/                    # Bevy plugins
โ”‚   โ”‚   โ”œโ”€โ”€ enemy_plugin.rs
โ”‚   โ”‚   โ”œโ”€โ”€ player_plugin.rs
โ”‚   โ”‚   โ””โ”€โ”€ world_plugin.rs
โ”‚   โ”œโ”€โ”€ resources/                  # Game resources
โ”‚   โ”‚   โ”œโ”€โ”€ animation_resource.rs
โ”‚   โ”‚   โ”œโ”€โ”€ enemy_resource.rs
โ”‚   โ”‚   โ”œโ”€โ”€ network_resource.rs
โ”‚   โ”‚   โ”œโ”€โ”€ player_resource.rs
โ”‚   โ”‚   โ””โ”€โ”€ world_resource.rs
โ”‚   โ””โ”€โ”€ systems/                    # Game systems
โ”‚       โ”œโ”€โ”€ camera/
โ”‚       โ”œโ”€โ”€ common/
โ”‚       โ”œโ”€โ”€ enemy/
โ”‚       โ”œโ”€โ”€ page/
โ”‚       โ”œโ”€โ”€ player/
โ”‚       โ””โ”€โ”€ world/
โ”œโ”€โ”€ server/
โ”‚   โ”œโ”€โ”€ mod.rs
โ”‚   โ”œโ”€โ”€ udp.rs                      # Server UDP networking
โ”‚   โ””โ”€โ”€ utils/
โ”‚       โ””โ”€โ”€ exeption.rs
โ””โ”€โ”€ common/
    โ”œโ”€โ”€ types/
    โ”‚   โ”œโ”€โ”€ game_state.rs           # Shared game state
    โ”‚   โ””โ”€โ”€ protocol.rs             # Network protocol definitions
    โ””โ”€โ”€ utils/
        โ””โ”€โ”€ socket_utils.rs         # Socket utilities

Module Responsibilities

๐ŸŒ Network Module

  • Purpose: Client-server communication via UDP
  • Responsibilities:
    • UDP server implementation using Tokio
    • Message serialization/deserialization with Serde
    • Handling 10+ simultaneous connections
    • Packet loss management and latency optimization

๐ŸŽฏ Game Logic Module

  • Purpose: Core game mechanics and rules
  • Responsibilities:
    • Entity management (players, mazes, obstacles, levels)
    • Procedural maze generation with increasing difficulty
    • Collision detection and movement mechanics
    • Win condition implementation

๐Ÿ–ผ๏ธ Graphics Module

  • Purpose: Rendering and visual presentation
  • Responsibilities:
    • Maze and world rendering
    • Camera synchronization with player movement
    • HUD display (FPS counter, mini-map, player name, level)
    • Real-time position updates from server state

๐Ÿ’ป Client Module

  • Purpose: User interaction and input handling
  • Responsibilities:
    • Command-line interface for connection setup
    • Keyboard and mouse input processing
    • Server state synchronization
    • Client-side prediction for latency compensation

๐Ÿ–ฅ๏ธ Server Module

  • Purpose: Centralized game state management
  • Responsibilities:
    • Global game state maintenance (positions, scores, maze state)
    • Network connection management
    • Periodic state broadcasting to connected clients
    • Player session management

๐Ÿ”ง Development Guidelines

Integration Best Practices

Network-Graphics Consistency

  • Network module sends only essential data (player positions, maze state)
  • Graphics module updates display based on received data
  • Use efficient data structures to minimize bandwidth

Client-Server Synchronization

  • Unique player IDs for state association
  • Client-side prediction to mask latency
  • Server authoritative for game state
  • Periodic reconciliation of client predictions

Performance & Modularity

  • Clear separation of concerns between modules
  • Unit tests for each module
  • Optimized maze algorithms
  • Minimal computations in main game loop

Testing Strategy

Create automated tests for:

  • Network connectivity and message passing
  • Maze generation algorithms
  • Collision detection
  • Player movement
  • State synchronization

๐Ÿค Contributing

Contributions are welcome! Here are some ways you can contribute:

  • Add New Features: Implement power-ups, weapons, or game modes
  • Improve Maze Generation: Enhance algorithms for better maze layouts and difficulty scaling
  • Optimize Networking: Reduce latency, improve packet handling, or add TCP fallback
  • Enhance Graphics: Add better textures, lighting effects, or visual feedback
  • Improve Collision Detection: Fine-tune physics and movement mechanics
  • Add Tests: Write unit and integration tests for critical systems
  • Fix Bugs: Report and fix issues in gameplay, networking, or rendering
  • Improve Documentation: Enhance code comments, add tutorials, or create guides

โญ Star this repository if you found it helpful! โญ

Made with โค๏ธ from ๐Ÿ‡ธ๐Ÿ‡ณ

About

A multiplayer first-person shooter built with Rust and Bevy. Navigate throught generated map, engage enemies, and compete with 10+ players in real-time UDP networked battles.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors