Last active
August 29, 2015 14:21
-
-
Save jh0ker/8a63a66d368d7b48c89d to your computer and use it in GitHub Desktop.
A Simplifier for pygame events for use with the Arduino Pixel Videogame
This file contains hidden or 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
from led.PixelEventHandler import * | |
[...] | |
# Event Loop | |
for pgevent in pygame.event.get(): | |
event = process_event(pgevent) | |
if event.type == PUSH and event.player == PLAYER1: | |
# Movements | |
if event.button == UP: | |
go_up() | |
elif event.button == DOWN: | |
go_down() | |
elif event.button == RIGHT: | |
go_right() | |
elif event.button == LEFT: | |
go_left() |
This file contains hidden or 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
# Return values | |
UP, DOWN, LEFT, RIGHT, B1, B2, B3, P1, P2, UNKNOWN, EXIT = range(11) # PixelEvent.button | |
PUSH, RELEASE = range(2) # PixelEvent.type | |
PLAYER1, PLAYER2 = range(2) # PixelEvent.player | |
# Player 1 Keyboard bindings (defaults) | |
KB_UP_1 = K_UP | |
KB_DOWN_1 = K_DOWN | |
KB_LEFT_1 = K_LEFT | |
KB_RIGHT_1 = K_RIGHT | |
KB_B1_1 = K_COMMA | |
KB_B2_1 = K_PERIOD | |
KB_B3_1 = K_MINUS | |
# Player 2 Keyboard bindings (defaults) | |
KB_UP_2 = K_w | |
KB_DOWN_2 = K_s | |
KB_LEFT_2 = K_a | |
KB_RIGHT_2 = K_d | |
KB_B1_2 = K_c | |
KB_B2_2 = K_v | |
KB_B3_2 = K_b | |
# Neutral bindings | |
KB_P1 = K_1 | |
KB_P2 = K_2 | |
# Instance of this class is returned | |
class PixelEvent: | |
def __init__(self, button, type, player): | |
self.button = button | |
self.type = type | |
self.player = player |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment