113 lines
2.9 KiB
Python
113 lines
2.9 KiB
Python
from escapelib import Game, nbus, gpio
|
|
from escapelib.io import on_input, on_puzzle
|
|
from escapelib.media import play_music, reset_played, stop_music
|
|
from escapelib.util import delay, quit_game
|
|
|
|
from twisted.application.service import Application
|
|
|
|
|
|
class ButtonPanel(nbus.Prop):
|
|
button_0 = nbus.Input(0)
|
|
button_1 = nbus.Input(1)
|
|
button_2 = nbus.Input(2)
|
|
button_3 = nbus.Input(3)
|
|
button_4 = nbus.Input(4)
|
|
button_5 = nbus.Input(5)
|
|
|
|
class Portrait(nbus.Prop):
|
|
top_left = nbus.Input(0)
|
|
top_right = nbus.Input(1)
|
|
bottom_left = nbus.Input(2)
|
|
bottom_right = nbus.Input(3)
|
|
|
|
class Jars(nbus.Prop):
|
|
slot_0 = nbus.Analog(0)
|
|
slot_1 = nbus.Analog(1)
|
|
slot_2 = nbus.Analog(2)
|
|
slot_3 = nbus.Analog(3)
|
|
slot_4 = nbus.Analog(4)
|
|
slot_5 = nbus.Analog(5)
|
|
cauldron_light = nbus.Output(0)
|
|
|
|
class Puzzle(nbus.Prop):
|
|
sensor_0 = nbus.Analog(0)
|
|
sensor_1 = nbus.Analog(1)
|
|
sensor_2 = nbus.Analog(2)
|
|
sensor_3 = nbus.Analog(3)
|
|
sensor_4 = nbus.Analog(4)
|
|
sensor_5 = nbus.Analog(5)
|
|
|
|
class LibraryCabinet(nbus.Prop):
|
|
sensor = nbus.Input(0)
|
|
lock = nbus.Output(0)
|
|
|
|
class InputBoard(nbus.Prop):
|
|
announcements = nbus.Input(0)
|
|
room_power = nbus.Input(2)
|
|
|
|
class BookOfSpells(Game):
|
|
|
|
__bus_port__ = '/dev/ttyUSB0'
|
|
__bus_baud__ = 1000000
|
|
|
|
reset = gpio.Input(8)
|
|
|
|
key_drop = gpio.Output(504)
|
|
exit_lock = gpio.Output(506)
|
|
exit_lights = gpio.Output(507)
|
|
cupboard_lock = gpio.Output(508)
|
|
dog_box = gpio.Output(509)
|
|
|
|
button_panel = ButtonPanel(0x00)
|
|
portrait = Portrait(0x01)
|
|
jars = Jars(0x02)
|
|
puzzle = Puzzle(0x03)
|
|
library_cabinet = LibraryCabinet(0x04)
|
|
input_board = InputBoard(0xaa)
|
|
|
|
@on_input(reset)
|
|
def reset_software(self):
|
|
quit_game()
|
|
|
|
@on_input(input_board.room_power)
|
|
def game_start(self): # type: () -> None
|
|
self.key_drop.set(True)
|
|
self.exit_lock.set(True)
|
|
self.cupboard_lock.set(True)
|
|
self.exit_lights.set(True)
|
|
reset_played()
|
|
play_music("music.mp3")
|
|
|
|
@on_input(input_board.room_power, False)
|
|
def game_stop(self): # type: () -> None
|
|
self.exit_lights.set(False)
|
|
self.exit_lock.set(False)
|
|
self.cupboard_lock.set(False)
|
|
stop_music()
|
|
|
|
@on_input(input_board.announcements)
|
|
def play_house_announcements(self, state): # type: (bool) -> None
|
|
if state is True:
|
|
play_sound_effect('button.mp3')
|
|
|
|
@on_puzzle(jars)
|
|
def win(self): # type: () -> None
|
|
self.timer.stop()
|
|
self.exit_lock.set(False)
|
|
|
|
@on_puzzle(button_panel)
|
|
def drop_key(self): # type: () -> None
|
|
self.key_drop.set(False)
|
|
|
|
@on_puzzle(portrait)
|
|
def play_slytherin(self): # type: () -> None
|
|
play_sound_effect_once("slytherin.mp3")
|
|
|
|
@on_puzzle(puzzle)
|
|
def open_cupboard(self): # type: () -> None
|
|
self.cupboard_lock.set(False)
|
|
|
|
game = BookOfSpells()
|
|
application = Application(game.__class__.__name__)
|
|
game.register(application)
|