1
0
forked from s444417/ProjektAI

turned grid and waiter into objects, added gitignore file, modified movement and graphic layer update

This commit is contained in:
Adam Wojdyla 2020-03-22 18:10:44 +01:00
parent 5fc44db844
commit 78a4c19601
8 changed files with 221 additions and 23 deletions

112
.gitignore vendored Normal file
View File

@ -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

2
.idea/.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
# Default ignored files
/workspace.xml

12
.idea/ProjektAI.iml Normal file
View File

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="PYTHON_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
<component name="PyDocumentationSettings">
<option name="format" value="PLAIN" />
<option name="myDocStringFormat" value="Plain" />
</component>
</module>

View File

@ -0,0 +1,6 @@
<component name="InspectionProjectProfileManager">
<settings>
<option name="USE_PROJECT_PROFILE" value="false" />
<version value="1.0" />
</settings>
</component>

7
.idea/misc.xml Normal file
View File

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="JavaScriptSettings">
<option name="languageLevel" value="ES6" />
</component>
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.8" project-jdk-type="Python SDK" />
</project>

8
.idea/modules.xml Normal file
View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/ProjektAI.iml" filepath="$PROJECT_DIR$/.idea/ProjektAI.iml" />
</modules>
</component>
</project>

6
.idea/vcs.xml Normal file
View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>

View File

@ -1,33 +1,76 @@
import pygame import pygame
import time
#initialize the pygame # initialize the pygame
pygame.init() pygame.init()
#create the screen # initiate variables
screen = pygame.display.set_mode((1000,1000)) screen = pygame.display.set_mode((1000,1000))
#caption
pygame.display.set_caption("Bardzo mądry kelner") pygame.display.set_caption("Bardzo mądry kelner")
#grid # Grid variables
gridImg = pygame.image.load("20x20grid.png") gridImg = pygame.image.load("20x20grid.png")
gridX = 0 gridX = 0
gridY = 0 gridY = 0
#weiter # Waiter variables
waiterImg = pygame.image.load("waiter.png") waiterImg = pygame.image.load("waiter.png")
waiterX = 10 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 waiterX_change = 0
waiterY_change = 0 waiterY_change = 0
def grid(): grid = Grid(gridX, gridY, gridImg)
screen.blit(gridImg, (gridX,gridY)) waiter = Waiter(waiterX, waiterY, waiterImg)
def waiter(x, y): # loop
screen.blit(waiterImg, (x,y))
#loop
running = True running = True
while running: while running:
@ -37,24 +80,26 @@ while running:
for event in pygame.event.get(): for event in pygame.event.get():
if event.type == pygame.QUIT: if event.type == pygame.QUIT:
running = False running = False
# TODO: switch case
if event.type == pygame.KEYDOWN: if event.type == pygame.KEYDOWN:
if event.key == pygame.K_LEFT: if event.key == pygame.K_LEFT:
waiterX_change = -50 waiter.move_left(20)
if event.key == pygame.K_RIGHT: if event.key == pygame.K_RIGHT:
waiterX_change = 50 waiter.move_right(20)
if event.key == pygame.K_UP: if event.key == pygame.K_UP:
waiterY_change = -50 waiter.move_up(20)
if event.key == pygame.K_DOWN: if event.key == pygame.K_DOWN:
waiterY_change = 50 waiter.move_down(20)
# do czego to ???
if event.type == pygame.KEYUP: if event.type == pygame.KEYUP:
if event.key == pygame.K_LEFT or event.key == pygame.K_RIGHT: if event.key == pygame.K_LEFT or event.key == pygame.K_RIGHT:
waiterX_change = 0 waiterX_change = 0
if event.key == pygame.K_UP or event.key == pygame.K_DOWN: if event.key == pygame.K_UP or event.key == pygame.K_DOWN:
waiterY_change = 0 waiterY_change = 0
grid() grid.draw_grid()
waiterX += waiterX_change waiter.draw_waiter()
waiterY += waiterY_change pygame.display.update()
waiter(waiterX, waiterY) time.sleep(0.1)
pygame.display.update()