예제 #1
0
파일: groups.py 프로젝트: Fluxanoia/Chessr
 def set_position(self, xy, preserve_tween=False):
     self._position = xy
     layer = self.layer_transform(xy)
     xy = self.position_transform(xy)
     if self.alive():
         instance(Groups).get_group(self._group).change_layer(self, layer)
     self.rect.x, self.rect.y = xy[0], xy[1]
     if not preserve_tween:
         self._position_tween = None
예제 #2
0
파일: groups.py 프로젝트: Fluxanoia/Chessr
    def __init__(self, xy, srcrect=None):
        super().__init__()
        self.dirty = 2
        self.srcrect = srcrect
        instance(Groups).get_group(self._group).add(self)

        size = self.image.get_size(
        ) if self.srcrect is None else self.source_rect.size
        self.rect = pg.Rect((0, 0), size)
        self.set_position(xy)

        self._position_tween = None
예제 #3
0
 def __init__(self, xy, scale):
     self.__type = ShadowType.DARK
     self.group = GroupType.SHADOW
     self.scale = scale
     self.image = instance(Spritesheet).get_image(
         Spritesheet.get_shadow_srcrect(self.__type, scale), scale)
     super().__init__(xy)
예제 #4
0
 def __get_all_moves(self, gxy):
     logic = instance(Logic)
     board = SimpleBoard(self)
     moves, challenges = logic.get_move_and_challenge_cells(board, gxy)
     special = logic.get_special_manoeuvres(board, gxy)
     return {
         Controller.MOVE_KEY: moves,
         Controller.CHALLENGE_KEY: challenges,
         Controller.SPECIAL_KEY: special,
     }
예제 #5
0
파일: logic.py 프로젝트: Fluxanoia/Chessr
 def __str__(self):
     s = ""
     for i in range(self.__height):
         for j in range(self.__width):
             piece = self.__board[i][j]
             if piece is not None:
                 piece = piece.get_piece()
             c = '-' if piece is None else instance(Logic).get_char(piece)
             s += c + ' '
         s += '\n'
     return s
예제 #6
0
    def start(self):
        self.__width, self.__height = 0, 0

        def side(c):
            if c == 'w':
                return Side.FRONT
            if c == 'b':
                return Side.BACK
            raise Exception("Incorrect board format.")

        data = {}
        logic = instance(Logic)
        for key, value in instance(FileManager).load_board(
                "default.board").items():
            if key == "w":
                self.__width = int(value)
            elif key == "h":
                self.__height = int(value)
            elif len(key) == 2:

                def get_coord(c):
                    return logic.get_coordinate(c, self.__height)

                coords = tuple(map(get_coord, value.split(' ')))
                data[(side(key[0]), logic.get_piece(key[1]))] = coords

        sw, sh = instance(Globals).get_window_size()
        cell_size = Spritesheet.BOARD_WIDTH * self.__board.get_cell_scale()
        self.__x_offset = (sw - cell_size * self.__width) / 2
        self.__y_offset = (sh - cell_size * self.__height) / 2

        self.reset_board()

        def colour(side):
            return (PieceColour.BLACK,
                    PieceColour.WHITE)[int(side == Side.FRONT)]

        for key, values in data.items():
            s, p = key
            for (i, j) in values:
                self.__cells[i][j].place_piece(colour(s), p, s)
예제 #7
0
    def __init__(self, gxy, xy, colour, _type, scale, child_scale):
        self.__colour = colour
        self.__type = _type

        self.group = GroupType.BOARD
        self.scale = scale
        self.image = instance(Spritesheet).get_sheet(self._scale)
        super().__init__(xy, self.get_srcrect())

        self.__grid_position = gxy
        self.__selected = False
        self.__fallback_type = None

        self.__child_scale = child_scale
        self.__piece = Piece(self)
예제 #8
0
    def __init__(self, cell):
        self.__cell = cell
        self.__colour = 0
        self.__type = 0
        self.__side = 0
        self.__tags = set()

        self.group = GroupType.PIECE
        self.scale = cell.get_child_scale()
        self.image = instance(Spritesheet).get_sheet(self._scale)

        xy = cell.get_piece_position()
        self.__lift = 0
        self.__lift_tween = None
        self.__shadow = Shadow(xy, self._scale)
        self.update_shadow_alpha()
        super().__init__(xy, self.get_srcrect())

        self.set_active(False)
예제 #9
0
 def __get_collision(self, pos):
     for s in reversed(instance(Groups).get_sprites(GroupType.BOARD)):
         if s.collidepoint(pos):
             return s.get_grid_position()
     return None
예제 #10
0
 def __init__(self, text, xy, scale):
     self.group = GroupType.UI
     self.scale = scale
     font = instance(FileManager).load_default_font(8 * scale)
     self.image = font.render(text, True, (255, 255, 255))
     super().__init__(xy)
예제 #11
0
 def __init__(self):
     super().__init__()
     self.__sheets = { "1" : instance(FileManager).load_image("sprites.png", True) }