示例#1
0
 def __init__(self, settings):
     super().__init__(settings)
     self.img_field = Image({
         'position': (0, 0),
         'path': 'static/field',
     })
     self.img_next = Image({
         'position': (300, 77),
         'path': 'static/next',
     })
     self.img_hold = Image({
         'position': (450, 77),
         'path': 'static/hold',
     })
     self.txt_score = Text({
         'position': (300, 300),
         'text': 'Score: 0',
     })
     self.current = pygame.Surface(
         (BOARD_SIZE[0] * TILE, BOARD_SIZE[1] * TILE))
     self.base = Base()
     self.figure = Figure()
     self.next = Figure()
     self.hold = None
     self.hold_first = True
     self.score = 0
     self.state = '__WAIT__'
     self.field = [[0 for _ in range(BOARD_SIZE[0])]
                   for _ in range(BOARD_SIZE[1])]
示例#2
0
 def start(self):
     self.base = Base()
     self.figure = Figure()
     self.next = Figure()
     self.hold = None
     self.score = 0
     self.txt_score.set_text('Score: 0')
     self.state = '__GAME__'
     self.field = [[0 for _ in range(BOARD_SIZE[0])]
                   for _ in range(BOARD_SIZE[1])]
示例#3
0
def validate_args(args):
    if args.path is None:
        print(f'{argparser.prog}: No filepath was supplied.', file=sys.stderr)
        parser.print_help()
        sys.exit()

    csvparser = CSVParser(args)
    wpms, accuracies, dates, count = csvparser.parse()
    figure = Figure(count=count, file=args.file, dates=dates)
    figure.plot(wpms, accuracies)
示例#4
0
 def show(self, surf):
     if self.state == '__GAME__':
         if self.figure.state == '__STOP__':
             if self.figure.can_move(self, (0, 1)):
                 self.figure.state = '__FALLING__'
             else:
                 self.hold_first = True
                 for block in self.figure.blocks:
                     self.set(block.position, 1)
                 deleted = []
                 self.base.add_blocks(self.figure)
                 for i in range(len(self.field)):
                     if all([
                             self.get((k, i))
                             for k in range(len(self.field[i]))
                     ]):
                         for row in range(i, 0, -1):
                             self.field[row] = self.field[row - 1]
                         deleted.append(i)
                         self.field[0] = [0 for _ in range(BOARD_SIZE[0])]
                 self.base.set_deleted(deleted)
                 if any([i == 1 for i in self.field[0]]):
                     self.state = '__LOSE__'
                     config.UPDATER.send_result(self.score)
                     if config.NICKNAME:
                         rating = config.WINDOW.get('txtRating')
                         rating.set_text(int(rating.text) + self.score)
                         best = config.WINDOW.get('txtBest')
                         best.set_text(max(int(best.text), self.score))
                 self.score += 2**len(deleted) if deleted else 0
                 self.txt_score.set_text('Score: ' + str(self.score))
                 self.figure = self.next
                 self.next = Figure()
     self.current.fill(BACKGROUND)
     self.img_field.show(self.current)
     if self.state == '__GAME__':
         self.figure.show(self.current)
     self.base.show(self.current)
     self.img_next.show(surf)
     self.img_hold.show(surf)
     if self.hold and self.state == '__GAME__':
         self.hold.static_show(surf, self.img_hold)
     if self.state == '__GAME__':
         self.next.static_show(surf, self.img_next)
     self.txt_score.show(surf)
     surf.blit(self.current, self.position)
示例#5
0
    def create_mane(self, data):
        self.hairs = Figure()

        hair_top = Ball(self.head - (-10, 5, 0), 8, None)
        hair_top.move_to_sphere(self.head)
        hair_bottom = Ball(self.shoulder - (-10, 15, 0), 8, None)
        hair_bottom.move_to_sphere(self.shoulder)
        for start, gamma, length, angle, lightness, straightness in zip(
                data.hair_starts, data.hair_gammas, data.hair_lengths,
                data.hair_angles, data.hair_tip_lightnesses,
                data.hair_straightnesses):
            x, y, z = (c[0] + start / 100.0 * (c[1] - c[0])
                       for c in zip(hair_top.center, hair_bottom.center))
            hair_start = Ball((x, y, z), 8, data.hair_col(60))
            hair_end = Ball((x + length, y, z + straightness), 4,
                            data.hair_col(lightness))
            hair_end.rotate(-angle, hair_start)
            hair = NonLinBone(hair_start, hair_end, yfunc=gammafunc(gamma))
            self.hairs.add(hair)
示例#6
0
 def key_down(self, key):
     if key == pygame.K_a:
         if self.figure.can_move(self, (-1, 0)):
             self.figure.move((-1, 0))
     elif key == pygame.K_d:
         if self.figure.can_move(self, (1, 0)):
             self.figure.move((1, 0))
     elif key == pygame.K_q:
         if self.figure.can_rotate(self, 3):
             self.figure.rotate(3)
     elif key == pygame.K_e:
         if self.figure.can_rotate(self, 1):
             self.figure.rotate(1)
     elif key == pygame.K_w:
         if not self.hold:
             if self.hold_first:
                 self.hold = self.figure.copy()
                 self.figure = Figure()
                 self.hold_first = False
         else:
             self.figure = self.hold.copy()
             self.hold = None
     elif key == pygame.K_n:
         self.start()