Commit 4d46d05d authored by Tošner, Jan's avatar Tošner, Jan
Browse files

v1.0

parent 89d6ab59
<?xml version="1.0" encoding="UTF-8"?>
<module type="PYTHON_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$">
<excludeFolder url="file://$MODULE_DIR$/venv" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="R User Library" level="project" />
<orderEntry type="library" name="R Skeletons" level="application" />
</component>
<component name="TestRunnerService">
<option name="PROJECT_TEST_RUNNER" value="Unittests" />
</component>
</module>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Encoding" addBOMForNewFiles="with NO BOM" />
</project>
\ No newline at end of file
<component name="libraryTable">
<library name="R User Library">
<CLASSES />
<SOURCES />
</library>
</component>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.7 (MapMaker)" project-jdk-type="Python SDK" />
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/MapMaker.iml" filepath="$PROJECT_DIR$/.idea/MapMaker.iml" />
</modules>
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>
\ No newline at end of file
import pygame
import ctypes
import os
from tkinter import Tk
from tkinter.filedialog import askopenfilename, asksaveasfilename
# Size of the screen
SCREEN_TITLE = "Map Maker"
SCREEN_WIDTH = 1920
SCREEN_HEIGHT = 1080
os.environ['SDL_VIDEO_WINDOW_POS'] = "0,0"
# Colors according to RGB codes
WHITE_COLOR = (255, 255, 255)
BLACK_COLOR = (0, 0, 0)
MAXIMAL_ZOOM = 3.5
# Clock used to update game events and frames
clock = pygame.time.Clock()
pygame.font.init()
font = pygame.font.SysFont("Sans", 75)
level_font = pygame.font.SysFont("Sans", 25)
ctypes.windll.user32.SetProcessDPIAware()
class Game:
# Typical rate of 60, equivalent to FPS
TICK_RATE = 60
def __init__(self, image_path, title, width, height):
self.title = title
self.width = width
self.height = height
# Create the window of specified size in white to display the game
self.screen = pygame.display.set_mode((width, height))
# Set the game window color to white
self.screen.fill(WHITE_COLOR)
pygame.display.set_caption(title)
background_image = pygame.image.load(image_path)
self.image = pygame.transform.scale(background_image, (width, height))
def run_game_loop(self):
running = True
in_menu = False
in_book = False
menu = Menu()
book = Book()
picture = Picture()
moving = False
selected = -1
while running:
for event in pygame.event.get():
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_ESCAPE:
in_menu = not in_menu
if event.key == pygame.K_TAB and not in_menu:
in_book = not in_book
elif event.type == pygame.MOUSEBUTTONDOWN:
x, y = pygame.mouse.get_pos()
l, m, r = pygame.mouse.get_pressed()
if in_menu and l == 1:
# Cross
if 1165 < x < 1165 + 75 and 160 < y < 160 + 75:
in_menu = False
# Save
if 789 < x < 789 + 342 and 311 < y < 311 + 135:
in_menu = False
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
picture.save(path)
# Load
if 789 < x < 789 + 342 and 473 < y < 473 + 135:
in_menu = False
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
picture.load(path)
# Vypnout program
if 789 < x < 789 + 342 and 635 < y < 635 + 135:
running = False
elif in_book and l == 1:
#Doleva
if 330 < x < 330 + 42 and 890 < y < 890 + 63:
if book.page != 0:
book.page += -2
#Doprava
elif 1530 < x < 1530 + 42 and 890 < y < 890 + 63:
if book.page + 2 < (len(book.blocks)+14)//15:
book.page += 2
#Reload
elif 287 < x < 287 + 75 and 38 < y < 38 +75:
book.load()
else:
selected = book.select(x, y)
else:
if event.button == 4:
if picture.extend <= MAXIMAL_ZOOM:
picture.extend += 0.5
picture.moveext(x, y, True)
elif event.button == 5:
if picture.extend <= 1:
picture.extend = 1
else:
picture.extend -= 0.5
picture.moveext(x, y, False)
elif l == 1:
if selected >= 0:
picture.put(book.blocks[selected], (x, y))
if m == 1:
pygame.mouse.get_rel()
moving = True
if moving and event.type == pygame.MOUSEBUTTONUP:
l, m, r = pygame.mouse.get_pressed()
if m == 0:
moving = False
if moving and not in_menu and not in_book:
picture.move(pygame.mouse.get_rel())
picture.print(self.screen)
#self.screen.blit(self.image, (0, 0)) #Přidání rámečku
if selected != -1 and not in_book and not in_menu:
picture.preview(book.blocks[selected], pygame.mouse.get_pos())
else:
picture.stop_preview()
if in_book:
book.draw(self.screen)
if in_menu:
menu.draw(self.screen)
# Update all game graphics
pygame.display.update()
#clock.tick(self.TICK_RATE)
class Picture:
def __init__(self):
self.pos = (0, 0)
self.extend = 1
self.surf = pygame.Surface((1920, 1080))
self.pic = pygame.Surface((960, 544))
self.pic.fill(WHITE_COLOR)
self.shown = self.pic.copy()
def scale(self):
return pygame.transform.scale(self.shown, (int(1920 * self.extend), int(1080 * self.extend)))
def load(self, path):
self.pic = pygame.image.load(path)
self.shown = self.pic.copy()
def move(self, pos):
x, y = self.pos
xm, ym = pos
xa = 0
ya = 0
if x + xm >= 0:
xa = 0
elif -1920 * (self.extend - 1) >= x + xm:
xa = -1920 * (self.extend - 1)
else:
xa = x + xm
if y + ym >= 0:
ya = 0
elif -1080 * (self.extend - 1) >= y + ym:
ya = -1080 * (self.extend - 1)
else:
ya = y + ym
self.pos = (xa, ya)
if self.extend == 1:
self.pos = (0, 0)
def print(self, screen):
self.surf.fill(BLACK_COLOR)
self.surf.blit(self.scale(), self.pos)
screen.blit(self.surf, (0, 0))
def moveext(self, x, y, zoom): #zoom = true -> making bigger; false -> making smaller
xo, yo = self.pos
if zoom:
xm = x * self.extend
ym = y * self.extend
self.move((x - xm - xo, y - ym - yo))
else:
self.moveext((x - xo) / (self.extend + 0.5), (y - yo) / (self.extend + 0.5), True)
def save(self,path):
pygame.image.save(self.pic, path)
def put(self, img, cord):
x, y = cord
xp, yp = self.pos
cord = (((x-xp)//(32*self.extend))*16, ((y-yp)//(32*self.extend))*16)
img.draw(self.pic, cord)
self.shown = self.pic.copy()
def preview(self, img, cord):
self.shown = self.pic.copy()
x, y = cord
xp, yp = self.pos
cord = (((x - xp) // (32 * self.extend)) * 16, ((y - yp) // (32 * self.extend)) * 16)
img.draw(self.shown, cord)
def stop_preview(self):
self.shown = self.pic.copy()
class Menu:
def __init__(self):
self.background = pygame.image.load("images/GUI/board.png")
self.button1 = pygame.image.load("images/GUI/plank_13.png")
self.button2 = pygame.image.load("images/GUI/plank_14.png")
self.button3 = pygame.image.load("images/GUI/plank_15.png")
self.cross = pygame.image.load("images/GUI/cross.png")
self.cross = pygame.transform.scale(self.cross, (75,75))
def draw(self, screen):
screen.blit(self.background, (704, 184))
screen.blit(self.button1, (789, 311))
screen.blit(self.cross, (1165, 160))
text = font.render("Uložit", True, BLACK_COLOR)
screen.blit(text, (880, 336))
screen.blit(self.button2, (789, 473))
text = font.render("Načíst", True, BLACK_COLOR)
screen.blit(text, (872, 498))
screen.blit(self.button3, (789, 635))
text = font.render("Vypnout", True, BLACK_COLOR)
screen.blit(text, (847, 660))
class Book:
def __init__(self):
self.book = pygame.image.load("images/GUI/book.png")
self.book = pygame.transform.scale(self.book, (1363, 1025))
self.left = pygame.image.load("images/GUI/left.png")
self.left = pygame.transform.scale(self.left, (42, 63))
self.right = pygame.image.load("images/GUI/right.png")
self.right = pygame.transform.scale(self.right, (42, 63))
self.reload = pygame.image.load("images/GUI/reload.png")
self.reload = pygame.transform.scale(self.reload, (75, 75))
self.page = 0
self.cords = [(300,100)]
self.blocks = []
self.load()
def draw(self, screen):
screen.blit(self.book, (278, 27))
self.draw_icons(screen, self.page)
self.draw_icons(screen, self.page+1)
screen.blit(self.left, (330, 890))
screen.blit(self.right, (1530, 890))
screen.blit(self.reload, (287, 38))
def draw_icons(self, screen, page):
for i in range(5):
for j in range(3):
if len(self.blocks) <= 3 * i + j + page * 15:
return
if page % 2 != 0:
self.blocks[3 * i + j + page * 15].draw_book(screen, (1050 + j * 175, 125 + i * 175))
else:
self.blocks[3 * i + j + page * 15].draw_book(screen, (400 + j * 175, 125 + i * 175))
def load(self):
self.blocks = []
for name in os.listdir("images/blocks"):
self.blocks.append(Block(name))
def select(self, x, y):
if 400 < x < 500 or 1050 < x < 1150:
j = 0
elif 575 < x < 675 or 1225 < x < 1325:
j = 1
elif 750 < x < 850 or 1400 < x < 1500:
j = 2
else:
return -1
if x > 1050:
j += 15
if 125 < y < 225:
i = 0
elif 300 < y < 400:
i = 1
elif 475 < y < 575:
i = 2
elif 650 < y < 750:
i = 3
elif 825 < y < 925:
i = 4
else:
return -1
return 3 * i + j + self.page * 15
class Block:
def __init__(self, name):
self.icon = pygame.image.load("images/blocks/"+name)
self.name = name
def draw_book(self, screen, cord):
icon = pygame.transform.scale(self.icon,(100, 100))
screen.blit(icon, cord)
def draw(self, surf, cord):
surf.blit(self.icon, cord)
pygame.init()
new_game = Game("images/GUI/frame.png", SCREEN_TITLE, SCREEN_WIDTH, SCREEN_HEIGHT)
new_game.run_game_loop()
pygame.quit()
quit()
# pygame.draw.rect(game_screen, BLACK_COLOR, [350, 350, 100, 100])
# pygame.draw.circle(game_screen, BLACK_COLOR, (400, 300), 50)
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