Ejemplo n.º 1
0
def main():
    """メインルーチン"""
    rect = Rect(0, 600, 10, 10)
    velocity = [5, -20]
    accel = (0, 0.5)
    while True:
        for event in pygame.event.get():
            if event.type == QUIT:
                pygame.quit()
                sys.exit()


        SURFACE.fill((0, 0, 0))
        velocity[1] += accel[1];
        rect.move_ip(velocity)


        if rect.x > 600:
            rect.x = 0
        if rect.y > 600:
            velocity[1] = -20


        pygame.draw.rect(SURFACE, (255, 255, 255), rect)

        pygame.display.update()
        FPSCLOCK.tick(10)
Ejemplo n.º 2
0
def main():
    """メインルーチン"""
    rect = Rect(0, 0, 10, 10)  # 初期位置、大きさの設定
    velocity = (5, 2)
    while True:
        for event in pygame.event.get():
            if event.type == QUIT:
                pygame.init()
                sys.exit()

        SURFACE.fill((0, 0, 0))
        rect.move_ip(velocity)  # 移動
        if rect.x > 600:
            rect.x = 0
        if rect.y > 600:
            rect.y = 0

        pygame.draw.rect(SURFACE, (255, 255, 255), rect)

        pygame.display.update()
        FPSCLOCK.tick(10)
Ejemplo n.º 3
0
    def create_image(self, rect_camera_map):
        # pre: rect_image must be created <TILE_SIZE*rows>X<TILE_SIZE*columns>
        assert self.is_map_loaded, "There's no map loaded yet!"

        image_map_tile = pygame.Surface(rect_camera_map.size, SRCALPHA)

        n_rows = rect_camera_map.height // self.tile_size
        n_columns = rect_camera_map.width // self.tile_size

        i_init_matriz = rect_camera_map.y // self.tile_size
        j_init_matriz = rect_camera_map.x // self.tile_size

        src_srfc_tile_rect = Rect(0, 0, self.tile_size, self.tile_size)

        for i in range(n_rows):

            i_matrix = i_init_matriz + i
            if i_matrix >= self.n_rows:
                continue

            for j in range(n_columns):

                j_matrix = j_init_matriz + j

                if j_matrix >= self.n_cols:
                    continue

                tile_index = self.matrix_tiles[i_matrix][j_matrix]

                if tile_index != 0:
                    src_srfc_tile_rect.x = self.tile_size * (tile_index - 1)
                    image_map_tile.blit(self.tileset_surface, (
                        (j_matrix - j_init_matriz) * self.tile_size, (i_matrix - i_init_matriz) * self.tile_size),
                                        src_srfc_tile_rect)

        return image_map_tile