Ejemplo n.º 1
0
 def __init__(self, screen, col_life):
     x = 0
     y = 770
     self.col_life = col_life
     self.lis = list()
     for i in range(20):
         self.lis.append(floor_class.Floor(x, y, screen))
         x += 75
     self.lis.append(start.Start(75, 748, screen))
     self.lis.append(fire.Fire(200, 737, screen))
     self.lis.append(fire.Fire(900, 737, screen))
     self.lis.append(fire.Fire(981, 737, screen))
     self.lis.append(cube.Cube(500, 684, screen))
     self.lis.append(cube.Cube(586, 684, screen))
     self.lis.append(cube.Cube(586, 598, screen))
     self.lis.append(cube.Cube(672, 684, screen))
     self.lis.append(cube.Cube(672, 598, screen))
     self.lis.append(cube.Cube(758, 684, screen))
     self.lis.append(fire.Fire(758, 655, screen))
     self.lis.append(flat.Flat(930, 500, screen))
     if self.col_life == 3:
         self.lis.append(life.Life(230, 30, screen))
         self.lis.append(life.Life(130, 30, screen))
         self.lis.append(life.Life(30, 30, screen))
     elif self.col_life == 2:
         self.lis.append(life.Life(130, 30, screen))
         self.lis.append(life.Life(30, 30, screen))
     elif self.col_life == 1:
         self.lis.append(life.Life(30, 30, screen))
     self.lis.append(die_player.DPlayer(2000, 2000, screen))
     self.lis.append(green_door.GDoor(2000, 2000, screen))
     self.lis.append(door.Door(1300, 581, screen))
     self.lis.append(green_button.GreenButton(2000, 2000, screen))
     self.lis.append(red_button.RedButton(1005, 452, screen))
     self.lis.append(player_class.Player(100, 465, screen))
Ejemplo n.º 2
0
def test_remote_client():
    # Receivers
    room_light = light.Light('room')
    garage_light = light.Light('garage')
    garage_door = door.Door('garage', garage_light)

    # Commands
    room_light_on = light.LightOn(room_light)
    room_light_off = light.LightOff(room_light)
    garage_door_open = door.DoorOpen(garage_door)
    garage_door_close = door.DoorClose(garage_door)
    party_on = MacroCommand([room_light_on, garage_door_open])
    party_off = MacroCommand([room_light_off, garage_door_close])

    # Invoker
    capacity = 4
    remote = Remote(capacity)
    remote.set_command(0, room_light_on, room_light_off)
    remote.set_command(1, garage_door_open, garage_door_close)
    remote.set_command(2, party_on, party_off)

    # Execute
    for i in range(capacity):
        print(f'\nbutton number #{i}')
        remote.on_button_was_pushed(i)
        remote.off_button_was_pushed(i)
        remote.undo()
Ejemplo n.º 3
0
 def lclick(self, x, y, mods):
     if self.start:
         new_id = max(self.editor.world.doors.keys() + [0]) + 1
         self.editor.world.doors[new_id] = door.Door(
             None, self.start, (x, y))
         self.start = None
     else:
         self.start = (x, y)
Ejemplo n.º 4
0
 def __init__(self, width, height):
     self.mWidth = width
     self.mHeight = height
     self.mWalls = walls.Walls(self.mWidth, self.mHeight)
     self.mSun = sun.Sun(0.75 * self.mWidth, 0.66 * self.mHeight,
                         (1. / 8.) * self.mHeight)
     self.mDoor = door.Door(self.mWidth / 6, self.mHeight / 3)
     return
Ejemplo n.º 5
0
def import_door():
    door_stats = []
    while len(door_stats) != 15:
        doorstring = raw_input("Enter the string of comma separated stats: ")
        door_stats = doorstring.split(',')
        if len(door_stats) != 15:
            print "Invalid import string!"
    new_door = door.Door(door_stats)
    return new_door
