Commit 9580543a authored by Tošner, Jan's avatar Tošner, Jan
Browse files

v1.4

- čtení a zápis hitzone
parent c69f534c
......@@ -82,7 +82,7 @@ class Game:
in_menu = False
changed = True
# Save
if 789 < x < 789 + 342 and 311 < y < 311 + 135:
elif 789 < x < 789 + 342 and 311 < y < 311 + 135:
Tk().withdraw() # we don't want a full GUI, so keep the root window from appearing
path = asksaveasfilename(title = "Select file",defaultextension=".png", filetypes=(("PNG (*.png)", "*.png"),("All Files", "*.*") )) # show an "Open" dialog box and return the path to the selected file
if path:
......@@ -90,7 +90,7 @@ class Game:
changed = True
picture.save(path)
# Load
if 789 < x < 789 + 342 and 473 < y < 473 + 135:
elif 789 < x < 789 + 342 and 473 < y < 473 + 135:
Tk().withdraw() # we don't want a full GUI, so keep the root window from appearing
path = askopenfilename(title = "Select file",defaultextension=".png", filetypes=(("PNG (*.png)", "*.png"),("All Files", "*.*") )) # show an "Open" dialog box and return the path to the selected file
if path:
......@@ -98,7 +98,7 @@ class Game:
changed = True
picture.load(path)
# Vypnout program
if 789 < x < 789 + 342 and 635 < y < 635 + 135:
elif 789 < x < 789 + 342 and 635 < y < 635 + 135:
running = False
elif in_book and l == 1 and not editing:
#Doleva
......@@ -120,7 +120,7 @@ class Game:
elif in_book and r == 1 and not editing:
editing = book.select(x,y)
elif in_book and editing:
pass
pass #TODO označování hit boxů
elif not in_menu and not in_book:
if event.button == 4:
if picture.extend != MAXIMAL_ZOOM:
......@@ -184,6 +184,7 @@ class Picture:
self.pic.fill(WHITE_COLOR)
self.shown = self.pic.copy()
self.last_cord = (-1, -1)
self.walls = {}
def scale(self, pic):
return pygame.transform.scale(pic, (int(SCREEN_WIDTH * self.extend), int(SCREEN_HEIGHT * self.extend)))
......@@ -229,12 +230,22 @@ class Picture:
def save(self,path):
pygame.image.save(self.pic, path)
with open(path.replace("png", "txt"), 'w', encoding='UTF-8') as f:
for key in self.walls:
string = "".join(self.walls[key])
arr = string.split(";")
for text in arr:
#text = "".join(text)
rect = text.split(",")
x = int(rect[0]) + int(key[0])
y = int(rect[1]) + int(key[1])
f.write(str(x)+ "," + str(y) + " " + rect[2] + "," + rect[3] + "\n")
def put(self, img, cord):
x, y = cord
xp, yp = self.pos
cord = (((x - xp)//(16 * self.ratio[0] * self.extend))*16, ((y - yp)//(16 * self.ratio[1] * self.extend))*16)
img.draw(self.pic, cord)
img.draw(self.pic, cord, self.walls)
self.shown = self.scale(self.pic)
def preview(self, img, cord, changed):
......@@ -243,9 +254,9 @@ class Picture:
x, y = cord
xp, yp = self.pos
cord = (((x - xp)//(16 * self.ratio[0] * self.extend))*16, ((y - yp)//(16 * self.ratio[1] * self.extend))*16)
#if self.last_cord != cord or changed:
if self.last_cord != cord or changed:
self.shown = self.pic.copy()
img.draw(self.shown, cord)
img.draw(self.shown, cord, None)
self.shown = self.scale(self.shown)
ret = True
else:
......@@ -295,6 +306,7 @@ class Book:
self.reload = pygame.image.load("images/GUI/reload.png")
self.reload = pygame.transform.scale(self.reload, (75, 75))
self.editing = None
self.dict = {}
self.page = 0
self.cords = [(300, 100)]
self.blocks = []
......@@ -324,9 +336,16 @@ class Book:
self.blocks[3 * i + j + page * 15].draw_book(screen, (400 + j * 175, 125 + i * 175))
def load(self):
with open("src/blocks.txt", 'r', encoding='UTF-8') as f:
while True:
line = f.readline()
if line == "":
break
split = line.split()
self.dict[split[0]] = split[1]
self.blocks = []
for name in os.listdir("images/blocks"):
self.blocks.append(Block(name))
self.blocks.append(Block(name, self.dict.get(name, "")))
def select(self, x, y):
if 400 < x < 500 or 1050 < x < 1150:
......@@ -356,16 +375,19 @@ class Book:
class Block:
def __init__(self, name):
def __init__(self, name, param):
self.icon = pygame.image.load("images/blocks/"+name)
self.name = name
self.param = param.split(";")
def draw_book(self, screen, cord):
icon = pygame.transform.scale(self.icon,(100, 100))
screen.blit(icon, cord)
def draw(self, surf, cord):
def draw(self, surf, cord, walls):
surf.blit(self.icon, cord)
if walls != None and self.param != [""]:
walls[cord] = self.param
pygame.init()
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment