Skip to content

Commit 8f43fa7

Browse files
author
XenGi
committed
pixel size in emulator is now adjustable
1 parent 19585f2 commit 8f43fa7

File tree

2 files changed

+24
-8
lines changed

2 files changed

+24
-8
lines changed

controller_example.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ def __init__(self, game_host='127.0.0.1', game_port=1338, host='0.0.0.0', port=1
9898
self.rumble_active = False
9999
self.uid = None
100100

101-
self._receiver = ReceiverThread(host, port)
101+
self._receiver = ReceiverThread(self.host, self.port)
102102
self._receiver.setDaemon(True)
103103
self._receiver.start()
104104

emulator.py

+23-7
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/usr/bin/env python2.7
1+
#!/usr/bin/env python2
22
# -*- coding: utf-8 -*-
33

44
"""
@@ -7,13 +7,27 @@
77
88
This little program emulates the awesome Mate Light, just in case you're not on c-base space station but want to send
99
something to it.
10+
11+
Usage:
12+
emulator.py [-w=<px>] [-h=<px>] [--host=<ip>] [--port=<num>] [--dot=<size>]
13+
emulator.py --help
14+
emulator.py --version
15+
16+
Options:
17+
--help Show this screen.
18+
--version Show version.
19+
-w=<px> Width in pixels [default: 40].
20+
-h=<px> Height in pixels [default: 16].
21+
--host=<host> Bind to IP address [default: 127.0.0.1].
22+
--port=<port> Bind to Port [default: 1337].
23+
--dot=<px> Size of dots in pixels [default: 10].
1024
"""
1125

1226
__author__ = 'Ricardo Band'
1327
__copyright__ = 'Copyright 2014, Ricardo Band'
1428
__credits__ = ['Ricardo Band']
1529
__license__ = 'MIT'
16-
__version__ = '0.2.0'
30+
__version__ = '0.3.0'
1731
__maintainer__ = 'Ricardo Band'
1832
__email__ = '[email protected]'
1933
__status__ = 'Development'
@@ -22,22 +36,23 @@
2236
import socket
2337

2438
import pygame
39+
from docopt import docopt
2540

2641

2742
class Emu(object):
2843
"""
2944
The Emulator is a simple pygame game.
3045
"""
31-
def __init__(self, width=40, height=16, ip='127.0.0.1', port=1337):
46+
def __init__(self, width=40, height=16, ip='127.0.0.1', port=1337, dotsize=10):
3247
"""
3348
Creates a screen with the given size, generates the matrix for the Mate bottles and binds the socket for
3449
incoming frames.
3550
"""
3651
self.width = width
3752
self.height = height
53+
self.dotsize = dotsize
3854
pygame.init()
39-
# one mate bottle is 10x10px
40-
self.screen = pygame.display.set_mode([self.width * 10, self.height * 10])
55+
self.screen = pygame.display.set_mode([self.width * self.dotsize, self.height * self.dotsize])
4156
pygame.display.set_caption("Mate Light Emu")
4257
self.clock = pygame.time.Clock()
4358
self.matrix = []
@@ -71,7 +86,7 @@ def update(self):
7186
if pixel < pixels:
7287
pygame.draw.circle(self.screen,
7388
(self.matrix[pixel], self.matrix[pixel + 1], self.matrix[pixel + 2]),
74-
(x * 10 + 5, y * 10 + 5), 5, 0)
89+
(x * self.dotsize + self.dotsize / 2, y * self.dotsize + self.dotsize / 2), self.dotsize / 2, 0)
7590

7691
def render(self):
7792
"""
@@ -101,5 +116,6 @@ def gameloop(self):
101116

102117

103118
if __name__ == '__main__':
104-
EMU = Emu(40, 16, '127.0.0.1', 1337)
119+
ARGS = docopt(__doc__, version=__version__)
120+
EMU = Emu(int(ARGS['-w']), int(ARGS['-h']), ARGS['--host'], int(ARGS['--port']), int(ARGS['--dot']))
105121
EMU.gameloop()

0 commit comments

Comments
 (0)