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">
<component name="ChangeListManager">
<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$/game.py" afterPath="$PROJECT_DIR$/game.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" />
</list>
<option name="EXCLUDED_CONVERTED_TO_IGNORED" value="true" />
@ -38,8 +32,8 @@
<file leaf-file-name="game.py" pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/game.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="1145">
<caret line="87" column="0" lean-forward="true" selection-start-line="87" selection-start-column="0" selection-end-line="87" selection-end-column="0" />
<state relative-caret-position="-153">
<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>
<element signature="e#0#18#0" expanded="true" />
</folding>
@ -51,7 +45,7 @@
<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" />
<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>
@ -86,8 +80,8 @@
<file leaf-file-name="pool.py" pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/pool.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="51">
<caret line="3" column="0" lean-forward="true" selection-start-line="3" selection-start-column="0" selection-end-line="3" selection-end-column="0" />
<state relative-caret-position="170">
<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>
<element signature="e#0#13#0" expanded="true" />
</folding>
@ -98,8 +92,8 @@
<file leaf-file-name="orderTable.py" pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/orderTable.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="51">
<caret line="3" column="0" lean-forward="true" selection-start-line="3" selection-start-column="0" selection-end-line="3" selection-end-column="0" />
<state relative-caret-position="187">
<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>
<element signature="e#0#13#0" expanded="true" />
</folding>
@ -110,8 +104,8 @@
<file leaf-file-name="waiter.py" pinned="false" current-in-tab="true">
<entry file="file://$PROJECT_DIR$/waiter.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="-130">
<caret line="3" column="87" lean-forward="true" selection-start-line="3" selection-start-column="87" selection-end-line="3" selection-end-column="87" />
<state relative-caret-position="448">
<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>
<element signature="e#0#13#0" expanded="true" />
</folding>
@ -147,9 +141,9 @@
<option value="$PROJECT_DIR$/pool.py" />
<option value="$PROJECT_DIR$/table.py" />
<option value="$PROJECT_DIR$/path.py" />
<option value="$PROJECT_DIR$/waiter.py" />
<option value="$PROJECT_DIR$/gridElement.py" />
<option value="$PROJECT_DIR$/game.py" />
<option value="$PROJECT_DIR$/waiter.py" />
</list>
</option>
</component>
@ -494,23 +488,11 @@
<state />
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/pool.py">
<entry file="file://$PROJECT_DIR$/order.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="51">
<caret line="3" column="0" lean-forward="true" selection-start-line="3" selection-start-column="0" selection-end-line="3" selection-end-column="0" />
<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 relative-caret-position="102">
<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 />
</state>
</provider>
</entry>
@ -534,28 +516,40 @@
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/orderTable.py">
<entry file="file://$PROJECT_DIR$/pool.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="51">
<caret line="3" column="0" lean-forward="true" selection-start-line="3" selection-start-column="0" selection-end-line="3" selection-end-column="0" />
<state relative-caret-position="170">
<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>
<element signature="e#0#13#0" expanded="true" />
</folding>
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/order.py">
<entry file="file://$PROJECT_DIR$/orderTable.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="102">
<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 />
<state relative-caret-position="187">
<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>
<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>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/game.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="1145">
<caret line="87" column="0" lean-forward="true" selection-start-line="87" selection-start-column="0" selection-end-line="87" selection-end-column="0" />
<state relative-caret-position="-153">
<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>
<element signature="e#0#18#0" expanded="true" />
</folding>
@ -564,8 +558,8 @@
</entry>
<entry file="file://$PROJECT_DIR$/waiter.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="-130">
<caret line="3" column="87" lean-forward="true" selection-start-line="3" selection-start-column="87" selection-end-line="3" selection-end-column="87" />
<state relative-caret-position="448">
<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>
<element signature="e#0#13#0" expanded="true" />
</folding>

Binary file not shown.

View File

@ -19,7 +19,8 @@ class Game(object):
self.idOrder = 0
self.idItem = -1
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')
self.background = pygame.image.load("./Images/tlo.jpg")

View File

@ -11,7 +11,7 @@ class GridElement(object):
game.idItem += 1
self.number = game.idItem
#Cała matematyka rysowania odbywa się tutaj
#Cała matematyka skalowania odbywa się tutaj
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.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
from pygame.math import Vector2
from gridElement import GridElement
#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.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:
collisionObject = game.grid[int(self.position.y)][int(self.position.x) - 1]
if collisionObject.type == "path":
self.position.x -= 1
else:
pass
def moveRight(self, game):
if keys[pygame.K_RIGHT]:
if int(self.position.x) != game.x - 1:
collisionObject = game.grid[int(self.position.y)][int(self.position.x) + 1]
if collisionObject.type == "path":
self.position.x += 1
else:
pass
def moveUp(self, game):
if keys[pygame.K_UP]:
if int(self.position.y) != 0:
collisionObject = game.grid[int(self.position.y) - 1][int(self.position.x)]
if collisionObject.type == "path":
self.position.y -= 1
else:
pass
def moveDown(self, game):
if keys[pygame.K_DOWN]:
if int(self.position.y) != game.y - 1:
collisionObject = game.grid[int(self.position.y) + 1][int(self.position.x)]
if collisionObject.type == "path":
self.position.y += 1
else:
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]:
game.showGrid(game.grid)
if(lastPosition.x != self.position.x or lastPosition.y != self.position.y):
game.waiterMovesHistory.append(lastPosition)
print(game.waiterMovesHistory)