-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
94 additions
and
83 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
#!/usr/bin/env python2.7 | ||
#!/usr/bin/env python2 | ||
# -*- coding: utf-8 -*- | ||
|
||
""" | ||
|
@@ -7,13 +7,27 @@ | |
This little program emulates the awesome Mate Light, just in case you're not on c-base space station but want to send | ||
something to it. | ||
Usage: | ||
emulator.py [-w=<px>] [-h=<px>] [--host=<ip>] [--port=<num>] [--dot=<size>] | ||
emulator.py --help | ||
emulator.py --version | ||
Options: | ||
--help Show this screen. | ||
--version Show version. | ||
-w=<px> Width in pixels [default: 40]. | ||
-h=<px> Height in pixels [default: 16]. | ||
--host=<host> Bind to IP address [default: 127.0.0.1]. | ||
--port=<port> Bind to Port [default: 1337]. | ||
--dot=<px> Size of dots in pixels [default: 10]. | ||
""" | ||
|
||
__author__ = 'Ricardo Band' | ||
__copyright__ = 'Copyright 2014, Ricardo Band' | ||
__credits__ = ['Ricardo Band'] | ||
__license__ = 'MIT' | ||
__version__ = '0.2.0' | ||
__version__ = '0.3.0' | ||
__maintainer__ = 'Ricardo Band' | ||
__email__ = '[email protected]' | ||
__status__ = 'Development' | ||
|
@@ -22,27 +36,27 @@ | |
import socket | ||
|
||
import pygame | ||
from docopt import docopt | ||
|
||
|
||
class Emu(object): | ||
""" | ||
The Emulator is a simple pygame game. | ||
""" | ||
def __init__(self, width=40, height=16, ip='127.0.0.1', port=1337): | ||
def __init__(self, width=40, height=16, ip='127.0.0.1', port=1337, dotsize=10): | ||
""" | ||
Creates a screen with the given size, generates the matrix for the Mate bottles and binds the socket for | ||
incoming frames. | ||
""" | ||
self.width = width | ||
self.height = height | ||
self.dotsize = dotsize | ||
pygame.init() | ||
# one mate bottle is 10x10px | ||
self.screen = pygame.display.set_mode([self.width * 10, self.height * 10]) | ||
self.screen = pygame.display.set_mode([self.width * self.dotsize, self.height * self.dotsize]) | ||
pygame.display.set_caption("Mate Light Emu") | ||
self.clock = pygame.time.Clock() | ||
self.matrix = [] | ||
for c in range(self.width * self.height * 3): | ||
# fill matrix with black color | ||
self.matrix.append(0) | ||
|
||
self.sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) | ||
|
@@ -71,7 +85,7 @@ def update(self): | |
if pixel < pixels: | ||
pygame.draw.circle(self.screen, | ||
(self.matrix[pixel], self.matrix[pixel + 1], self.matrix[pixel + 2]), | ||
(x * 10 + 5, y * 10 + 5), 5, 0) | ||
(x * self.dotsize + self.dotsize / 2, y * self.dotsize + self.dotsize / 2), self.dotsize / 2, 0) | ||
|
||
def render(self): | ||
""" | ||
|
@@ -101,5 +115,6 @@ def gameloop(self): | |
|
||
|
||
if __name__ == '__main__': | ||
EMU = Emu(40, 16, '127.0.0.1', 1337) | ||
ARGS = docopt(__doc__, version=__version__) | ||
EMU = Emu(int(ARGS['-w']), int(ARGS['-h']), ARGS['--host'], int(ARGS['--port']), int(ARGS['--dot'])) | ||
EMU.gameloop() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,15 +13,15 @@ | |
__copyright__ = 'Copyright 2014, Ricardo Band' | ||
__credits__ = ['Ricardo Band'] | ||
__license__ = 'MIT' | ||
__version__ = '0.2.0' | ||
__version__ = '0.3.0' | ||
__maintainer__ = 'Ricardo Band' | ||
__email__ = '[email protected]' | ||
__status__ = 'Development' | ||
|
||
from datetime import datetime | ||
|
||
import pymlgame | ||
from pymlgame.locals import * | ||
from pymlgame.locals import WHITE, BLUE, GREEN, CYAN, MAGENTA, YELLOW, RED, BLACK, E_NEWCTLR, E_DISCONNECT, E_KEYDOWN, E_KEYUP, E_PING | ||
from pymlgame.screen import Screen | ||
from pymlgame.clock import Clock | ||
from pymlgame.surface import Surface | ||
|
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,35 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
""" | ||
PyMLGame | ||
""" | ||
|
||
__author__ = 'Ricardo Band' | ||
__copyright__ = 'Copyright 2014, Ricardo Band' | ||
__credits__ = ['Ricardo Band'] | ||
__license__ = 'MIT' | ||
__version__ = '0.2.0' | ||
__version__ = '0.3.0' | ||
__maintainer__ = 'Ricardo Band' | ||
__email__ = '[email protected]' | ||
__status__ = 'Development' | ||
|
||
# from pymlgame.locals import * | ||
# from pymlgame.screen import Screen | ||
# from pymlgame.clock import Clock | ||
# from pymlgame.surface import Surface | ||
from pymlgame.locals import * | ||
from pymlgame.screen import Screen | ||
from pymlgame.clock import Clock | ||
from pymlgame.surface import Surface | ||
from pymlgame.controller import Controller | ||
|
||
_ctlr = Controller() | ||
CONTROLLER = Controller() | ||
|
||
|
||
def init(host='0.0.0.0', port=1338): | ||
""" | ||
Initialize pymlgame. This creates a controller thread that listens for game controllers and events. | ||
Initialize PyMLGame. This creates a controller thread that listens for game controllers and events. | ||
""" | ||
_ctlr.host = host | ||
_ctlr.port = port | ||
_ctlr.setDaemon(True) # because it's a deamon it will exit together with the main thread | ||
_ctlr.start() | ||
CONTROLLER.host = host | ||
CONTROLLER.port = port | ||
CONTROLLER.setDaemon(True) # because it's a deamon it will exit together with the main thread | ||
CONTROLLER.start() | ||
|
||
|
||
def get_events(maximum=10): | ||
|
@@ -35,10 +39,10 @@ def get_events(maximum=10): | |
events = [] | ||
for ev in range(0, maximum): | ||
try: | ||
if _ctlr.queue.empty(): | ||
if CONTROLLER.queue.empty(): | ||
break | ||
else: | ||
events.append(_ctlr.queue.get_nowait()) | ||
events.append(CONTROLLER.queue.get_nowait()) | ||
except NameError: | ||
not_initialized() | ||
events = False | ||
|
@@ -50,11 +54,11 @@ def get_event(): | |
""" | ||
Get the next event in the queue if there is one. | ||
""" | ||
if not _ctlr.queue.empty(): | ||
return _ctlr.queue.get_nowait() | ||
if not CONTROLLER.queue.empty(): | ||
return CONTROLLER.queue.get_nowait() | ||
else: | ||
return False | ||
|
||
|
||
def not_initialized(): | ||
print('pymlgame is not initialized correctly. Use pymlgame.init() first.') | ||
print('PyMLGame is not initialized correctly. Use pymlgame.init() first.') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.