Esempio n. 1
0
 def get_hat_direction(self, player):
     """Get direction from current key state."""
     factors = xytuple(*self.hat_factors)
     try:
         return factors * self.joysticks[player - 1].get_hat(0)
     except (IndexError, pg.error):
         return factors * (0, 0)
Esempio n. 2
0
 def get_hat_direction(self, player):
     """Get direction from current key state."""
     factors = xytuple(*self.hat_factors)
     try:
         return factors * self.joysticks[player-1].get_hat(0)
     except (IndexError, pg.error):
         return factors * (0, 0)
Esempio n. 3
0
 def init(self):
     """Initialize the joysticks."""
     # Init joystick
     pg.joystick.quit()
     pg.joystick.init()
     # Get joysticks
     self.joysticks = []
     for i in range(pg.joystick.get_count()):
         self.joysticks.append(pg.joystick.Joystick(i))
         self.joysticks[-1].init()
     # Players
     self.nb_players = max(pid for _, pid in self.key_dct.values())
     self.nb_players = max(self.nb_players, len(self.joysticks))
     self.players = range(1, self.nb_players + 1)
     # Init direction
     for player in self.players:
         lst = [self.get_key_direction(player),
                self.get_axis_direction(player),
                self.get_hat_direction(player)]
         iterator = (direction for direction in lst if any(direction))
         direction = next(iterator, xytuple(0,0))
         if self.dir_action in self.special_actions:
             self.register(self.dir_action, direction, player, False)
         if self.hdir_action in self.special_actions:
             self.register(self.hdir_action, direction.x, player, False)
         if self.dir_action in self.special_actions:
             self.register(self.vdir_action, direction.y, player, False)
     # Special keys
     dct = pg.key.get_pressed()
     special_keys = (key for key, value in self.key_dct.items()
                     if value[0] in self.special_actions)
     for key in special_keys:
         if dct[key]:
             self.register_key(key, dct[key], filter=False)
Esempio n. 4
0
 def get_axis_direction(self, player):
     """Get direction from current key state."""
     factors = xytuple(*self.axis_factors)
     try:
         raw_values = [self.joysticks[player - 1].get_axis(i) for i in (0, 1)]
     except (IndexError, pg.error):
         raw_values = 0, 0
     return factors * list(map(self.axis_position, raw_values))
Esempio n. 5
0
 def get_axis_direction(self, player):
     """Get direction from current key state."""
     factors = xytuple(*self.axis_factors)
     try :
         raw_values = [self.joysticks[player-1].get_axis(i) for i in (0,1)]
     except (IndexError, pg.error):
         raw_values = 0,0
     return factors * map(self.axis_position, raw_values)
Esempio n. 6
0
 def size(self):
     margins = xytuple(self.margins) * (2, 2)
     try:
         rects = list(self.rect_dict.values())
         rect = rects[0].unionall(rects[1:])
         return margins + rect.size
     except (IndexError, AttributeError):
         return margins
Esempio n. 7
0
 def size(self):
     margins = xytuple(self.margins) * (2, 2)
     try:
         rects = self.rect_dict.values()
         rect = rects[0].unionall(rects[1:])
         return margins + rect.size
     except (IndexError, AttributeError):
         return margins
Esempio n. 8
0
 def update(self):
     self.rect_dict = {}
     # Get rects
     for sprite in self.group:
         rect = sprite.get_max_rect()
         pos = xytuple(self.interlines)
         pos += 0, rect.h
         pos *= (sprite.model.pos, ) * 2
         setattr(rect, self.reference, pos)
         self.rect_dict[sprite.model.pos] = rect
     # Move rects
     if not self.rect_dict:
         return
     x = min(rect.x for rect in list(self.rect_dict.values()))
     y = min(rect.y for rect in list(self.rect_dict.values()))
     for rect in list(self.rect_dict.values()):
         rect.move_ip(xytuple(self.margins) - (x, y))
Esempio n. 9
0
 def update(self):
     self.rect_dict = {}
     # Get rects
     for sprite in self.group:
         rect = sprite.get_max_rect()
         pos = xytuple(self.interlines)
         pos += 0, rect.h
         pos *= (sprite.model.pos,) * 2
         setattr(rect, self.reference, pos)
         self.rect_dict[sprite.model.pos] = rect
     # Move rects
     if not self.rect_dict:
         return
     x = min(rect.x for rect in self.rect_dict.values())
     y = min(rect.y for rect in self.rect_dict.values())
     for rect in self.rect_dict.values():
         rect.move_ip(xytuple(self.margins) - (x, y))
