Welcome to ASCII Realms, a Python-based multiplayer game that leverages Pygame for graphics and socket programming for network communication. Dive into a dynamic world where players interact in real-time, engage in lively chats, and experience customizable text rendering controlled by the server. Immerse yourself in the retro charm of ASCII art while enjoying modern multiplayer features.
- Features
- Prerequisites
- Installation
- Running the Server
- Running the Client
- Game Controls
- Customizing Text Rendering
- Troubleshooting
- Contributing
- License
- Multiplayer Support: Connect multiple clients to a central server for seamless real-time interaction.
- Chat System: Engage in text-based conversations with friends and other players, complete with character limits and command support.
- Customizable Text Rendering: The server can display text with various fonts, sizes, colors, spacing, and positions anywhere within the game window.
- Dynamic Popups: Receive and interact with pop-up messages that enhance gameplay and provide important information.
- Player Interaction: Navigate your character using intuitive keyboard controls and interact with other players in the shared environment.
- ASCII Art Style: Embrace the nostalgic feel of ASCII art combined with modern multiplayer dynamics.
Before you begin, ensure you have met the following requirements:
- Operating System: Windows, macOS, or Linux
- Python: Version 3.7 or higher
- Pygame: Installed for the client
- Socket Programming Knowledge: Basic understanding for running the server
-
Clone the Repository
git clone https://github.com/BarioIsCoding/ascii-realms.git cd ascii-realms
-
Create a Virtual Environment (Optional but Recommended)
python -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate
-
Install Required Python Packages
pip install pygame
The server manages player connections, handles chat messages, and sends customizable text rendering commands to all connected clients.
-
Navigate to the Project Directory
Ensure you're in the project root directory where
server.py
is located. -
Run the Server Script
python server.py
Server Configuration Options:
- Port: The server listens on port
55555
by default. You can change this by modifying theSERVER_PORT
variable inserver.py
. - Fonts: Ensure that the fonts you intend to use for custom text rendering are installed on the server machine.
- Port: The server listens on port
-
Server Commands
The server can accept commands to broadcast messages or render custom text. Example commands include:
-
Broadcast Chat Message
/chat Hello, players!
-
Render Custom Text
/render_text {"text": "Welcome!", "position": [100, 150], "font": "Arial", "size": 24, "colors": [[255, 0, 0]], "spacing": 2, "duration": 10}
Note: The exact command format may vary based on the server implementation. Refer to
server.py
for detailed command handling. -
Each player runs a client instance to connect to the server and participate in the game.
-
Navigate to the Project Directory
Ensure you're in the project root directory where
client.py
(ormain.py
) is located. -
Run the Client Script
python client.py
-
Client Setup
- Server IP: When prompted, enter the IP address of the server. If running locally, you can use
localhost
. - Username: Enter a unique name to represent you in the game.
- Server IP: When prompted, enter the IP address of the server. If running locally, you can use
Use the following keyboard controls to navigate and interact within the game:
-
Movement:
- Left Arrow or A: Move left
- Right Arrow or D: Move right
- Up Arrow or W: Move up
- Down Arrow or S: Move down
-
Chat:
- Spacebar: Activate chat typing mode
- Enter: Send chat message
- Backspace: Delete the last character in your chat input
-
Popups:
- Escape (ESC): Close any active popup messages
The server can send commands to display text with various properties. Here's how you can utilize this feature:
-
Sending a Render Text Command
The server can send a JSON-formatted command to instruct clients to render text with specific attributes. Example command structure:
{ "render_text": [ { "text": "Hello, World!", "position": [100, 150], "font": "Arial", "size": 24, "colors": [[255, 0, 0], [0, 255, 0], [0, 0, 255]], "spacing": 2, "duration": 15 }, { "text": "Welcome to ASCII Realms!", "position": [300, 400], "font": "Courier", "size": 30, "colors": [], "spacing": 1, "duration": 20 } ] }
Field Descriptions:
text
: The string to render.position
:[x, y]
coordinates on the screen.font
: (Optional) Font name. Defaults toCourier
if not specified or invalid.size
: (Optional) Font size. Defaults to24
if not specified.colors
: (Optional) List of RGB color tuples for each character. If not provided or shorter than the text length, missing characters default to white.spacing
: (Optional) Space in pixels between characters. Defaults to2
.duration
: (Optional) Time in seconds the text should remain on the screen. Defaults to10
seconds.
-
Server Example: Rendering Custom Text
Here's how the server can send a custom text rendering command:
import socket import json SERVER_HOST = 'localhost' SERVER_PORT = 55555 with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s: s.connect((SERVER_HOST, SERVER_PORT)) render_command = { "render_text": [ { "text": "Game Started!", "position": [200, 100], "font": "Verdana", "size": 28, "colors": [[0, 255, 0]] * 12, # Green color for each character "spacing": 1, "duration": 10 } ] } s.sendall(json.dumps(render_command).encode('utf-8'))
If you encounter any issues while setting up or running the game, consider the following solutions:
-
Font Recognition Issues:
- Ensure that the fonts specified in
render_text
commands are installed on both the server and client machines. - Check for typos in font names.
- Use default fonts like
Courier
orArial
to minimize issues.
- Ensure that the fonts specified in
-
Connection Problems:
- Verify that the server is running and listening on the correct IP and port.
- Ensure that firewall settings allow traffic through the specified port (
55555
by default). - Use the correct server IP when prompted by the client.
-
Pygame Errors:
- Ensure Pygame is installed correctly by running
pip install pygame
. - Check for any missing dependencies or incompatible Python versions.
- Ensure Pygame is installed correctly by running
-
Script Crashes:
- Run scripts in a terminal to view error messages.
- Ensure that no other application is using the server port.
- Verify that all required Python packages are installed.
-
Popups Not Displaying Correctly:
- Ensure that the server sends
render_text
commands in the correct JSON format. - Check that the
colors
array matches the length of thetext
string or provides defaults.
- Ensure that the server sends
Contributions are welcome! If you'd like to improve this project, please follow these steps:
-
Fork the Repository
-
Create a New Branch
git checkout -b feature/YourFeature
-
Make Your Changes
-
Commit Your Changes
git commit -m "Add your message here"
-
Push to the Branch
git push origin feature/YourFeature
-
Open a Pull Request
This project is licensed under the MIT License.
Enjoy exploring the realms of ASCII Realms! If you have any questions or need further assistance, feel free to open an issue or contact the maintainer.