From 6a20ab31ef4d9f6bb0e008b9f1b8d3fbeb6bd956 Mon Sep 17 00:00:00 2001 From: RaindropsSys Date: Sat, 2 Sep 2023 15:32:03 +0200 Subject: Updated 13 files and added 2 files (automated) --- src/picker.py | 60 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 src/picker.py (limited to 'src/picker.py') diff --git a/src/picker.py b/src/picker.py new file mode 100644 index 0000000..d23b8c3 --- /dev/null +++ b/src/picker.py @@ -0,0 +1,60 @@ +import pygame + +import helper +from blocks import blocks +import audio + +def show(mouse): + surface = pygame.Surface((1280, 720)) + surface.fill((0, 0, 0, 128)) + + surface.blit(helper.text("Select a block:", 20, (255, 255, 255)), (50, 50)) + + x = 50 + y = 85 + + for block in list(filter(lambda i: blocks[i]['placeable'], blocks.keys())): + if x <= mouse[0] <= x + 42 and y <= mouse[1] <= y + 42: + surface.fill((255, 255, 255), (x - 5, y - 5, 52, 52)) + + surface.blit(helper.draw_texture(blocks[block]['texture']), (x, y)) + x += 52 + + if x >= 1040: + x = 50 + y += 52 + + + x = 50 + y = 85 + + for block in list(filter(lambda i: blocks[i]['placeable'], blocks.keys())): + if x <= mouse[0] <= x + 42 and y <= mouse[1] <= y + 42: + text = pygame.font.Font("./assets/font/main.ttf", 20).render(blocks[block]['name'], False, (0, 0, 0), (255, 255, 255)) + surface.blit(text, (x - (text.get_width() / 2) + 21, y - text.get_height() - 5)) + + x += 52 + + if x >= 1040: + x = 50 + y += 52 + + return surface + +def click(mouse, screen, picker, selected_block): + x = 50 + y = 85 + + for block in list(filter(lambda i: blocks[i]['placeable'], blocks.keys())): + if x <= mouse[0] <= x + 42 and y <= mouse[1] <= y + 42: + audio.play_sfx("action") + selected_block = block + picker = False + + x += 52 + + if x >= 1040: + x = 50 + y += 52 + + return mouse, screen, picker, selected_block \ No newline at end of file -- cgit