Zmiany w poruszaniu, gridzie i elementach

This commit is contained in:
Emulowsky 2019-04-16 13:43:41 +02:00
parent 6e681ce7a7
commit 58bbd316b9
6 changed files with 72 additions and 81 deletions

View File

@ -2,15 +2,9 @@
<project version="4"> <project version="4">
<component name="ChangeListManager"> <component name="ChangeListManager">
<list default="true" id="152ea650-8e02-4ed6-aa8c-04d44b275be4" name="Default Changelist" comment=""> <list default="true" id="152ea650-8e02-4ed6-aa8c-04d44b275be4" name="Default Changelist" comment="">
<change beforePath="" afterPath="$PROJECT_DIR$/path.py" />
<change beforePath="$PROJECT_DIR$/.idea/Test.iml" afterPath="$PROJECT_DIR$/.idea/Test.iml" />
<change beforePath="$PROJECT_DIR$/.idea/misc.xml" afterPath="$PROJECT_DIR$/.idea/misc.xml" />
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" afterPath="$PROJECT_DIR$/.idea/workspace.xml" /> <change beforePath="$PROJECT_DIR$/.idea/workspace.xml" afterPath="$PROJECT_DIR$/.idea/workspace.xml" />
<change beforePath="$PROJECT_DIR$/game.py" afterPath="$PROJECT_DIR$/game.py" /> <change beforePath="$PROJECT_DIR$/game.py" afterPath="$PROJECT_DIR$/game.py" />
<change beforePath="$PROJECT_DIR$/gridElement.py" afterPath="$PROJECT_DIR$/gridElement.py" /> <change beforePath="$PROJECT_DIR$/gridElement.py" afterPath="$PROJECT_DIR$/gridElement.py" />
<change beforePath="$PROJECT_DIR$/orderTable.py" afterPath="$PROJECT_DIR$/orderTable.py" />
<change beforePath="$PROJECT_DIR$/pool.py" afterPath="$PROJECT_DIR$/pool.py" />
<change beforePath="$PROJECT_DIR$/table.py" afterPath="$PROJECT_DIR$/table.py" />
<change beforePath="$PROJECT_DIR$/waiter.py" afterPath="$PROJECT_DIR$/waiter.py" /> <change beforePath="$PROJECT_DIR$/waiter.py" afterPath="$PROJECT_DIR$/waiter.py" />
</list> </list>
<option name="EXCLUDED_CONVERTED_TO_IGNORED" value="true" /> <option name="EXCLUDED_CONVERTED_TO_IGNORED" value="true" />
@ -38,8 +32,8 @@
<file leaf-file-name="game.py" pinned="false" current-in-tab="false"> <file leaf-file-name="game.py" pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/game.py"> <entry file="file://$PROJECT_DIR$/game.py">
<provider selected="true" editor-type-id="text-editor"> <provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="1145"> <state relative-caret-position="-153">
<caret line="87" column="0" lean-forward="true" selection-start-line="87" selection-start-column="0" selection-end-line="87" selection-end-column="0" /> <caret line="21" column="96" lean-forward="false" selection-start-line="21" selection-start-column="96" selection-end-line="21" selection-end-column="96" />
<folding> <folding>
<element signature="e#0#18#0" expanded="true" /> <element signature="e#0#18#0" expanded="true" />
</folding> </folding>
@ -51,7 +45,7 @@
<entry file="file://$PROJECT_DIR$/gridElement.py"> <entry file="file://$PROJECT_DIR$/gridElement.py">
<provider selected="true" editor-type-id="text-editor"> <provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="204"> <state relative-caret-position="204">
<caret line="12" column="0" lean-forward="false" selection-start-line="12" selection-start-column="0" selection-end-line="12" selection-end-column="0" /> <caret line="12" column="0" lean-forward="true" selection-start-line="12" selection-start-column="0" selection-end-line="12" selection-end-column="0" />
<folding> <folding>
<element signature="e#0#13#0" expanded="true" /> <element signature="e#0#13#0" expanded="true" />
</folding> </folding>
@ -86,8 +80,8 @@
<file leaf-file-name="pool.py" pinned="false" current-in-tab="false"> <file leaf-file-name="pool.py" pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/pool.py"> <entry file="file://$PROJECT_DIR$/pool.py">
<provider selected="true" editor-type-id="text-editor"> <provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="51"> <state relative-caret-position="170">
<caret line="3" column="0" lean-forward="true" selection-start-line="3" selection-start-column="0" selection-end-line="3" selection-end-column="0" /> <caret line="10" column="0" lean-forward="true" selection-start-line="10" selection-start-column="0" selection-end-line="10" selection-end-column="0" />
<folding> <folding>
<element signature="e#0#13#0" expanded="true" /> <element signature="e#0#13#0" expanded="true" />
</folding> </folding>
@ -98,8 +92,8 @@
<file leaf-file-name="orderTable.py" pinned="false" current-in-tab="false"> <file leaf-file-name="orderTable.py" pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/orderTable.py"> <entry file="file://$PROJECT_DIR$/orderTable.py">
<provider selected="true" editor-type-id="text-editor"> <provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="51"> <state relative-caret-position="187">
<caret line="3" column="0" lean-forward="true" selection-start-line="3" selection-start-column="0" selection-end-line="3" selection-end-column="0" /> <caret line="11" column="32" lean-forward="true" selection-start-line="11" selection-start-column="32" selection-end-line="11" selection-end-column="32" />
<folding> <folding>
<element signature="e#0#13#0" expanded="true" /> <element signature="e#0#13#0" expanded="true" />
</folding> </folding>
@ -110,8 +104,8 @@
<file leaf-file-name="waiter.py" pinned="false" current-in-tab="true"> <file leaf-file-name="waiter.py" pinned="false" current-in-tab="true">
<entry file="file://$PROJECT_DIR$/waiter.py"> <entry file="file://$PROJECT_DIR$/waiter.py">
<provider selected="true" editor-type-id="text-editor"> <provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="-130"> <state relative-caret-position="448">
<caret line="3" column="87" lean-forward="true" selection-start-line="3" selection-start-column="87" selection-end-line="3" selection-end-column="87" /> <caret line="51" column="42" lean-forward="false" selection-start-line="51" selection-start-column="42" selection-end-line="51" selection-end-column="42" />
<folding> <folding>
<element signature="e#0#13#0" expanded="true" /> <element signature="e#0#13#0" expanded="true" />
</folding> </folding>
@ -147,9 +141,9 @@
<option value="$PROJECT_DIR$/pool.py" /> <option value="$PROJECT_DIR$/pool.py" />
<option value="$PROJECT_DIR$/table.py" /> <option value="$PROJECT_DIR$/table.py" />
<option value="$PROJECT_DIR$/path.py" /> <option value="$PROJECT_DIR$/path.py" />
<option value="$PROJECT_DIR$/waiter.py" />
<option value="$PROJECT_DIR$/gridElement.py" /> <option value="$PROJECT_DIR$/gridElement.py" />
<option value="$PROJECT_DIR$/game.py" /> <option value="$PROJECT_DIR$/game.py" />
<option value="$PROJECT_DIR$/waiter.py" />
</list> </list>
</option> </option>
</component> </component>
@ -494,23 +488,11 @@
<state /> <state />
</provider> </provider>
</entry> </entry>
<entry file="file://$PROJECT_DIR$/pool.py"> <entry file="file://$PROJECT_DIR$/order.py">
<provider selected="true" editor-type-id="text-editor"> <provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="51"> <state relative-caret-position="102">
<caret line="3" column="0" lean-forward="true" selection-start-line="3" selection-start-column="0" selection-end-line="3" selection-end-column="0" /> <caret line="6" column="0" lean-forward="false" selection-start-line="6" selection-start-column="0" selection-end-line="6" selection-end-column="0" />
<folding> <folding />
<element signature="e#0#13#0" expanded="true" />
</folding>
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/gridElement.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="204">
<caret line="12" column="0" lean-forward="false" selection-start-line="12" selection-start-column="0" selection-end-line="12" selection-end-column="0" />
<folding>
<element signature="e#0#13#0" expanded="true" />
</folding>
</state> </state>
</provider> </provider>
</entry> </entry>
@ -534,28 +516,40 @@
</state> </state>
</provider> </provider>
</entry> </entry>
<entry file="file://$PROJECT_DIR$/orderTable.py"> <entry file="file://$PROJECT_DIR$/pool.py">
<provider selected="true" editor-type-id="text-editor"> <provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="51"> <state relative-caret-position="170">
<caret line="3" column="0" lean-forward="true" selection-start-line="3" selection-start-column="0" selection-end-line="3" selection-end-column="0" /> <caret line="10" column="0" lean-forward="true" selection-start-line="10" selection-start-column="0" selection-end-line="10" selection-end-column="0" />
<folding> <folding>
<element signature="e#0#13#0" expanded="true" /> <element signature="e#0#13#0" expanded="true" />
</folding> </folding>
</state> </state>
</provider> </provider>
</entry> </entry>
<entry file="file://$PROJECT_DIR$/order.py"> <entry file="file://$PROJECT_DIR$/orderTable.py">
<provider selected="true" editor-type-id="text-editor"> <provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="102"> <state relative-caret-position="187">
<caret line="6" column="0" lean-forward="false" selection-start-line="6" selection-start-column="0" selection-end-line="6" selection-end-column="0" /> <caret line="11" column="32" lean-forward="true" selection-start-line="11" selection-start-column="32" selection-end-line="11" selection-end-column="32" />
<folding /> <folding>
<element signature="e#0#13#0" expanded="true" />
</folding>
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/gridElement.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="204">
<caret line="12" column="0" lean-forward="true" selection-start-line="12" selection-start-column="0" selection-end-line="12" selection-end-column="0" />
<folding>
<element signature="e#0#13#0" expanded="true" />
</folding>
</state> </state>
</provider> </provider>
</entry> </entry>
<entry file="file://$PROJECT_DIR$/game.py"> <entry file="file://$PROJECT_DIR$/game.py">
<provider selected="true" editor-type-id="text-editor"> <provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="1145"> <state relative-caret-position="-153">
<caret line="87" column="0" lean-forward="true" selection-start-line="87" selection-start-column="0" selection-end-line="87" selection-end-column="0" /> <caret line="21" column="96" lean-forward="false" selection-start-line="21" selection-start-column="96" selection-end-line="21" selection-end-column="96" />
<folding> <folding>
<element signature="e#0#18#0" expanded="true" /> <element signature="e#0#18#0" expanded="true" />
</folding> </folding>
@ -564,8 +558,8 @@
</entry> </entry>
<entry file="file://$PROJECT_DIR$/waiter.py"> <entry file="file://$PROJECT_DIR$/waiter.py">
<provider selected="true" editor-type-id="text-editor"> <provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="-130"> <state relative-caret-position="448">
<caret line="3" column="87" lean-forward="true" selection-start-line="3" selection-start-column="87" selection-end-line="3" selection-end-column="87" /> <caret line="51" column="42" lean-forward="false" selection-start-line="51" selection-start-column="42" selection-end-line="51" selection-end-column="42" />
<folding> <folding>
<element signature="e#0#13#0" expanded="true" /> <element signature="e#0#13#0" expanded="true" />
</folding> </folding>