Ejemplo n.º 6
0
    def __init__(self, width, height):
        self.width = width
        self.height = height
        self.walls = walls.Walls(self.width, self.height)
        self.door = door.Door(0.10 * self.width, 20 * self.height,
                              self.width / 7, self.height / 5, 112, 95, 54)
        #self.tv = tv.TV()
        self.light = light.Light(0.75 * self.width, 0.66 * self.height,
                                 (1. / 8.) * self.height)

        return
Ejemplo n.º 7
0
    def setUp(self):
        self.interface = mock.create_autospec(serialinterface.SerialInterface)
        self.interface.writeMessage = mock.MagicMock()
        self.input_queue = Queue.Queue()
        self.t0 = time.time()
        self.door_name = 'Door1'
        self.persisted_min_rx_seq_leap = 2**15
        self.persisted_min_rx_seq = 128
        self.key = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
        self.address = 'A'

        (sequence_number_container_file,
         self.sequence_number_container_file_path) = tempfile.mkstemp()

        sequence_number_container_file = open(
            self.sequence_number_container_file_path, 'w')
        sequence_number_container_file.write(
            "[Door1]\r\nrx_sequence = %d\r\n" % self.persisted_min_rx_seq)
        sequence_number_container_file.close()

        config = ConfigParser.RawConfigParser()
        config.add_section(self.door_name)
        config.set("Door1", "rx_sequence_leap", self.persisted_min_rx_seq_leap)
        config.set("Door1", "inital_unlock", True)
        config.set("Door1", "address", self.address)
        config.set("Door1", "sequence_number_container_file",
                   self.sequence_number_container_file_path)
        config.set("Door1", "key", ' '.join([str(x) for x in self.key]))
        config.set("Door1", "timeout", '2')

        self.buttons = {1: 'Button0', 2: 'Button1'}

        self.packet_press = packet.Packet(0, ord('S'), '\x01\x00\x00\x00\x00',
                                          False)
        self.packet_release = packet.Packet(0, ord('S'),
                                            '\x00\x00\x00\x00\x00', False)
        self.packet_unlocking = packet.Packet(0, ord('S'),
                                              '\x00\x10\x00\x00\x00', False)
        self.packet_manual_unlocked = packet.Packet(0, ord('S'),
                                                    '\x00\x40\x00\x00\x00',
                                                    False)
        self.packet_locked = packet.Packet(0, ord('S'), '\x00\x02\x00\x00\x00',
                                           False)
        self.packet_open_unlocked = packet.Packet(0, ord('S'),
                                                  '\x00\x00\x00\x00\x00',
                                                  False)

        self.door = door.Door('Door1', config, self.interface,
                              self.input_queue, self.buttons)
        self.callback = mock.MagicMock()
        self.door.add_state_listener(self.callback)
Ejemplo n.º 8
0
 def __init__(self, screen):
     x = 0
     y = 770
     self.lis = list()
     for i in range(20):
         self.lis.append(floor_class.Floor(x, y, screen))
         x += 75
     self.lis.append(start.Start(75, 748, screen))
     self.lis.append(life.Life(230, 30, screen))
     self.lis.append(life.Life(130, 30, screen))
     self.lis.append(floor_class.Floor(-75, 697, screen))
     self.lis.append(life.Life(30, 30, screen))
     self.lis.append(green_door.GDoor(2000, 2000, screen))
     self.lis.append(door.Door(1200, 581, screen))
     self.lis.append(green_button.GreenButton(2000, 2000, screen))
     self.lis.append(red_button.RedButton(400, 728, screen))
     self.lis.append(player_class.Player(100, 465, screen))
