From 9d37e2464cc248c911543c2543f6b06b4df1d1c9 Mon Sep 17 00:00:00 2001 From: Megamichi Date: Fri, 23 Feb 2024 19:35:20 +0100 Subject: [PATCH] aff --- __pycache__/button.cpython-311.pyc | Bin 0 -> 2460 bytes button.py | 31 +++++++++++++++++++++++++++ main.py | 33 +++++++++++------------------ 3 files changed, 43 insertions(+), 21 deletions(-) create mode 100644 __pycache__/button.cpython-311.pyc create mode 100644 button.py diff --git a/__pycache__/button.cpython-311.pyc b/__pycache__/button.cpython-311.pyc new file mode 100644 index 0000000000000000000000000000000000000000..40e5a34cab3af985e0dc6291445ec40e4880304e GIT binary patch literal 2460 zcmcIlPe>eR6#wS0v%3Ci+~}&?YJ!1IB3W!xLW`6VijfLZQQBgKVVxOw*Q~qdo00fu z1P>lOc#vN7u+S-pP4VI(lpb;@U*<0vokemq0l!o@B7~S z-uJ%u-n`$;kIl`E1n7s~%X*q8nIbH?Pc(LeXxu(a$N@Z6 znqo9&g2?kgjH`E?L?h)%$kOtG4%aU1*;r|}zPiq{0-g2sZ621mTNXqtt* zBU0U5r1>#b3iv~J96aZft~-mf_*vE>if>{Gmgs62Pi5h{7Y4BykkErmRs%?0vXCYO zz>LX)!z~nyiv}=B(`P?F`(AehwU8@NM>JHb>v@Ma^(9l59Ny4#vlQz{BfuPH$zhfq z;ZasIGmeHOf`jcd)Fs~=)^>k`Jt7fvv2{l9Y?2MT;)J#$>XxV%^ zIa{DCsODcCJ zcE8%TU>Yr7?S`ST+>wBxsT_;L5ZQ$595xZvuNVlJja%m!RBnfuXi%d$-_G`{>aF2u zk-2(($(&zZ&(vfs$Xc8d^&G%%KUcfi(*{RC&)>k#RB_TUM)CEZxeQz4tRL8<%(?11lUp2dVHp}- zcX*Aa9yvVKRkMy6ibbVZPlul^h&^5$^(PgMNywX#6Dj^uiu#Ep?B$X)cp?oRc{go`Y}Fuk zu|(Jh=l9@6?jYVks8SG-p!cyK)CceeKY}_wRd$Je;O?N;|D#U`qUK>D&oU(cWynvU zuS2l~^r6@S`nSdwu=y9C_1FYAHdf;&0L$WOp|ore3^<-dIXbmZ6Zr=!pNUkn_5{mqNy(YMp3FQ!XFwe_kk@c+eUd*}9@ zm+kTGkKD$C6u~S6!i3z}5vVy#ceIi0h*Y zW$aq&wXQJ?(z<_DSV8EjkT8q32p?34&)y5K`o`5G&@sds_YR>l&Ja58>93`sYQ&$? jo1nukH$DRfAY_;_X None: + self.pos = x,y + self.größe = width,height + self.color = color + self.screen = screen + self.text = text + def draw(self): + pygame.draw.rect(self.screen, + self.color, + (self.pos[0]-self.größe[0]//2, + self.pos[1]-self.größe[1]//2, + self.größe[0], + self.größe[1]) + ) + + font = pygame.font.Font(None, 36) + text_surface = font.render(self.text, True, (0,0,0)) + text_rect = text_surface.get_rect() + text_rect.center = (self.pos[0], + self.pos[1]) + self.screen.blit(text_surface, text_rect) + def check_press(self, mouse): + if (self.pos[0] - self.größe[0]//2 <= mouse[0] <= self.pos[0] + self.größe[0]//2 and + self.pos[1] - self.größe[1]//2 <= mouse[1] <= self.pos[1] + self.größe[1]//2): + return True + else: + return False + diff --git a/main.py b/main.py index 9385dd7..4dfafb6 100644 --- a/main.py +++ b/main.py @@ -1,6 +1,6 @@ #!/usr/bin/python3 import pygame -import pygame.gfxdraw +from button import * import copy import random @@ -26,7 +26,6 @@ def centered_text(text=str, pos=tuple, color=tuple): def draw_feld(feld, color_key, block_size): - # print(feld) for a in range(len(feld[0])): for b in range(len(feld)): if feld[b][a] != " ": @@ -36,24 +35,8 @@ def draw_feld(feld, color_key, block_size): (a * block_size, b * block_size, block_size, block_size), ) - -def get_block_size(): - return 20, 20 - - -def get_meightboars(feld, position): - nachtbaren = [] - return nachtbaren - - -def save_list(liste, index1, index2): - if index2 > len(liste[0]) and index1 > len(liste): - return liste[index1][index2] - else: - return "a" - - def verarbeite_feld(feld): + feldx,feldy = len(feld[0]),len(feld) feld2 = copy.deepcopy(feld) for y in range(len(feld)): for x in range(len(feld[0])): @@ -106,6 +89,7 @@ wechselfarbe = "r" using_element = "a" pixelsize = 20 +buttons = [Button(screen,(200,200,200),100,100,30,30,"*")] show_debug = False running = True if __name__ == "__main__": @@ -162,14 +146,21 @@ if __name__ == "__main__": acolor = r, g, b color_key = {"#": (100, 100, 100), "a": acolor} draw_feld(feld, color_key, pixelsize) + mx, my = pygame.mouse.get_pos() mousepressed = pygame.mouse.get_pressed()[0] + for button in buttons: + button.draw() + if mousepressed: - feld[my // pixelsize][mx // pixelsize] = using_element + for button in buttons: + if button.check_press((mx,my)): + show_debug = not show_debug + else: + feld[my // pixelsize][mx // pixelsize] = using_element preview_mousepressed = pygame.mouse.get_pressed()[0] feld = verarbeite_feld(feld) - if show_debug: get_debug_text() ## bildschirm aktuallisierung