master
parent
4720ca3c0c
commit
c436594f71
Binary file not shown.
After Width: | Height: | Size: 13 KiB |
Binary file not shown.
After Width: | Height: | Size: 134 KiB |
45
main.py
45
main.py
|
@ -13,13 +13,13 @@ FPS = 60
|
|||
|
||||
MAIN_PATH = "C:/Users/User/Documents/Coding/Picture Puzzle/"
|
||||
#School: MAIN_PATH = "C:/Users/RVKG/Documents/My Palettes/Picture Puzzle/"
|
||||
IMAGES_PATH = "/images/albums/"
|
||||
IMAGES_PATH = "images/albums/"
|
||||
SIZE_PATH = "images/assets/"
|
||||
|
||||
DATA_FILE = "main_data.json"
|
||||
PUZZLE_FILE = "main_puzzle.json"
|
||||
SETTINGS_FILE = "main_settings.json"
|
||||
STATS_FILE = "main_stats.json"
|
||||
SIZE_PATH = "images/assets/"
|
||||
|
||||
# Data loading and saving
|
||||
def load_data(data):
|
||||
|
@ -49,17 +49,17 @@ if settings_data["style"] == STYLE_CHOICES[0]:
|
|||
FONT = FONTS[0]
|
||||
STYLE_PATH = "1_"
|
||||
text_color = (1, 35, 61)
|
||||
timer_color = (255, 255, 255)
|
||||
oposite_color = (255, 255, 255)
|
||||
elif settings_data["style"] == STYLE_CHOICES[1]:
|
||||
FONT = FONTS[1]
|
||||
STYLE_PATH = "2_"
|
||||
text_color = (255, 255, 255)
|
||||
timer_color = (70, 35, 0)
|
||||
oposite_color = (70, 35, 0)
|
||||
else:
|
||||
FONT = FONTS[2]
|
||||
STYLE_PATH = "3_"
|
||||
text_color = (255, 255, 255)
|
||||
timer_color = text_color
|
||||
oposite_color = text_color
|
||||
|
||||
if settings_data["size"] == SIZE_CHOICES[0]:
|
||||
WIDTH, HEIGHT = 144, 154
|
||||
|
@ -77,6 +77,7 @@ if settings_data["size"] == SIZE_CHOICES[0]:
|
|||
size = [20, 25, 100, 15]
|
||||
cons = [15, 195, 12, 3, 9]
|
||||
scaled_size = (18, 21, 108, 108)
|
||||
area = (72 , 142)
|
||||
|
||||
elif settings_data["size"] == SIZE_CHOICES[1]:
|
||||
WIDTH, HEIGHT = 202, 216
|
||||
|
@ -94,12 +95,13 @@ elif settings_data["size"] == SIZE_CHOICES[1]:
|
|||
size = [30, 35, 110, 25]
|
||||
cons = [25, 247, 18, 3, 13]
|
||||
scaled_size = (22, 26, 158, 158)
|
||||
area = (100, 200)
|
||||
|
||||
else:
|
||||
WIDTH, HEIGHT = 396, 425
|
||||
INT = 2
|
||||
if FONT == FONTS[0]:
|
||||
FONT_SIZE = 27
|
||||
FONT_SIZE = 24
|
||||
elif FONT == FONTS[1]:
|
||||
FONT_SIZE = 22
|
||||
elif FONT == FONTS[2]:
|
||||
|
@ -111,6 +113,7 @@ else:
|
|||
size = [50, 55, 120, 35]
|
||||
cons = [35, 455, 25, 13, 26]
|
||||
scaled_size = (43, 48, 310, 310)
|
||||
area = (197, 390)
|
||||
|
||||
puzzle_version = settings_data["grid"]
|
||||
|
||||
|
@ -266,9 +269,14 @@ def set_shadow_style(hwnd):
|
|||
print(e)
|
||||
|
||||
# Text render
|
||||
def render_text(text, position, screen, color=text_color):
|
||||
def render_text(text, position, screen, color=text_color, centered=False):
|
||||
font = pygame.font.SysFont(FONT, FONT_SIZE)
|
||||
text_render = font.render(text, True, color)
|
||||
|
||||
if centered:
|
||||
text_rect = text_render.get_rect(center=position)
|
||||
screen.blit(text_render, text_rect.topleft)
|
||||
else:
|
||||
screen.blit(text_render, position)
|
||||
|
||||
# MENU MODE
|
||||
|
@ -357,18 +365,21 @@ class ImageRender:
|
|||
self.scaled_image = pygame.transform.scale(selected_image, (self.scaled_size[2], self.scaled_size[3]))
|
||||
current_img = self.current
|
||||
current_album = self.album_name
|
||||
self.num_images = len(storage["albums"][self.album_name])
|
||||
self.current_text = f"{self.index+1} of {self.num_images}"
|
||||
|
||||
|
||||
def render(self, screen):
|
||||
screen.blit(self.scaled_image, (self.scaled_size[0], self.scaled_size[1]))
|
||||
render_text(self.current_text, (area[0], area[1]), screen, oposite_color, True)
|
||||
pygame.display.flip()
|
||||
|
||||
def update_index(self, increment):
|
||||
self.index += increment
|
||||
num_images = len(storage["albums"][self.album_name])
|
||||
if self.index >= num_images:
|
||||
if self.index >= self.num_images:
|
||||
self.index = 0
|
||||
elif self.index < 0:
|
||||
self.index = num_images - 1
|
||||
self.index = self.num_images - 1
|
||||
self.image_load()
|
||||
|
||||
@staticmethod
|
||||
|
@ -654,8 +665,8 @@ if settings_data["size"] == SIZE_CHOICES[0]:
|
|||
new_button = Button((150, 0), (80, 3), px12)
|
||||
info_button = Button((165, 0), (7, 3), px12)
|
||||
stats_button = Button((180, 0), (95, 3), px12)
|
||||
to_left_button = Button((0, 30), (44, 136), px14)
|
||||
to_right_button = Button((17, 30), (86, 136), px14)
|
||||
to_left_button = Button((0, 30), (33, 136), px14)
|
||||
to_right_button = Button((17, 30), (97, 136), px14)
|
||||
BACKGROUND_IMAGE = Image((0, 64), (0, 0), (WIDTH, HEIGHT))
|
||||
ver1_layer = sprite_sheet.get_sprite((147, 64), WIDTH, HEIGHT, color_key=(255, 0, 128))
|
||||
ver2_layer = sprite_sheet.get_sprite((294, 64), WIDTH, HEIGHT, color_key=(255, 0, 128))
|
||||
|
@ -676,8 +687,8 @@ elif settings_data["size"] == SIZE_CHOICES[1]:
|
|||
new_button = Button((190, 0), (118, 4), px16)
|
||||
info_button = Button((209, 0), (8, 4), px16)
|
||||
stats_button = Button((228, 0), (138, 4), px16)
|
||||
to_left_button = Button((0, 38), (66, 191), px20)
|
||||
to_right_button = Button((23, 38), (116, 191), px20)
|
||||
to_left_button = Button((0, 38), (46, 191), px20)
|
||||
to_right_button = Button((23, 38), (136, 191), px20)
|
||||
BACKGROUND_IMAGE = Image((0, 84), (0, 0), (WIDTH, HEIGHT))
|
||||
ver1_layer = sprite_sheet.get_sprite((205, 84), WIDTH, HEIGHT, color_key=(255, 0, 128))
|
||||
ver2_layer = sprite_sheet.get_sprite((410, 84), WIDTH, HEIGHT, color_key=(255, 0, 128))
|
||||
|
@ -698,8 +709,8 @@ else:
|
|||
new_button = Button((350, 0), (241, 6), px32)
|
||||
info_button = Button((385, 0), (12, 6), px32)
|
||||
stats_button = Button((420, 0), (278, 6), px32)
|
||||
to_left_button = Button((0, 70), (130, 372), px40)
|
||||
to_right_button = Button((43, 70), (226, 372), px40)
|
||||
to_left_button = Button((0, 70), (107, 372), px40)
|
||||
to_right_button = Button((43, 70), (248, 372), px40)
|
||||
BACKGROUND_IMAGE = Image((0, 156), (0, 0), (WIDTH, HEIGHT))
|
||||
ver1_layer = sprite_sheet.get_sprite((399, 156), WIDTH, HEIGHT, color_key=(255, 0, 128))
|
||||
ver2_layer = sprite_sheet.get_sprite((798, 156), WIDTH, HEIGHT, color_key=(255, 0, 128))
|
||||
|
@ -911,7 +922,7 @@ while run:
|
|||
total_seconds = hours * 3600 + minutes * 60 + seconds
|
||||
elapsed_time += total_seconds
|
||||
current_timer_text = timer(elapsed_time)
|
||||
render_text(current_timer_text, (timer_area.x, timer_area.y), screen, timer_color)
|
||||
render_text(current_timer_text, (timer_area.x, timer_area.y), screen, oposite_color)
|
||||
|
||||
# Puzzle
|
||||
if pressed_button == shuffle_button and current_time - last_shuffle_time > 500:
|
||||
|
|
|
@ -85,15 +85,33 @@
|
|||
"10.png": [
|
||||
0,
|
||||
0,
|
||||
1,
|
||||
2290,
|
||||
"00:01:13",
|
||||
"00:00:00",
|
||||
4
|
||||
0,
|
||||
0,
|
||||
"00:00:34",
|
||||
"00:00:04",
|
||||
0
|
||||
]
|
||||
},
|
||||
"Birds": {
|
||||
"1.png": [
|
||||
1,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
"00:00:00",
|
||||
"00:00:00",
|
||||
0
|
||||
],
|
||||
"2.png": [
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
"00:00:00",
|
||||
"00:00:00",
|
||||
0
|
||||
],
|
||||
"3.png": [
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
|
|
|
@ -1 +1 @@
|
|||
{"puzzle 4x4": [[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12], [13, 14, 15, 0]], "puzzle 3x3": [[1, 2, 3], [4, 5, 6], [7, 8, 0]], "current 4x4": {"matrix": [[15, 1, 0, 4], [13, 3, 10, 5], [9, 12, 14, 6], [2, 7, 11, 8]], "selected_image": "/images/albums/Original images/10.png"}, "current 3x3": {"matrix": [[3, 6, 7], [5, 4, 1], [0, 8, 2]], "selected_image": "/images/albums/Birds/1.png"}}
|
||||
{"puzzle 4x4": [[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12], [13, 14, 15, 0]], "puzzle 3x3": [[1, 2, 3], [4, 5, 6], [7, 8, 0]], "current 4x4": {"matrix": [[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12], [13, 14, 15, 0]], "selected_image": "/images/albums/Birds/1.png"}, "current 3x3": {"matrix": [[3, 6, 7], [5, 4, 1], [0, 8, 2]], "selected_image": "/images/albums/Birds/1.png"}}
|
Loading…
Reference in New Issue