How ai0702/among-us-clone works
Project Type & Purpose
• This is a multiplayer game (LAN) with optional voice chat, built in Python using pygame, pytmx, sockets, asyncore, threading, and pyaudio.
• Supports single-player (“Freeplay”) and local multiplayer via a custom game server and an optional voice chat server.
Main Architectural Components
a. Game Client
– Menu/UI Layer (menu.py)
– Game Loop & Renderer (main.py → game.py → drawable.py → sprites.py → tilemap.py)
– Input & Control Handlers (func.py, gamefunctions.py)
– Task Subsystem (tasks.py)
– Network Client (client side sockets in game.py)
– Voice Chat Client (voice.py, pyaudio streams)
– Asset Loader (loads images under Assets/, sounds under Assets/Sounds/, maps via pytmx)
b. Game Server (server.py)
– Connection Manager (asyncore / threading)
– Game State Manager (maintains player positions, tasks, impostor logic)
– Broadcast Loop (sends serialized state via pickle over sockets)
c. Voice Chat Server (server_voice.py)
– Audio Stream Manager (accepts pyaudio streams, forwards to clients)
d. Persistence & Configuration
– settings.py (configurable constants)
– setup.py (installation entry)
Relationships & Data Flows
• Clients ↔ Game Server
– TCP/UDP sockets carry serialized game state and player input.
• Clients ↔ Voice Chat Server
– pyaudio streams via sockets.
• Client Internal
– Game Loop → Rendering → Display
– Input Handler → Game Logic → Network Client
• Asset Loading
– Static assets (images, sounds, maps) are read at startup and cached by the client.
Architectural Patterns & Principles
• Client-Server (authoritative server) for game logic
• Modular layering inside Client:
– Presentation (UI/Menu)
– Application Logic (Game Loop, Tasks)
– Infrastructure (Networking, Audio I/O)
• Threaded / asynchronous I/O to prevent blocking (asyncore + threading + pyaudio callbacks)
• Asset separation (Assets folder) for maintainability
• Single Responsibility: each Python module handles one concern (e.g., tilemap.py for TMX parsing)
• Arrowheads to show direction of data/commands
– Client components (blue)
– Server components (green)
– External/third‐party (gray)