Add documentation for remote control

This commit is contained in:
Nguyễn Gia Phong 2018-03-05 23:59:02 +07:00
parent 3cf78b680a
commit 2bafc0c75a
4 changed files with 61 additions and 19 deletions

View File

@ -33,16 +33,19 @@ The installation procedure should be as simply as follow:
* Open Terminal or Command Prompt and run ``pip install --user brutalmaze``.
Now you can launch the game by running the command ``brutalmaze``.
For more information, see the `Installation <https://github.com/McSinyx/brutalmaze/wiki/Installation>`_
from Brutal Maze wiki.
For more information, see
`Installation <https://github.com/McSinyx/brutalmaze/wiki/Installation>`_
page from Brutal Maze wiki.
Configuration
-------------
Brutal Maze supports both configuration file and command-line options.
Apparently one can change settings for graphics and control in the config file
and set graphics options using in CLI. These settings are read in the following
order:
Apparently, while settings for graphics, sound and socket server can be set
either in the config file or using CLI, keyboard and mouse bindings are limited
to configuration file only.
Settings are read in the following order:
0. Default configuration [0]_
1. System-wide configuration file [1]_
@ -50,7 +53,7 @@ order:
3. Manually set configuration file [2]_
4. Command-line arguments
The later-read preferences will overide the previous ones.
Later-read preferences will overide previous ones.
.. [0] This can be copied to desired location by ``brutalmaze --write-config
PATH``. ``brutalmaze --write-config`` alone will print the file to stdout.
@ -58,3 +61,29 @@ The later-read preferences will overide the previous ones.
(``brutalmaze --help``). See `wiki <https://github.com/McSinyx/brutalmaze/wiki/Configuration>`_
for more info.
.. [2] If specified by ``brutalmaze --config PATH``.
Remote control
--------------
If you enable the socket server [3]_, Brutal Maze will no longer accept direct
input from your mouse or keyboard, but wait for a client to connect. Details
about I/O format are explained carefully in
`Remote control <https://github.com/McSinyx/brutalmaze/wiki/Remote-control>`_
wiki page.
.. [3] This can be done by either editing option *Enable* in section *Server*
in the configuration file, or launching Brutal Maze using ``brutalmaze
--server``.
License
-------
Brutal Maze's source code and its icon are released under GNU Affero General
Public License version 3 or later. This means if you run a modified program on
a server and let other users communicate with it there, your server must also
allow them to download the source code corresponding to the modified version
running there.
Tango color palette and several sound effects, whose author and licenses are
listed in `Credits <https://github.com/McSinyx/brutalmaze/wiki/Credits>`_ wiki
page.

View File

@ -40,7 +40,7 @@ from appdirs import AppDirs
from .constants import SETTINGS, ICON, MUSIC, HERO_SPEED, COLORS, WALL
from .maze import Maze
from .misc import round2, sign
from .misc import deg, round2, sign
class ConfigReader:
@ -148,9 +148,14 @@ class Game:
def export(self):
"""Export maze data to a bytes object."""
maze, hero, time = self.maze, self.hero, get_ticks()
lines = deque(['{0} {4} {5} {1} {2:d} {3:d}'.format(
COLORS[hero.get_color()], deg(self.hero.angle),
hero.next_strike <= time, hero.next_heal <= time,
*self.expos(maze.x, maze.y))])
walls = [[1 if maze.map[x][y] == WALL else 0 for x in maze.rangex]
for y in maze.rangey] if maze.next_move <= time else []
lines, ne, nb = deque(), 0, 0
ne = nb = 0
for enemy in maze.enemies:
if not enemy.awake and walls:
@ -158,24 +163,22 @@ class Game:
continue
elif enemy.color == 'Chameleon' and maze.next_move <= time:
continue
x, y = self.expos(*enemy.get_pos())
lines.append('{} {} {} {:.0f}'.format(COLORS[enemy.get_color()],
x, y, degrees(enemy.angle)))
lines.append('{0} {2} {3} {1:.0f}'.format(
COLORS[enemy.get_color()], deg(enemy.angle),
*self.expos(*enemy.get_pos())))
ne += 1
for bullet in maze.bullets:
x, y = self.expos(bullet.x, bullet.y)
color, angle = COLORS[bullet.get_color()], degrees(bullet.angle)
color, angle = COLORS[bullet.get_color()], deg(bullet.angle)
if color != '0':
lines.append('{} {} {} {:.0f}'.format(color, x, y, angle))
nb += 1
if walls: lines.appendleft('\n'.join(''.join(str(cell) for cell in row)
for row in walls))
x, y = self.expos(maze.x, maze.y)
lines.appendleft('{} {} {} {} {} {} {} {:d} {:d}'.format(
len(walls), ne, nb, maze.get_score(), COLORS[hero.get_color()],
x, y, hero.next_strike <= time, hero.next_heal <= time))
lines.appendleft('{} {} {} {}'.format(len(walls), ne, nb,
maze.get_score()))
return '\n'.join(lines).encode()
def update(self):
@ -257,7 +260,10 @@ class Game:
time = get_ticks()
print('[{}] Connected to {}:{}'.format(time, *address))
self.maze.reinit()
while not self.hero.dead:
while True:
if self.hero.dead:
connection.send('00000000'.encode())
break
data = self.export()
connection.send('{:08}'.format(len(data)).encode())
connection.send(data)

View File

@ -19,7 +19,7 @@
__doc__ = 'Brutal Maze module for miscellaneous functions'
from math import cos, sin, pi
from math import degrees, cos, sin, pi
from random import uniform
import pygame
@ -57,6 +57,13 @@ def sign(n):
return -1 if n < 0 else 1 if n else 0
def deg(x):
"""Convert angle x from radians to degrees casted to a nonnegative
integer.
"""
return round2((lambda a: a if a > 0 else a + 360)(degrees(x)))
def cosin(x):
"""Return the sum of cosine and sine of x (measured in radians)."""
return cos(x) + sin(x)

2
wiki

@ -1 +1 @@
Subproject commit 91e65bda2aaf4563623b1faeae0afbf2f5840420
Subproject commit c1138583e40e11bf1acd473b83ea98b81caac191