Esempio n. 10
0
 def get_key_direction(self, player):
     """Get direction from current key state."""
     dct = pg.key.get_pressed()
     gen = (
         direc
         for key, (direc, play) in list(self.dir_dct.items())
         if play == player and dct[key]
     )
     return sum(gen, xytuple(0, 0))
Esempio n. 11
0
 def get_child_pos(self, lid):
     previous = self.lines[lid - 1] if lid else None
     interline = xytuple(0, self.interline)
     # Left aligment
     if self.alignment == "left":
         if previous:
             return interline + previous.bottomleft
         return self.margins
     # Centered aligment
     if self.alignment == "center":
         if previous:
             return interline + previous.midbottom
         return xytuple(self.margins) + (self.max_width / 2, 0)
     # Right aligment
     if self.alignment == "right":
         if previous:
             return interline + previous.bottomright
         return xytuple(self.margins) + (self.max_width, 0)
Esempio n. 12
0
 def init(self):
     """Initialize the joysticks."""
     # Init joystick
     pg.joystick.quit()
     pg.joystick.init()
     # Get joysticks
     self.joysticks = []
     for i in range(pg.joystick.get_count()):
         self.joysticks.append(pg.joystick.Joystick(i))
         self.joysticks[-1].init()
     # Players
     self.nb_players = max(pid for _, pid in list(self.key_dct.values()) if pid is not None)
     self.nb_players = max(self.nb_players, len(self.joysticks))
     self.players = list(range(1, self.nb_players + 1))
     # Init direction
     for player in self.players:
         lst = [
             self.get_key_direction(player),
             self.get_axis_direction(player),
             self.get_hat_direction(player),
         ]
         iterator = (direction for direction in lst if any(direction))
         direction = next(iterator, xytuple(0, 0))
         if self.dir_action in self.special_actions:
             self.register(self.dir_action, direction, player, False)
         if self.hdir_action in self.special_actions:
             self.register(self.hdir_action, direction.x, player, False)
         if self.dir_action in self.special_actions:
             self.register(self.vdir_action, direction.y, player, False)
     # Special keys
     dct = pg.key.get_pressed()
     special_keys = (
         key
         for key, value in list(self.key_dct.items())
         if value[0] in self.special_actions
     )
     for key in special_keys:
         if dct[key]:
             self.register_key(key, dct[key], filter=False)
Esempio n. 13
0
 def size(self):
     return xytuple(self._width, self._height)
Esempio n. 14
0
 def get_key_direction(self, player):
     """Get direction from current key state."""
     dct = pg.key.get_pressed()
     gen = (direc for key, (direc, play) in self.dir_dct.items()
            if play == player and dct[key])
     return sum(gen, xytuple(0,0))
Esempio n. 15
0
 def size(self):
     return xytuple(self._width, self._height)
Esempio n. 16
0
 def size(self):
     if not self.size_ratio:
         return xytuple(*self.image.get_size())
     return (self.settings.size * self.size_ratio).map(int)
Esempio n. 17
0
 def size(self):
     return xytuple(*self.image.get_size())
Esempio n. 18
0
 def size(self):
     if not self.group:
         return xytuple(0, 0)
     x = max(sprite.rect.right for sprite in self.group)
     y = max(sprite.rect.bottom for sprite in self.group)
     return xytuple(x, y) + self.margins
Esempio n. 19
0
 def size(self):
     if not self.size_ratio:
         return xytuple(*self.image.get_size())
     return (self.settings.size * self.size_ratio).map(int)
Esempio n. 20
0
 def convert_position(self, pos):
     new_pos = xytuple(pos) - self.rect.topleft
     new_pos *= self.view.screen_size
     return new_pos / self.size
Esempio n. 21
0
 def screen_size(self):
     if self.size is None:
         return xytuple(self.screen.get_size())
     return xytuple(self.size)
Esempio n. 22
0
 def size(self):
     return xytuple(*self.image.get_size())
Esempio n. 23
0
 def convert_position(self, pos):
     new_pos = xytuple(pos) - self.rect.topleft
     new_pos *= self.view.screen_size
     return new_pos / self.size
Esempio n. 24
0
 def screen_size(self):
     if self.size is None:
         return xytuple(self.screen.get_size())
     return xytuple(self.size)