Commit 3770e45f authored by Tošner, Jan's avatar Tošner, Jan
Browse files

v2.1

-přidány další funkce editování
parent 6235a807
......@@ -56,6 +56,7 @@ class Game:
selected = -1
changed = True
editing = None
bucket = False
while running:
......@@ -86,19 +87,30 @@ class Game:
elif editing:
if l == 1 or r == 1:
if 560 < x < 1360 and 140 < y < 940:
if l == 1:
if l == 1 and not bucket:
book.blocks[editing].update_wall(x, y, "1")
changed = True
elif r == 1:
elif r == 1 and not bucket:
book.blocks[editing].update_wall(x, y, "0")
changed = True
elif event.type == pygame.MOUSEBUTTONDOWN:
if event.button == 1 and 480 < x < 480 + 75 and 140 < y < 140 + 75:
if event.type == pygame.MOUSEBUTTONDOWN:
if event.button == 1 and bucket:
book.blocks[editing].bucket(x, y, "1")
changed = True
elif event.button == 3 and bucket:
book.blocks[editing].bucket(x, y, "0")
changed = True
elif event.type == pygame.MOUSEBUTTONDOWN and event.button == 1:
if 480 < x < 480 + 75 and 140 < y < 140 + 75:
book.blocks[editing].fill("1")
changed = True
elif event.button == 1 and 480 < x < 480 + 75 and 220 < y < 220 + 75:
elif 480 < x < 480 + 75 and 220 < y < 220 + 75:
book.blocks[editing].fill("0")
changed = True
elif 480 < x < 480 + 75 and 300 < y < 300 + 75:
bucket = False
elif 480 < x < 480 + 75 and 380 < y < 380 + 75:
bucket = True
elif event.type == pygame.MOUSEBUTTONDOWN:
if in_menu and event.button == 1:
# Cross
......@@ -342,6 +354,10 @@ class Book:
self.fill = pygame.transform.scale(self.fill, (75, 75))
self.blank = pygame.image.load("images/GUI/t_07.png")
self.blank = pygame.transform.scale(self.blank, (75, 75))
self.bucket = pygame.image.load("images/GUI/bucket.png")
self.bucket = pygame.transform.scale(self.bucket, (75, 75))
self.feather = pygame.image.load("images/GUI/feather.png")
self.feather = pygame.transform.scale(self.feather, (75, 75))
self.editing = None
self.editing_walls = None
self.page = 0
......@@ -362,6 +378,8 @@ class Book:
self.surf.blit(self.editing_walls, (560, 140))
self.surf.blit(self.fill, (480, 140))
self.surf.blit(self.blank, (480, 220))
self.surf.blit(self.feather, (480, 300))
self.surf.blit(self.bucket, (480, 380))
screen.blit(scale(self.surf), (0, 0))
def draw_icons(self, screen, page):
......@@ -427,6 +445,8 @@ class Block:
self.name = name
self.width, self.height = self.icon.get_size()
self.walls = []
self.tested = []
self.testing = None
name = name.replace("png", "txt")
if name in os.listdir("images/blocks"):
with open("images/blocks/" + name, 'r', encoding='UTF-8') as f:
......@@ -450,6 +470,37 @@ class Block:
def fill(self, to):
self.walls = [[to] * self.width for _ in range(self.height)]
def bucket(self, x, y, to):
x -= 560
y -= 140
x = int(x // (800 / self.width))
y = int(y // (800 / self.height))
self.testing = self.icon.get_at((x, y))
self.tested = [[False] * self.width for _ in range(self.height)]
self.tested[y][x] = True
self.walls[y][x] = to
if x - 1 >= 0:
self.test(x - 1, y, to)
if y - 1 >= 0:
self.test(x, y - 1, to)
if y + 1 < self.height:
self.test(x, y + 1, to)
if x + 1 < self.width:
self.test(x + 1, y, to)
def test(self, x, y, to):
self.tested[y][x] = True
if self.testing == self.icon.get_at((x, y)):
self.walls[y][x] = to
if x - 1 >= 0 and not self.tested[y][x-1]:
self.test(x - 1, y, to)
if y - 1 >= 0 and not self.tested[y-1][x]:
self.test(x, y - 1, to)
if y + 1 < self.height and not self.tested[y+1][x]:
self.test(x, y + 1, to)
if x + 1 < self.width and not self.tested[y][x+1]:
self.test(x + 1, y, to)
def update_wall(self, x, y, to):
x -= 560
y -= 140
......
0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 1 1 1 0 0 0 0 1 0 0 0
1 1 1 1 1 1 1 1 1 0 0 0 1 1 0 0
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0
1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 0
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
......
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