Binary file not shown.

View File

@ -19,7 +19,8 @@ class Game(object):
self.idOrder = 0 self.idOrder = 0
self.idItem = -1 self.idItem = -1
self.idOrderTable = 0 self.idOrderTable = 0
self.waiter = Waiter(5, 0, self) #Waiter jest atrybutem klasy Game self.waiter = Waiter(5, 0, self) #Waiter jest atrybutem klasy Game i nie ma go w gridzie
self.waiterMovesHistory = []
pygame.display.set_caption('Automatic Waiter') pygame.display.set_caption('Automatic Waiter')
self.background = pygame.image.load("./Images/tlo.jpg") self.background = pygame.image.load("./Images/tlo.jpg")

View File

@ -11,7 +11,7 @@ class GridElement(object):
game.idItem += 1 game.idItem += 1
self.number = game.idItem self.number = game.idItem
#Cała matematyka rysowania odbywa się tutaj #Cała matematyka skalowania odbywa się tutaj
def draw(self): def draw(self):
self.rect = pygame.Rect(self.position.x * self.game.gridElementWidth, self.position.y * self.game.gridElementHeight, self.game.gridElementWidth, self.game.gridElementHeight) self.rect = pygame.Rect(self.position.x * self.game.gridElementWidth, self.position.y * self.game.gridElementHeight, self.game.gridElementWidth, self.game.gridElementHeight)
self.game.screen.blit(self.image, (self.position.x * self.game.gridElementWidth, self.position.y * self.game.gridElementHeight)) self.game.screen.blit(self.image, (self.position.x * self.game.gridElementWidth, self.position.y * self.game.gridElementHeight))