Ejemplo n.º 9
0
 def __init__(self, screen, col_life):
     self.lis = []
     self.col_life = col_life
     self.lis.append(floor_class.Floor(0, 600, screen))
     self.lis.append(floor_class.Floor(75, 600, screen))
     self.lis.append(floor_class.Floor(150, 600, screen))
     self.lis.append(floor_class.Floor(225, 600, screen))
     self.lis.append(floor_class.Floor(225, 675, screen))
     self.lis.append(floor_class.Floor(225, 750, screen))
     self.lis.append(floor_class.Floor(300, 750, screen))
     x = 300
     for i in range(11):
         self.lis.append(floor_class.Floor(x, 750, screen))
         x += 75
     self.lis.append(floor_class.Floor(x, 750, screen))
     self.lis.append(floor_class.Floor(x, 675, screen))
     self.lis.append(floor_class.Floor(x, 600, screen))
     for i in range(5):
         self.lis.append(floor_class.Floor(x, 600, screen))
         x += 75
     self.lis.append(fire.Fire(300, 717, screen))
     self.lis.append(fire.Fire(381, 717, screen))
     self.lis.append(cube.Cube(462, 664, screen))
     self.lis.append(cube.Cube(548, 664, screen))
     self.lis.append(cube.Cube(773, 664, screen))
     self.lis.append(cube.Cube(859, 664, screen))
     self.lis.append(cube.Cube(945, 664, screen))
     self.lis.append(fire.Fire(945, 635, screen))
     self.lis.append(cube.Cube(859, 578, screen))
     self.lis.append(flat.Flat(640, 430, screen))
     self.lis.append(start.Start(75, 578, screen))
     if self.col_life == 3:
         self.lis.append(life.Life(230, 30, screen))
         self.lis.append(life.Life(130, 30, screen))
         self.lis.append(life.Life(30, 30, screen))
     elif self.col_life == 2:
         self.lis.append(life.Life(130, 30, screen))
         self.lis.append(life.Life(30, 30, screen))
     elif self.col_life == 1:
         self.lis.append(life.Life(30, 30, screen))
     self.lis.append(die_player.DPlayer(2000, 2000, screen))
     self.lis.append(green_door.GDoor(2000, 2000, screen))
     self.lis.append(door.Door(1350, 420, screen))
     self.lis.append(green_button.GreenButton(2000, 2000, screen))
     self.lis.append(red_button.RedButton(670, 381, screen))
     self.lis.append(player_class.Player(100, 415, screen))
Ejemplo n.º 10
0
 def __init__(self, screen, col_life):
     x = 0
     self.col_life = col_life
     y = 770
     self.lis = list()
     for i in range(16):
         self.lis.append(floor_class.Floor(x, y, screen))
         x += 75
     x -= 75
     self.lis.append(floor_class.Floor(x, 695, screen))
     self.lis.append(floor_class.Floor(x, 620, screen))
     self.lis.append(floor_class.Floor(x, 545, screen))
     for i in range(4):
         x += 75
         self.lis.append(floor_class.Floor(x, 545, screen))
     self.lis.append(fire.Fire(x - 10, 516, screen))
     self.lis.append(cube.Cube(250, 684, screen))
     self.lis.append(cube.Cube(336, 684, screen))
     self.lis.append(cube.Cube(422, 684, screen))
     self.lis.append(cube.Cube(508, 684, screen))
     self.lis.append(cube.Cube(336, 598, screen))
     self.lis.append(cube.Cube(422, 598, screen))
     self.lis.append(fire.Fire(700, 741, screen))
     self.lis.append(fire.Fire(771, 741, screen))
     self.lis.append(fire.Fire(862, 741, screen))
     self.lis.append(fire.Fire(933, 741, screen))
     self.lis.append(fire.Fire(1004, 741, screen))
     self.lis.append(start.Start(75, 748, screen))
     if self.col_life == 3:
         self.lis.append(life.Life(230, 30, screen))
         self.lis.append(life.Life(130, 30, screen))
         self.lis.append(life.Life(30, 30, screen))
     elif self.col_life == 2:
         self.lis.append(life.Life(130, 30, screen))
         self.lis.append(life.Life(30, 30, screen))
     elif self.col_life == 1:
         self.lis.append(life.Life(30, 30, screen))
     self.lis.append(shadow_block.SBlock(600, 500, screen))
     self.lis.append(shadow_block.SBlock(860, 400, screen))
     self.lis.append(die_player.DPlayer(2000, 2000, screen))
     self.lis.append(green_door.GDoor(2000, 2000, screen))
     self.lis.append(door.Door(1300, 356, screen))
     self.lis.append(green_button.GreenButton(2000, 2000, screen))
     self.lis.append(red_button.RedButton(620, 721, screen))
     self.lis.append(player_class.Player(100, 465, screen))
