Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/aermoss/aerics
A networking library written Python for online games.
https://github.com/aermoss/aerics
client multiplayer multiplayer-game multiplayer-game-server server server-client
Last synced: about 3 hours ago
JSON representation
A networking library written Python for online games.
- Host: GitHub
- URL: https://github.com/aermoss/aerics
- Owner: Aermoss
- License: mit
- Created: 2022-01-25T17:34:06.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2023-11-28T02:27:33.000Z (12 months ago)
- Last Synced: 2024-08-09T16:35:42.954Z (3 months ago)
- Topics: client, multiplayer, multiplayer-game, multiplayer-game-server, server, server-client
- Language: Python
- Homepage:
- Size: 14.6 KB
- Stars: 3
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Aerics
A networking library written Python for online games.## Getting Started
1) Install Python
2) Open cmd/terminal and type:```
pip install Aerics
```## Examples
# Creating a server
``` python
import aerics, sysdef main(argv):
server = aerics.Server("localhost", 5656)@server.event
def setup(globals):
pass# @server.event
# def update():
# pass@server.event
def on_connection(connection, address, id, clients, globals):
print("New connection")
return {"x" : 0, "y" : 0}@server.event
def on_disconnection(connection, address, id, clients, globals):
print(f"Client {id} disconnected")@server.event
def on_recv(connection, address, id, clients, globals, data):
data = data.split(",")if data[0] == "move":
clients[id]["x"], clients[id]["y"] = int(data[1]), int(data[2])
return clientsif data[0] == "get_id":
return idif data[0] == "close":
server.disconnect(connection)
return Noneserver.listen()
if __name__ == "__main__":
sys.exit(main(sys.argv))
```# Creating a client
``` python
import forges, aerics, sysclass Window(forges.Window):
def __init__(self):
super(Window, self).__init__()self.client = aerics.Client("localhost", 5656)
self.client.connect()
self.client.send("get_id")
self.id = self.client.recv()
self.clients = []self.player = forges.prefabs.TopViewController()
def update(self):
self.client.send(f"move,{self.player.x},{self.player.y}")
clients = self.client.recv()
del clients[self.id]while len(clients) != len(self.clients):
if len(clients) < len(self.clients):
self.clients[0].destroy()
self.clients.pop(0)else:
self.clients.append(forges.Entity(width = 50, height = 100))for index, i in enumerate(clients):
self.clients[index].x, self.clients[index].y = clients[i]["x"], clients[i]["y"]def main(argv):
window = Window()
forges.run()
return 0if __name__ == "__main__":
sys.exit(main(sys.argv))
```