View File

@ -1,4 +1,5 @@
import pygame import pygame
from pygame.math import Vector2
from gridElement import GridElement from gridElement import GridElement
#Klasa Waiter dziedziczy z klasy GridElement ale obiekt Waiter nie należy do listy grid #Klasa Waiter dziedziczy z klasy GridElement ale obiekt Waiter nie należy do listy grid
@ -10,48 +11,43 @@ class Waiter(GridElement):
self.image.set_colorkey((0, 0, 0)) self.image.set_colorkey((0, 0, 0))
self.type = "waiter" self.type = "waiter"
def moveLeft(self, game): #Waiter może wejść tylko na pole które znajduje się na gridzie i ma atrybut type równy "path"
#metoda move dodaje poprzednią pozycję waitera do listy waiterMovesHistory
#aktualna pozycja waitara jest w obiekcie position typu Vector2 (dziedziczonym z GridElement)
def move(self, game):
keys = pygame.key.get_pressed()
lastPosition = Vector2(self.position.x, self.position.y)
if keys[pygame.K_LEFT]:
if int(self.position.x) != 0: if int(self.position.x) != 0:
collisionObject = game.grid[int(self.position.y)][int(self.position.x) - 1] collisionObject = game.grid[int(self.position.y)][int(self.position.x) - 1]
if collisionObject.type == "path": if collisionObject.type == "path":
self.position.x -= 1 self.position.x -= 1
else: else:
pass pass
if keys[pygame.K_RIGHT]:
def moveRight(self, game):
if int(self.position.x) != game.x - 1: if int(self.position.x) != game.x - 1:
collisionObject = game.grid[int(self.position.y)][int(self.position.x) + 1] collisionObject = game.grid[int(self.position.y)][int(self.position.x) + 1]
if collisionObject.type == "path": if collisionObject.type == "path":
self.position.x += 1 self.position.x += 1
else: else:
pass pass
if keys[pygame.K_UP]:
def moveUp(self, game):
if int(self.position.y) != 0: if int(self.position.y) != 0:
collisionObject = game.grid[int(self.position.y) - 1][int(self.position.x)] collisionObject = game.grid[int(self.position.y) - 1][int(self.position.x)]
if collisionObject.type == "path": if collisionObject.type == "path":
self.position.y -= 1 self.position.y -= 1
else: else:
pass pass
if keys[pygame.K_DOWN]:
def moveDown(self, game):
if int(self.position.y) != game.y - 1: if int(self.position.y) != game.y - 1:
collisionObject = game.grid[int(self.position.y) + 1][int(self.position.x)] collisionObject = game.grid[int(self.position.y) + 1][int(self.position.x)]
if collisionObject.type == "path": if collisionObject.type == "path":
self.position.y += 1 self.position.y += 1
else: else:
pass pass
def move(self, game):
keys = pygame.key.get_pressed()
if keys[pygame.K_LEFT]:
self.moveLeft(game)
if keys[pygame.K_RIGHT]:
self.moveRight(game)
if keys[pygame.K_UP]:
self.moveUp(game)
if keys[pygame.K_DOWN]:
self.moveDown(game)
if keys[pygame.K_s]: if keys[pygame.K_s]:
game.showGrid(game.grid) game.showGrid(game.grid)
if(lastPosition.x != self.position.x or lastPosition.y != self.position.y):
game.waiterMovesHistory.append(lastPosition)
print(game.waiterMovesHistory)