Skip to content

Commit c0bfdda

Browse files
author
Ricardo Band
committed
intercorse protocol implemented. game and controller example updated.
1 parent 7d2eaf6 commit c0bfdda

12 files changed

+469
-484
lines changed

README.md

Lines changed: 96 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,113 @@
1-
# pymlgame
1+
pymlgame
2+
========
23

34
pymlgame is an abstraction layer to easily build games for Mate Light inspired by pygame.
45

56
You need 3 parts to actually have a running game on Mate Light.
67

7-
## The game
8+
The game
9+
--------
810

9-
You can build a game using the pymlgame library. If you know the pygame library this should mean nothing new to you.
10-
Use the game_example.py to find out how to do it.
11+
You can build a game using the pymlgame library. If you know the pygame library this should be nothing new to you.
12+
Use the game_example.py to find out how to do so.
1113

12-
## A controller
14+
A controller
15+
------------
1316

14-
If you want players, your game needs a controller to have some inputs. You can use anything as a controller that can
15-
speak the pymlgame controller protocol. As an example you can use the controller_example.py and adapt it to your
16-
controller.
17+
If you want players, your game needs a controller to have some inputs. Controllers should work with every game made with
18+
pymlgame. There is a controller_example.py to play with. An Android based controller app is in the works.
1719

18-
Here are the commands a controller can send to a pymlgame:
20+
Mate Light
21+
----------
1922

20-
- /cotroller/new
21-
Tell pymlgame that you want to play also known as "anpymln". It will send you a UID which should be used in
22-
future communication.
23-
- /controller/<int:uid>/ping
24-
Just tell pymlgame that you're still their. Also this updates your IP address so use this after a reconnect.
25-
- /controller/<int:uid>/kthxbye
26-
Be so nice and tell pymlgame that you are closing the controller on your device. That helps to avoid alot of
27-
garbage to go through.
28-
- /controller/<int:uid>/states/00000000000000
29-
Send the states of the 14 possible buttons. These are Up, Down, Left, Right, A, B, X, Y, Start, Select, L1, L2,
30-
R1, R2
31-
- /controller/<int:uid>/text/<str:text>
32-
Send a message to pymlgame. this can be used to enter player names.
23+
To play pymlgames you need the awesome Mate Light. You could use the one on c-base space station, or build your own.
24+
If you're not near c-base and don't want to build your own, you can use the Mate Light emulator provided with pymlgame.
3325

34-
These are the commands that a controller could receive:
3526

36-
- /uid/<int:uid>
37-
Use this UID in future communication.
38-
- /rumble/<int:duration>
39-
The game wants your controller to rumble for n seconds.
40-
- /message/<str:text>
41-
The game wants your controller to display some text.
27+
Protocol
28+
========
4229

43-
## Mate Light
30+
This is the coitus protocol that handles the communication between the game and the controllers.
31+
32+
33+
Controller -> Game
34+
------------------
35+
36+
### /controller/new/<port>
37+
38+
Connect a new controller to the game. Game will answer with /uid/<uid>. This is also known as 'anpymln'.
39+
40+
### /controller/<uid>/ping/<port>
41+
42+
Tell the game that the controller is still in use and update it's address and port. Use this once a minute or the
43+
controller will get deleted.
44+
45+
### /controller/<uid>/kthxbye
46+
47+
Disconnect the controller properly. In theory you could just wait 60s but this is the cleaner way and most games would
48+
be very happy if you use this.
49+
50+
###/controller/<uid>/states/<states>
51+
52+
Send the states of your controller keys. Always send all 14 states, even if your controller doesn't have 14 buttons.
53+
The states should be an array with 0 for key not pressed and 1 for key pressed. So if you're pressing the Up button and
54+
X the states array should look like this: 10000010000000
55+
You can lookup all possible buttons and there location in the array in pymlgame/locals.py.
56+
57+
### /controller/<uid>/text/<text>
58+
59+
*Optional*
60+
61+
Send some text to the game. Maybe it asks you for a player name. Games should always give you the option to enter text
62+
without this function but you can use it if your controller is capable of text input.
63+
64+
65+
Game -> Controller
66+
------------------
67+
68+
### /uid/<uid>
69+
70+
Tell the controller its uid. This is ideally an integer.
71+
72+
### /rumble/<duration>
73+
74+
*Optional*
75+
76+
Tell the controller to rumble. Duration should be given in milliseconds. Not all controllers have the ability to rumble.
77+
Maybe they do it in an optical way.
78+
79+
### /message/<text>
80+
81+
*Optional*
82+
83+
Send some text to the controller. Be aware that not all controllers can display text, so don't send important things.
84+
85+
### /download/<url>
86+
87+
*Optional*
88+
89+
Tell the controller to download the media file under the given url. The game can then ask the controller to play the
90+
file so that the player can hear some ingame sounds. Use this function everytime the game starts because a controller
91+
could have deleted the files after playing. Controllers should ensure that files already downloaded gets downloaded
92+
again to reduce loading times for games that have been played before.
93+
94+
### /play/<file>
95+
96+
*Optional*
97+
98+
Tell the controller to play the file with that name. Use the download command to download media files to the controller
99+
before using this.
100+
101+
102+
Tipps
103+
-----
104+
105+
If your controller downloads media files for games it is good practice to delete the downloaded stuff from time to time
106+
or give the user the ability to cleanup the downloaded files.
107+
108+
If your game uses some optional features, tell the players that they can have an even better gaming experience when they
109+
use a controller with is capable of these features.
44110

45-
Last but not least you need Mate Light as your display. If you are not at c-base space station but still want to
46-
tinker around with this you can use the emulator.py to do so.
47111

48112
---
49113

0 commit comments

Comments
 (0)