Compare commits
No commits in common. "9d37e2464cc248c911543c2543f6b06b4df1d1c9" and "1971b72419726e9af080c432c704601e3f51b99e" have entirely different histories.
9d37e2464c
...
1971b72419
3 changed files with 58 additions and 95 deletions
Binary file not shown.
31
button.py
31
button.py
|
@ -1,31 +0,0 @@
|
|||
import pygame
|
||||
|
||||
class Button():
|
||||
def __init__(self, screen, color, x, y, width, height, text) -> 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
|
||||
|
46
main.py
46
main.py
|
@ -1,12 +1,9 @@
|
|||
#!/usr/bin/python3
|
||||
import pygame
|
||||
from button import *
|
||||
import pygame.gfxdraw
|
||||
import copy
|
||||
import random
|
||||
|
||||
pygame.init()
|
||||
|
||||
|
||||
## funktionen
|
||||
def get_debug_text():
|
||||
def text(text,line_counter):
|
||||
|
@ -19,24 +16,31 @@ def get_debug_text():
|
|||
text(f"{str(a)} = {str(globalvars[a])}",line_counter)
|
||||
line_counter += 1
|
||||
|
||||
|
||||
def centered_text(text=str,pos=tuple,color=tuple):
|
||||
text = default_font.render(str(text), True, color,(255,255,255))
|
||||
screen.blit(text,(pos[0]-text.get_width()/2,pos[1]))
|
||||
|
||||
|
||||
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] != " ":
|
||||
pygame.draw.rect(
|
||||
screen,
|
||||
color_key[feld[b][a]],
|
||||
(a * block_size, b * block_size, block_size, block_size),
|
||||
)
|
||||
|
||||
pygame.draw.rect(screen,color_key[feld[b][a]],
|
||||
(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])):
|
||||
|
@ -60,7 +64,6 @@ def verarbeite_feld(feld):
|
|||
feld2[(y+1)%feldy][(x+direction)%feldx] = feld[y][x]
|
||||
return feld2
|
||||
|
||||
|
||||
def make_feld(size,mode):
|
||||
x = screensize[0]//size
|
||||
y = screensize[1]//size
|
||||
|
@ -69,8 +72,6 @@ def make_feld(size, mode):
|
|||
for x in range(x):
|
||||
feld[y-1][x] = "#"
|
||||
return feld ,x,y
|
||||
|
||||
|
||||
## klassen
|
||||
|
||||
|
||||
|
@ -89,7 +90,6 @@ 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__":
|
||||
|
@ -144,23 +144,17 @@ if __name__ == "__main__":
|
|||
if b == 0:
|
||||
wechselfarbe = "r"
|
||||
acolor = r,g,b
|
||||
color_key = {"#": (100, 100, 100), "a": acolor}
|
||||
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 :
|
||||
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
|
||||
|
|
Loading…
Reference in a new issue