summaryrefslogtreecommitdiff
path: root/src/helper.py
blob: 46f831a240d8794c1b0468c6cf3b3861109f40a3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
from blocks import blocks
import pygame
from math import floor
from sys import platform
from pathlib import Path
import os

texture_map = pygame.image.load('./assets/textures/texture_atlas.png')
controls_map = pygame.image.load('./assets/textures/controls.png')

def get_data_path():
    path = str(Path.home()) + "/.blocks"

    if platform == "darwin":
        path = str(Path.home()) + "/Library/Application Support/Blocks"
    elif platform == "win32":
        path = str(Path.home()).replace("\\", "/") + "/.blocks"

    if not os.path.exists(path):
        os.mkdir(path)

    if not os.path.exists(path + "/saves"):
        os.mkdir(path + "/saves")

    if not os.path.exists(path + "/crash_reports"):
        os.mkdir(path + "/crash_reports")

    return path

def transparent(surface, percentage):
    screen = pygame.Surface((1280, 720))
    screen.fill("black")
    screen.blit(surface, (0, 0))

    surface2 = pygame.Surface((1280, 720))
    surface2.fill((0, 0, 0, 255*(1-percentage)))
    screen.blit(pygame.Surface.convert_alpha(surface2), (0, 0))

    return screen

def text(text, size, color):
    return pygame.Surface.convert_alpha(pygame.font.Font("./assets/font/main.ttf", size).render(text, False, color))

def get_block_texture(block):
    return blocks[block]['texture']

def draw_texture(id):
    if id < 10:
        pos = (42 * id, 0)
    else:
        pos = (42 * (id - (floor(((id + 1) / 10) - 1) * 10)), 42 * (floor(((id + 1) / 10) - 1)))

    return texture_map.subsurface((pos[0], pos[1], 42, 42))

def draw_control(id):
    if id < 10:
        pos = (17 * id, 0)
    else:
        pos = (17 * (id - (floor(((id + 1) / 10) - 1) * 10)), 17 * (floor(((id + 1) / 10) - 1)))

    return pygame.Surface.convert_alpha(controls_map.subsurface((pos[0], pos[1], 17, 17)))

def get_chunk_regions(chunks):
    data = []

    for x in range(len(chunks)):
        for y in range(len(chunks)):
            data.append({
                "file": str(x) + "," + str(y) + ".bcr",
                "range": (16 * x, 16 * y, 15 + 16 * x, 15 + 16 * y)
            })

    return data