Ejemplo n.º 11
0
    def __init__(self, config, debugging=False):
        Utils.isDebugging = debugging
        self.config = config

        # read config
        c = self.config['site']
        self.port = c['port']
        self.port_secure = c['port_secure']

        c = self.config['config']
        self.use_https = c['use_https']
        self.use_auth = c['use_auth']
        self.use_alerts = c['use_alerts']
        self.motion_pin = c['motion_pin']
        self.file_name = "/var/log/%s.log" % (os.getcwd().split(os.sep)[-1])

        Utils.temperature_pin = c['temperature_pin']

        c = self.config['config']['times']
        self.time_to_close = c['to_close_door']
        self.time_to_open = c['to_open_door']
        self.time_to_report_open = c['to_report_open']
        self.time_to_report_still_open = c['to_report_still_open']
        self.time_to_force_close = c['to_force_close']

        c = self.config['alerts']
        self.when_opened = c['when_opened']
        self.when_closed = c['when_closed']
        self.on_days_of_week = c['on_days_of_week']
        self.from_time = c['from_time']
        self.to_time = c['to_time']
        self.alert_type = c['alert_type']

        c = self.config['mqtt']
        self.mqtt_server = c['server']
        self.mqtt_username = c['username']
        self.mqtt_password = c['password']

        c = self.config['mqtt']['topics']
        self.mqtt_topic_garage = c['garage']
        self.mqtt_topic_temperature = c['temperature']
        self.mqtt_topic_day_temperature = c['day_temperature']

        c = self.config['weatherapi']
        self.weather_url = c['url']
        self.weather_key = c['key']

        for arg in sys.argv:
            if str(arg) == 'debug':
                # ex. python controller.py debug -v
                Utils.isDebugging = True
                if self.time_to_report_open > 35:
                    self.time_to_report_open = 35
                self.time_to_report_still_open = 100
                Utils.gfileCache += "debug"

            if str(arg).startswith('port='):
                self.port = int((arg).split('=')[1])
                self.port_secure = self.port

        # set up fcache to log last time garage door was opened
        self.fileCache = FileCache(Utils.gfileCache, flag='cs')

        # set up logging
        log_fmt = '%(asctime)s %(levelname)-8s %(message)s'
        date_fmt = '%a, %m/%d/%y %H:%M:%S'
        log_level = logging.INFO

        if Utils.isDebugging:
            logging.basicConfig(datefmt=date_fmt,
                                format=log_fmt,
                                level=log_level)
            self.debugMsg = "Debugging=%s time_to_report_open=%d time_to_report_still_open %d gfileCache=%s" % (
                Utils.isDebugging, self.time_to_report_open,
                self.time_to_report_still_open, Utils.gfileCache)
        else:
            self.debugMsg = "Debugging=%s" % Utils.isDebugging
            logging.getLogger('mylogger').setLevel(logging.NOTSET)
            logging.basicConfig(datefmt=date_fmt,
                                format=log_fmt,
                                level=log_level,
                                filename=self.file_name)
            rotatingHandler = logging.handlers.RotatingFileHandler(
                self.file_name, maxBytes=5000000, backupCount=3)
            rotatingHandler.setLevel(log_level)
            rotatingHandler.setFormatter(logging.Formatter(log_fmt))
            logging.getLogger('mylogger').addHandler(rotatingHandler)

            gpio.setwarnings(False)
            gpio.cleanup()
            gpio.setmode(gpio.BCM)

        # Banner
        logging.info("<---Garage Controller starting (port=%s %s) --->" %
                     (self.port_secure, self.debugMsg))

        self.updateHandler = UpdateHandler(self)

        self.initMsg = ""

        # setup motion sensor
        if self.motion_pin != None and Utils.isDebugging != True:
            gpio.setup(self.motion_pin, gpio.IN)
            gpio.add_event_detect(self.motion_pin,
                                  gpio.RISING,
                                  callback=self.on_motion,
                                  bouncetime=300)
            logging.info("Motion pin = %s" % (self.motion_pin))

        # setup Doors from config file
        self.doors = [
            Doors.Door(x, c) for (x, c) in sorted(config['doors'].items())
        ]
        for door in self.doors:
            door.setup(gpio, self.get_time_since_last_open(door.id))
            self.set_initial_text_msg(door)

        # setup alerts
        if self.alert_type == 'smtp':
            self.use_smtp = False
            smtp_params = ("smtphost", "smtpport", "smtp_tls", "username",
                           "password", "to_email")
            self.use_smtp = ('smtp'
                             in config['alerts']) and set(smtp_params) <= set(
                                 config['alerts']['smtp'])
        elif self.alert_type == 'pushover':
            self.pushover_user_key = config['alerts']['pushover']['user_key']
            self.pushover_api_key = config['alerts']['pushover']['api_key']
        else:
            self.alert_type = None
            logging.info("No alerts configured")

        if Utils.isDebugging:
            print self.initMsg
        else:
            logging.info(self.initMsg)
            self.send_msg(self.initMsg)
