Ejemplo n.º 1
0
 def move_board(self, direction, speed=11):
     self.pan[0] = utils.min_max(self.pan[0] - speed * direction[0],
                                 -self.size(0) // 2,
                                 self.size(0) // 2)
     self.pan[1] = utils.min_max(self.pan[1] - speed * direction[1],
                                 -self.size(1) // 2,
                                 self.size(1) // 2)
Ejemplo n.º 2
0
 def move_board(self, direction=(0, 0), step=11):
     step = (-step, -step)
     self.pan = (self.pan[0] + step[0] * direction[0],
                 self.pan[1] + step[1] * direction[1])
     self.pan = (utils.min_max(self.pan[0], -self.total_size[0] // 2,
                               self.total_size[0] // 2),
                 utils.min_max(self.pan[1], -self.total_size[1] // 2,
                               self.total_size[1] // 2))
Ejemplo n.º 3
0
 def focus_board(self, grid):
     grid_pos = utils.add(
         self.get(grid).get_rect()[0], (self.grid_size // 2, grid[1] // 2))
     self.pan = list(
         utils.add(self.args.get_pos(1, 1), utils.negative(self.pos),
                   utils.negative(grid_pos)))
     self.pan[0] = utils.min_max(self.pan[0], -self.size(0) // 2,
                                 self.size(0) // 2)
     self.pan[1] = utils.min_max(self.pan[1], -self.size(1) // 2,
                                 self.size(1) // 2)
Ejemplo n.º 4
0
 def process_right_click(self, mouse_pos):
     for name in self.buttons:
         if self.buttons[name].in_range(mouse_pos):
             target_turn = utils.min_max(
                 eval(f'{self.map.turn} {name[4:]} 10'), self.min_turn,
                 self.max_turn)
             return ['turn', target_turn]
     return [None]
Ejemplo n.º 5
0
    def generate_apples(self, players, num=None):
        # recalculate num
        if num is None:
            num = self.max_apples - len(self.apples)
        empty = self.get_empty(players)
        num = utils.min_max(num, 0, len(empty))
        if num == 0:
            return

        # generate apples
        new_apple_grids = choices(empty, k=num)
        for grid in new_apple_grids:
            self.apples.append(grid)
Ejemplo n.º 6
0
    def process_events(self, events):
        commands = {'move-board': [0, 0], 'turn': self.map.turn, 'speed': 0, 'pause': False}

        # key events
        for key in events['key-pressed']:
            if key == 'w':
                commands['move-board'][1] -= 1
            elif key == 'a':
                commands['move-board'][0] -= 1
            elif key == 's':
                commands['move-board'][1] += 1
            elif key == 'd':
                commands['move-board'][0] += 1
        for key in events['key-down']:
            if key == 'up':
                commands['turn'] -= 10
            elif key == 'left':
                commands['turn'] -= 1
            elif key == 'down':
                commands['turn'] += 10
            elif key == 'right':
                commands['turn'] += 1
            elif key == '-':
                commands['speed'] -= 1
            elif key == '=':
                commands['speed'] += 1
            elif key == 'space':
                commands['pause'] = True
        commands['turn'] = utils.min_max(commands['turn'], self.min_turn, self.max_turn)
        commands['speed'] = {0: None, -1: '-', 1: '+'}[commands['speed']]

        # mouse events
        if events['mouse-left'] == 'down':
            self.map.cursor = self.map.pos_to_cord(events['mouse-pos'])

        return commands
Ejemplo n.º 7
0
def multiply(color, num):
    return rgb(*[utils.min_max(c * num, 0, 255) for c in color])
Ejemplo n.º 8
0
def add(color, num):
    return rgb(*[utils.min_max(c + num, 0, 255) for c in color])
Ejemplo n.º 9
0
def multiply(color, num):
    return tuple((utils.min_max(color[i] * num, 0, 255)) for i in (0, 1, 2))
Ejemplo n.º 10
0
def add(color, num):
    return tuple((utils.min_max(color[i] + num, 0, 255)) for i in (0, 1, 2))