From 78a4c1960122b5957f13ad8f06cc5b6d46ab843d Mon Sep 17 00:00:00 2001 From: Adam Wojdyla Date: Sun, 22 Mar 2020 18:10:44 +0100 Subject: [PATCH 1/3] turned grid and waiter into objects, added gitignore file, modified movement and graphic layer update --- .gitignore | 112 ++++++++++++++++++ .idea/.gitignore | 2 + .idea/ProjektAI.iml | 12 ++ .../inspectionProfiles/profiles_settings.xml | 6 + .idea/misc.xml | 7 ++ .idea/modules.xml | 8 ++ .idea/vcs.xml | 6 + kelner/main.py | 91 ++++++++++---- 8 files changed, 221 insertions(+), 23 deletions(-) create mode 100644 .gitignore create mode 100644 .idea/.gitignore create mode 100644 .idea/ProjektAI.iml create mode 100644 .idea/inspectionProfiles/profiles_settings.xml create mode 100644 .idea/misc.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/vcs.xml diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..73ffb59 --- /dev/null +++ b/.gitignore @@ -0,0 +1,112 @@ + +# Created by https://www.gitignore.io/api/python +# Edit at https://www.gitignore.io/?templates=python + +### Python ### +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class + +# C extensions +*.so + +# Distribution / packaging +.Python +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +pip-wheel-metadata/ +share/python-wheels/ +*.egg-info/ +.installed.cfg +*.egg + +/idea/workspace.xml +MANIFEST + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.nox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*.cover +.hypothesis/ +.pytest_cache/ + +# Translations +*.mo +*.pot + +# Scrapy stuff: +.scrapy + +# Sphinx documentation +docs/_build/ + +# PyBuilder +target/ + +# pyenv +.python-version + +# pipenv +# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. +# However, in case of collaboration, if having platform-specific dependencies or dependencies +# having no cross-platform support, pipenv may install dependencies that don't work, or not +# install all needed dependencies. +#Pipfile.lock + +# celery beat schedule file +celerybeat-schedule + +# SageMath parsed files +*.sage.py + +# Spyder project settings +.spyderproject +.spyproject + +# Rope project settings +.ropeproject + +# Mr Developer +.mr.developer.cfg +.project +.pydevproject + +# mkdocs documentation +/site + +# mypy +.mypy_cache/ +.dmypy.json +dmypy.json + +# Pyre type checker +.pyre/ + +# End of https://www.gitignore.io/api/python \ No newline at end of file diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..e7e9d11 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,2 @@ +# Default ignored files +/workspace.xml diff --git a/.idea/ProjektAI.iml b/.idea/ProjektAI.iml new file mode 100644 index 0000000..8b8c395 --- /dev/null +++ b/.idea/ProjektAI.iml @@ -0,0 +1,12 @@ + + + + + + + + + + \ No newline at end of file diff --git a/.idea/inspectionProfiles/profiles_settings.xml b/.idea/inspectionProfiles/profiles_settings.xml new file mode 100644 index 0000000..105ce2d --- /dev/null +++ b/.idea/inspectionProfiles/profiles_settings.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..6649a8c --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,7 @@ + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..44f5414 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/kelner/main.py b/kelner/main.py index e206b56..0a056e3 100644 --- a/kelner/main.py +++ b/kelner/main.py @@ -1,33 +1,76 @@ import pygame +import time -#initialize the pygame +# initialize the pygame pygame.init() -#create the screen +# initiate variables screen = pygame.display.set_mode((1000,1000)) - -#caption pygame.display.set_caption("Bardzo mÄ…dry kelner") -#grid +# Grid variables gridImg = pygame.image.load("20x20grid.png") gridX = 0 gridY = 0 -#weiter +# Waiter variables waiterImg = pygame.image.load("waiter.png") waiterX = 10 -waiterY = 1 +waiterY = 10 + + +# TODO: classes in separate folders + + +class Grid: + + def __init__(self, g_x, g_y, grid_img): + self.g_x = g_x + self.g_y = g_y + + self.grid_img = grid_img + + def draw_grid(self): + global screen + screen.blit(self.grid_img, (self.g_x, self.g_y)) + + +class Waiter: + def __init__(self, w_x, w_y, waiter_img): + self.waiter_img = waiter_img + self.w_x = w_x + self.w_y = w_y + self.position = [w_x, w_y] + + def draw_waiter(self): + global screen + screen.blit(self.waiter_img, self.position) + + def move_left(self, w_x): + self.position[0] = (self.position[0]-w_x) % 1000 + screen.blit(self.waiter_img, self.position) + + def move_right(self, w_x): + self.position[0] = (self.position[0]+w_x) % 1000 + screen.blit(self.waiter_img, self.position) + + def move_up(self, w_y): + self.position[1] = (self.position[1]-w_y) % 1000 + screen.blit(self.waiter_img, self.position) + + def move_down(self, w_y): + self.position[1] = (self.position[1]+w_y) % 1000 + screen.blit(self.waiter_img, self.position) + + +# waiter waiterX_change = 0 waiterY_change = 0 -def grid(): - screen.blit(gridImg, (gridX,gridY)) +grid = Grid(gridX, gridY, gridImg) +waiter = Waiter(waiterX, waiterY, waiterImg) -def waiter(x, y): - screen.blit(waiterImg, (x,y)) - -#loop +# loop running = True while running: @@ -37,24 +80,26 @@ while running: for event in pygame.event.get(): if event.type == pygame.QUIT: running = False - +# TODO: switch case if event.type == pygame.KEYDOWN: if event.key == pygame.K_LEFT: - waiterX_change = -50 + waiter.move_left(20) if event.key == pygame.K_RIGHT: - waiterX_change = 50 + waiter.move_right(20) if event.key == pygame.K_UP: - waiterY_change = -50 + waiter.move_up(20) if event.key == pygame.K_DOWN: - waiterY_change = 50 + waiter.move_down(20) + + # do czego to ??? if event.type == pygame.KEYUP: if event.key == pygame.K_LEFT or event.key == pygame.K_RIGHT: waiterX_change = 0 if event.key == pygame.K_UP or event.key == pygame.K_DOWN: waiterY_change = 0 - grid() - waiterX += waiterX_change - waiterY += waiterY_change - waiter(waiterX, waiterY) - pygame.display.update() \ No newline at end of file + grid.draw_grid() + waiter.draw_waiter() + pygame.display.update() + time.sleep(0.1) + From feb9eec7081ea13807729d13db7abf5f24930d62 Mon Sep 17 00:00:00 2001 From: Adam Wojdyla Date: Sun, 22 Mar 2020 18:19:15 +0100 Subject: [PATCH 2/3] deleted .idea/ --- .../inspectionProfiles/profiles_settings.xml | 6 -- kelner/.idea/kelner.iml | 13 --- kelner/.idea/misc.xml | 7 -- kelner/.idea/modules.xml | 8 -- kelner/.idea/workspace.xml | 90 ------------------- 5 files changed, 124 deletions(-) delete mode 100644 kelner/.idea/inspectionProfiles/profiles_settings.xml delete mode 100644 kelner/.idea/kelner.iml delete mode 100644 kelner/.idea/misc.xml delete mode 100644 kelner/.idea/modules.xml delete mode 100644 kelner/.idea/workspace.xml diff --git a/kelner/.idea/inspectionProfiles/profiles_settings.xml b/kelner/.idea/inspectionProfiles/profiles_settings.xml deleted file mode 100644 index 105ce2d..0000000 --- a/kelner/.idea/inspectionProfiles/profiles_settings.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - \ No newline at end of file diff --git a/kelner/.idea/kelner.iml b/kelner/.idea/kelner.iml deleted file mode 100644 index f7ae110..0000000 --- a/kelner/.idea/kelner.iml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - \ No newline at end of file diff --git a/kelner/.idea/misc.xml b/kelner/.idea/misc.xml deleted file mode 100644 index 53407e2..0000000 --- a/kelner/.idea/misc.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/kelner/.idea/modules.xml b/kelner/.idea/modules.xml deleted file mode 100644 index 620b5e5..0000000 --- a/kelner/.idea/modules.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/kelner/.idea/workspace.xml b/kelner/.idea/workspace.xml deleted file mode 100644 index 2db0200..0000000 --- a/kelner/.idea/workspace.xml +++ /dev/null @@ -1,90 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 1584822897275 - - - - - - - - - \ No newline at end of file From 42d6989b7ad048ff32dc0e85c668d20f597a31c9 Mon Sep 17 00:00:00 2001 From: Adam Wojdyla Date: Sun, 22 Mar 2020 18:26:47 +0100 Subject: [PATCH 3/3] deleted .idea v2 --- .idea/.gitignore | 2 -- .idea/ProjektAI.iml | 12 ------------ .idea/inspectionProfiles/profiles_settings.xml | 6 ------ .idea/misc.xml | 7 ------- .idea/modules.xml | 8 -------- .idea/vcs.xml | 6 ------ 6 files changed, 41 deletions(-) delete mode 100644 .idea/.gitignore delete mode 100644 .idea/ProjektAI.iml delete mode 100644 .idea/inspectionProfiles/profiles_settings.xml delete mode 100644 .idea/misc.xml delete mode 100644 .idea/modules.xml delete mode 100644 .idea/vcs.xml diff --git a/.idea/.gitignore b/.idea/.gitignore deleted file mode 100644 index e7e9d11..0000000 --- a/.idea/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -# Default ignored files -/workspace.xml diff --git a/.idea/ProjektAI.iml b/.idea/ProjektAI.iml deleted file mode 100644 index 8b8c395..0000000 --- a/.idea/ProjektAI.iml +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - - - - - \ No newline at end of file diff --git a/.idea/inspectionProfiles/profiles_settings.xml b/.idea/inspectionProfiles/profiles_settings.xml deleted file mode 100644 index 105ce2d..0000000 --- a/.idea/inspectionProfiles/profiles_settings.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml deleted file mode 100644 index 6649a8c..0000000 --- a/.idea/misc.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml deleted file mode 100644 index 44f5414..0000000 --- a/.idea/modules.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml deleted file mode 100644 index 94a25f7..0000000 --- a/.idea/vcs.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file