Ejemplo n.º 12
0
    def __init__(self, player):
        """ Create level 2. """

        # Player start position
        self.posx = 290
        self.posy = 580

        # Call the parent constructor
        Level.__init__(self, player)

        # Door
        block = door.Door()
        block.rect.x = 522
        block.rect.y = 0
        block.player = self.player
        self.door_list.add(block)

        # Walls
        self.walls = [[wall.Wall(0), 58, 0], [wall.Wall(1), 116, 0],
                      [wall.Wall(1), 174, 0], [wall.Wall(1), 232, 0],
                      [wall.Wall(1), 290, 0], [wall.Wall(1), 348, 0],
                      [wall.Wall(1), 406, 0], [wall.Wall(1), 464, 0]]
        for w in self.walls:
            block = w[0]
            block.rect.x = w[1]
            block.rect.y = w[2]
            block.player = self.player
            self.walls_list.add(block)

        # Chest
        self.hearts_needed = 4
        block = chest.Chest(4)
        block.rect.x = 58
        block.rect.y = 348
        block.player = self.player
        self.chest_list.add(block)

        # Hearts
        self.hearts = [[heart.Heart(2), 116, 116], [heart.Heart(0), 580, 116],
                       [heart.Heart(0), 58, 638], [heart.Heart(0), 464, 522]]
        for h in self.hearts:
            block = h[0]
            block.rect.x = h[1]
            block.rect.y = h[2]
            block.player = self.player
            self.hearts_list.add(block)

        # Dragon
        #block = snake.Snake()
        #block.rect.x = 406
        #block.rect.y = 348
        #block.player = self.player
        #self.enemy_list.add(block)

        # Array with type of artifacts, and x, y location of them.
        level = [[artifact.Artifact("Assets/Rock.png", self), 348, 58],
                 [artifact.Artifact("Assets/Rock.png", self), 406, 58],
                 [artifact.Artifact("Assets/Rock.png", self), 464, 58],
                 [artifact.Artifact("Assets/Rock.png", self), 348, 116],
                 [artifact.Artifact("Assets/Rock.png", self), 406, 116],
                 [artifact.Artifact("Assets/Rock.png", self), 464, 116],
                 [artifact.Artifact("Assets/Rock.png", self), 348, 464],
                 [artifact.Artifact("Assets/Rock.png", self), 348, 522],
                 [artifact.Artifact("Assets/Rock.png", self), 406, 464],
                 [artifact.Artifact("Assets/Rock.png", self), 406, 522],
                 [artifact.Artifact("Assets/Tree.png", self), 174, 348],
                 [artifact.Artifact("Assets/Tree.png", self), 174, 406],
                 [artifact.Artifact("Assets/Tree.png", self), 232, 348],
                 [artifact.Artifact("Assets/Tree.png", self), 232, 406],
                 [artifact.Artifact("Assets/Tree.png", self), 464, 406],
                 [artifact.Artifact("Assets/Tree.png", self), 522, 406],
                 [artifact.Artifact("Assets/Tree.png", self), 464, 464],
                 [artifact.Artifact("Assets/Tree.png", self), 522, 464],
                 [artifact.Artifact("Assets/Tree.png", self), 406, 174],
                 [artifact.Artifact("Assets/Tree.png", self), 464, 174]]
        for a in level:
            block = a[0]
            block.rect.x = a[1]
            block.rect.y = a[2]
            block.player = self.player
            self.artifact_list.add(block)

        # Green blocks
        block = artifact.Artifact("Assets/Block.png", self, True)
        block.rect.x = 232  #406
        block.rect.y = 580
        block.player = self.player
        self.block_list.add(block)

        waters = [[water.Water(), 58, 232], [water.Water(), 116, 232],
                  [water.Water(), 174, 232], [water.Water(), 232, 232],
                  [water.Water(), 58, 290], [water.Water(), 116, 290],
                  [water.Water(), 174, 290], [water.Water(), 232, 290],
                  [water.Water(), 348, 232], [water.Water(), 406, 232],
                  [water.Water(), 464, 232], [water.Water(), 522, 232],
                  [water.Water(), 348, 290], [water.Water(), 406, 290],
                  [water.Water(), 464, 290], [water.Water(), 522, 290],
                  [water.Water(), 638, 232], [water.Water(), 638, 290],
                  [water.Water(), 638, 348], [water.Water(), 638, 406],
                  [water.Water(), 638, 464], [water.Water(), 638, 522],
                  [water.Water(), 638, 580], [water.Water(), 638, 638],
                  [water.Water(), 580, 638], [water.Water(), 522, 638],
                  [water.Water(), 464, 638], [water.Water(), 406, 638]]

        for w in waters:
            block = w[0]
            block.rect.x = w[1]
            block.rect.y = w[2]
            block.player = self.player
            self.water_list.add(block)

        bridges = [[bridge.Bridge("VERTICAL"), 290, 232],
                   [bridge.Bridge("VERTICAL"), 290, 290],
                   [bridge.Bridge("VERTICAL"), 580, 232],
                   [bridge.Bridge("VERTICAL"), 580, 290]]

        for b in bridges:
            block = b[0]
            block.rect.x = b[1]
            block.rect.y = b[2]
            block.player = self.player
            self.bridge_list.add(block)
Ejemplo n.º 13
0
    def __init__(self, player):
        """ Create level 1. """

        # Player start position
        self.posx = 58
        self.posy = 232

        # Call the parent constructor
        Level.__init__(self, player)

        # Door
        block = door.Door()
        block.rect.x = 348
        block.rect.y = 0
        block.player = self.player
        self.door_list.add(block)

        # Walls
        self.walls = [[wall.Wall(0), 58, 0], [wall.Wall(1), 116, 0],
                      [wall.Wall(1), 174, 0], [wall.Wall(1), 232, 0],
                      [wall.Wall(1), 290, 0], [wall.Wall(1), 522, 0],
                      [wall.Wall(1), 580, 0], [wall.Wall(1), 638, 0]]
        for w in self.walls:
            block = w[0]
            block.rect.x = w[1]
            block.rect.y = w[2]
            block.player = self.player
            self.walls_list.add(block)

        # Chest
        self.hearts_needed = 2
        block = chest.Chest(2)
        block.rect.x = 290
        block.rect.y = 580
        block.player = self.player
        self.chest_list.add(block)

        # Hearts
        self.hearts = [[heart.Heart(0), 290, 116], [heart.Heart(2), 638, 290]]
        for h in self.hearts:
            block = h[0]
            block.rect.x = h[1]
            block.rect.y = h[2]
            block.player = self.player
            self.hearts_list.add(block)

        # Snake
        block = snake.Snake(self.player, self)
        block.rect.x = 406
        block.rect.y = 348
        self.enemy_list.add(block)

        # Array with type of artifacts, and x, y location of them.
        level = [[artifact.Artifact("Assets/Rock.png", self), 58, 58],
                 [artifact.Artifact("Assets/Rock.png", self), 58, 116],
                 [artifact.Artifact("Assets/Rock.png", self), 116, 58],
                 [artifact.Artifact("Assets/Rock.png", self), 174, 58],
                 [artifact.Artifact("Assets/Rock.png", self), 232, 58],
                 [artifact.Artifact("Assets/Rock.png", self), 290, 58],
                 [artifact.Artifact("Assets/Rock.png", self), 348, 58],
                 [artifact.Artifact("Assets/Rock.png", self), 232, 116],
                 [artifact.Artifact("Assets/Rock.png", self), 232, 174],
                 [artifact.Artifact("Assets/Rock.png", self), 290, 174],
                 [artifact.Artifact("Assets/Rock.png", self), 348, 174],
                 [artifact.Artifact("Assets/Rock.png", self), 290, 232],
                 [artifact.Artifact("Assets/Rock.png", self), 348, 232],
                 [artifact.Artifact("Assets/Rock.png", self), 290, 290],
                 [artifact.Artifact("Assets/Rock.png", self), 348, 290],
                 [artifact.Artifact("Assets/Rock.png", self), 464, 58],
                 [artifact.Artifact("Assets/Rock.png", self), 464, 116],
                 [artifact.Artifact("Assets/Rock.png", self), 464, 174],
                 [artifact.Artifact("Assets/Rock.png", self), 464, 232],
                 [artifact.Artifact("Assets/Rock.png", self), 464, 290],
                 [artifact.Artifact("Assets/Rock.png", self), 522, 58],
                 [artifact.Artifact("Assets/Rock.png", self), 522, 116],
                 [artifact.Artifact("Assets/Rock.png", self), 522, 174],
                 [artifact.Artifact("Assets/Rock.png", self), 522, 232],
                 [artifact.Artifact("Assets/Rock.png", self), 522, 290],
                 [artifact.Artifact("Assets/Rock.png", self), 522, 348],
                 [artifact.Artifact("Assets/Rock.png", self), 580, 174],
                 [artifact.Artifact("Assets/Rock.png", self), 580, 232],
                 [artifact.Artifact("Assets/Rock.png", self), 58, 580],
                 [artifact.Artifact("Assets/Rock.png", self), 232, 580],
                 [artifact.Artifact("Assets/Rock.png", self), 58, 638],
                 [artifact.Artifact("Assets/Rock.png", self), 116, 638],
                 [
                     artifact.Artifact("Assets/Rock.png", self),
                     174,
                     638,
                 ], [artifact.Artifact("Assets/Rock.png", self), 232, 638],
                 [artifact.Artifact("Assets/Rock.png", self), 290, 638],
                 [artifact.Artifact("Assets/Rock.png", self), 348, 638],
                 [artifact.Artifact("Assets/Tree.png", self), 58, 464],
                 [artifact.Artifact("Assets/Tree.png", self), 58, 522],
                 [artifact.Artifact("Assets/Tree.png", self), 116, 116],
                 [artifact.Artifact("Assets/Tree.png", self), 116, 174],
                 [artifact.Artifact("Assets/Tree.png", self), 116, 406],
                 [artifact.Artifact("Assets/Tree.png", self), 116, 464],
                 [artifact.Artifact("Assets/Tree.png", self), 116, 522],
                 [artifact.Artifact("Assets/Tree.png", self), 116, 580],
                 [artifact.Artifact("Assets/Tree.png", self), 174, 116],
                 [artifact.Artifact("Assets/Tree.png", self), 174, 174],
                 [artifact.Artifact("Assets/Tree.png", self), 174, 232],
                 [artifact.Artifact("Assets/Tree.png", self), 174, 406],
                 [artifact.Artifact("Assets/Tree.png", self), 174, 464],
                 [artifact.Artifact("Assets/Tree.png", self), 174, 522],
                 [artifact.Artifact("Assets/Tree.png", self), 174, 580],
                 [artifact.Artifact("Assets/Tree.png", self), 232, 232],
                 [artifact.Artifact("Assets/Tree.png", self), 232, 464],
                 [artifact.Artifact("Assets/Tree.png", self), 232, 522],
                 [artifact.Artifact("Assets/Tree.png", self), 464, 464],
                 [artifact.Artifact("Assets/Tree.png", self), 464, 522],
                 [artifact.Artifact("Assets/Tree.png", self), 522, 464],
                 [artifact.Artifact("Assets/Tree.png", self), 522, 522],
                 [artifact.Artifact("Assets/Tree.png", self), 522, 580],
                 [artifact.Artifact("Assets/Tree.png", self), 580, 58],
                 [artifact.Artifact("Assets/Tree.png", self), 580, 116],
                 [artifact.Artifact("Assets/Tree.png", self), 580, 290],
                 [artifact.Artifact("Assets/Tree.png", self), 580, 522],
                 [artifact.Artifact("Assets/Tree.png", self), 580, 580],
                 [artifact.Artifact("Assets/Tree.png", self), 638, 58],
                 [artifact.Artifact("Assets/Tree.png", self), 638, 116],
                 [artifact.Artifact("Assets/Tree.png", self), 638, 174],
                 [artifact.Artifact("Assets/Tree.png", self), 638, 232]]
        for a in level:
            block = a[0]
            block.rect.x = a[1]
            block.rect.y = a[2]
            block.player = self.player
            self.artifact_list.add(block)
Ejemplo n.º 14
0
    def __init__(self, app, data, pos=(0, 0, 0), angle=0):
        self.app = app

        rads = angle / 57.3
        cos = math.cos(rads)
        sin = math.sin(rads)

        transform = pymunk.Transform(a=cos, b=-sin,
                                     c=sin, d=cos,
                                     tx=pos[0], ty=pos[2])

        f = pymunk.ShapeFilter(categories=physics.STATIC_FILTER)

        self.colliders = []
        for c in data['colliders']:
            vertices = zip(c[0][::2], c[0][1::2])
            collider = pymunk.Poly(self.app.physics.space.static_body,
                                   vertices=vertices,
                                   transform=transform)
            collider.y = pos[1] + c[1]
            collider.height = c[2]
            collider.collision_type = physics.STATIC
            collider.filter = f
            self.app.physics.space.add(collider)
            self.colliders.append(collider)

        for x, y, z in data['stairs']:
            stairs_x = pos[0] + (cos * x + sin * z)
            stairs_y = pos[1] + y
            stairs_z = pos[2] + (-sin * x + cos * z)
            d = stairs.Staircase(self.app,
                                 pos=(stairs_x, stairs_y, stairs_z),
                                 angle=angle)
            self.app.game_manager.game_objects.add(d)
            self.app.renderer.scene.add(d.canvas)

        self.doors = []
        for x, y, z in data['doors']:
            door_x = pos[0] + (cos * x + sin * z)
            door_y = pos[1] + y
            door_z = pos[2] + (-sin * x + cos * z)
            d = door.Door(self.app,
                          pos=(door_x, door_y, door_z),
                          angle=angle)
            self.doors.append(d)
            self.app.game_manager.game_objects.add(d)
            self.app.renderer.scene.add(d.canvas)

        self.canvas = Canvas()
        with self.canvas:
            PushMatrix()

            Color(1, 1, 1)
            self.pos = Translate(*pos)
            Rotate(angle, 0, 1, 0)

            self.app.graphic_data.draw_mesh(data['mesh_name'],
                                            self.canvas,
                                            texture=data['texture'])

            PopMatrix()
Ejemplo n.º 15
0
                                y=viewport.window.height,
                                font_size=32,
                                batch=hud_batch)

lives_label = pyglet.text.Label(text='Lives:',
                                anchor_x='right',
                                anchor_y='top',
                                x=viewport.window.width,
                                y=viewport.window.height,
                                font_size=32,
                                batch=hud_batch)

game_over_label = pyglet.text.Label(text='GAME OVER',
                                    anchor_x='center',
                                    anchor_y='center',
                                    x=viewport.h_ctr,
                                    y=-300,
                                    font_size=72,
                                    batch=hud_batch)

win_label = pyglet.text.Label(text="You Won!!!!",
                              anchor_x='center',
                              anchor_y='center',
                              x=viewport.h_ctr,
                              y=-300,
                              font_size=72,
                              batch=hud_batch)

d = door.Door()
d.batch = hud_batch