From bf74cff257ffffe611482c3d0a6950cd74506c78 Mon Sep 17 00:00:00 2001 From: Arkadiusz Date: Wed, 17 Apr 2019 00:28:24 +0100 Subject: [PATCH] Zmiana poruszania --- .idea/workspace.xml | 39 +++++++-------- __pycache__/waiter.cpython-37.pyc | Bin 3428 -> 3085 bytes game.py | 5 +- waiter.py | 78 ++++++++++++++++-------------- 4 files changed, 64 insertions(+), 58 deletions(-) diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 8cceaf6..f22b358 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -2,6 +2,7 @@ + @@ -428,25 +429,25 @@ + + + + + + + + + + - - + + - - - - - - - - - - \ No newline at end of file diff --git a/__pycache__/waiter.cpython-37.pyc b/__pycache__/waiter.cpython-37.pyc index 414dbb1462635635b93ed92550e9274f5efdcef0..c6c5b7aa134501b324109867d71e4281e4d81e6e 100644 GIT binary patch literal 3085 zcmb7G%Z?jG6s_v6ZnvM~Bq+&{5E32|-b_STfT9RRc`{7oM41c$%Tmj6bv*6(MRiXm zGcv2>8(7;*et>^KVu4s>QDT9_YJPzYoLg;s+D?O@t-4ipZ`G~xJ@-`AjdHob@ckrz zY_3-s`-3|3PoQxfCHe?LGRb?aLABN6eXC({c9%(8idRgEzB zeHFChp}Nv0#r(6-xQ-Itf(TfHOV+R?m)0xRuoHK1WwH8|5ZS^a5hc$IOQmtji_;lv&J&rpvn4#GW$P#Mpv# z#x|rI=f;+_&asy?%R|pz^zw0`Tbz`nJ>`?KnOTIN;-n(QlyfE>%vkG?$Esx5n_EBP zSpVn>#Nnxp%bWdHCx|ZZoBeK#2A!IH^cQT(oeS+I#@Y!jI<0=7-B51EL0`L3TLr;D zdz~Qmqwp}$!btu?^8;;%gIMQB!zhfy;o$4z<~Q0M9T-PWNQ-OH8@8m*wTFY}fr@o0 zg1h#xH&oAp11;i%QJ}qED~h+{U{n)WB*dBzO%+w z7n%0V%C;j%gcK%6#Pa-gBo^5|qx^ZpwmepvwJhY^>JF~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kjkuvvorUs;zmY+>!Q>sSK|nBay5>@v^jHMaW>*>a`bWj+S0 zWB5N;tpD+)<0sUNA#a&rXDcBMrSJ`~R689Rh@z!FK^;;^PXW`K ze(1M@wH+jh;ZZDZ;kesszm+&85+Ou41UPUXSn!ZOux`_z=rk>`As+_T>2!-~aAca`2svVs{_Otdz8Y)wWxwwuhJNvpep6=wa{WJR3KAbS~B@B}ODk|Bhe z0|3;gAjXSpX1vo^6C!glCZ10XoM*v0d*R|GfwZpz!}!F7qOl` zi~XVbc(5l1KLkM>@X2IwY4DG=j)VFFe2{F0X~m?N*zN)yF4!et9y{L%%wsG@U_R&l zgM&YTHQVlt0BztkKpV)1A$~oe9Yk)sv+y3}F%g|lpuF7~5AikQ8KOLn;W0p8jOVe| zm&EhAEk4Wg)?`AA06k`P=YYOoaZR8riv zSa(I>BZ7LX$NJ`chIea@s5@QK<6Vk*s>?uUgKiOYPC}Og-AmB930)d=Wzc03x-95A zUE0e5HhJ`DPD5HM7E}Rd*A|vTSuChJN`|2n+FA8py?D8$?%{B1)!SHE{$Wdffjz$J zZLh2Q_zG4_Yi~;GOYB&yUZ~x0uYG9FN(`Z7Uep{W3C|}+j(f8PrXglbLNhEw&)>({ zM7-4S0LKg4VKuY`orv_XR>cf&L7hzdSbuWdIoLDOfLc}H81Gw@L}_@-oZ#M?kzN+s z96aXhUDk)9-RzN7GA9E32+nu>J953|=Zfb~=xHQN919jiB00000 diff --git a/game.py b/game.py index c3d87cc..0b6e8d3 100644 --- a/game.py +++ b/game.py @@ -35,7 +35,8 @@ class Game(object): self.row.append(table) self.tableList.append(table) elif i == 4 and b == 9: - self.row.append(Waiter(self, i * 50, b * 50)) + self.waiter = Waiter(self, i * 50, b * 50) + self.row.append(self.waiter) self.waiterNumberInGrid.x = i self.waiterNumberInGrid.y = b elif (((b > 0 and b < 6) and (i > 0 and i < 9)) and not((i==1 or i == 8) and (b==1 or b==5))) \ @@ -54,7 +55,7 @@ class Game(object): sys.exit(0) self.draw() - self.grid[int(self.waiterNumberInGrid.y)][int(self.waiterNumberInGrid.x)].move(self) + self.waiter.move(self) pygame.display.flip() #print(self.waiterNumberInGrid) self.fpsClock.tick(10) diff --git a/waiter.py b/waiter.py index 168680a..6685865 100644 --- a/waiter.py +++ b/waiter.py @@ -9,6 +9,8 @@ class Waiter(object): self.size= self.game.screen.get_size() self.x = x self.y = y + self.positionX = int(x / 50) + self.positionY = int(y / 50) self.image = pygame.image.load("./Images/waiter.png").convert() self.image.set_colorkey((255, 255, 255)) self.type = "waiter" @@ -16,60 +18,62 @@ class Waiter(object): def moveLeft(self, game): - if int(game.waiterNumberInGrid.x) != 0: - collisionObject = game.grid[int(game.waiterNumberInGrid.y)][int(game.waiterNumberInGrid.x-1)] + if self.positionX != 0: + collisionObject = game.grid[self.positionY][self.positionX - 1] if collisionObject.type == "gridElement": - game.grid[int(game.waiterNumberInGrid.y)][int(game.waiterNumberInGrid.x - 1)].x += 50 - game.grid[int(game.waiterNumberInGrid.y)][int(game.waiterNumberInGrid.x)].x -= 50 - game.grid[int(game.waiterNumberInGrid.y)][int(game.waiterNumberInGrid.x - 1)], \ - game.grid[int(game.waiterNumberInGrid.y)][int(game.waiterNumberInGrid.x)] = \ - game.grid[int(game.waiterNumberInGrid.y)][int(game.waiterNumberInGrid.x)], \ - game.grid[int(game.waiterNumberInGrid.y)][int(game.waiterNumberInGrid.x-1)] - game.waiterNumberInGrid.x -= 1 + game.grid[self.positionY][self.positionX - 1].x += 50 + game.grid[self.positionY][self.positionX].x -= 50 + game.grid[self.positionY][self.positionX - 1], \ + game.grid[self.positionY][self.positionX] = \ + game.grid[self.positionY][self.positionX], \ + game.grid[self.positionY][self.positionX - 1] + self.positionX -= 1 + print(self.positionX) self.lastStep.append("Left") else: pass def moveRight(self, game): - if int(game.waiterNumberInGrid.x) != game.x-1: - collisionObject = game.grid[int(game.waiterNumberInGrid.y)][int(game.waiterNumberInGrid.x + 1)] + if self.positionX != game.x-1: + collisionObject = game.grid[self.positionY][self.positionX + 1] if collisionObject.type == "gridElement": - game.grid[int(game.waiterNumberInGrid.y)][int(game.waiterNumberInGrid.x + 1)].x -= 50 - game.grid[int(game.waiterNumberInGrid.y)][int(game.waiterNumberInGrid.x)].x += 50 - game.grid[int(game.waiterNumberInGrid.y)][int(game.waiterNumberInGrid.x + 1)], \ - game.grid[int(game.waiterNumberInGrid.y)][int(game.waiterNumberInGrid.x)] = \ - game.grid[int(game.waiterNumberInGrid.y)][int(game.waiterNumberInGrid.x)], \ - game.grid[int(game.waiterNumberInGrid.y)][int(game.waiterNumberInGrid.x + 1)] - game.waiterNumberInGrid.x += 1 + game.grid[self.positionY][self.positionX + 1].x -= 50 + game.grid[self.positionY][self.positionX].x += 50 + game.grid[self.positionY][self.positionX + 1], \ + game.grid[self.positionY][self.positionX] = \ + game.grid[self.positionY][self.positionX], \ + game.grid[self.positionY][self.positionX + 1] + self.positionX += 1 + print(self.positionX) self.lastStep.append("Right") else: pass def moveUp(self, game): - if int(game.waiterNumberInGrid.y) != 0: - collisionObject = game.grid[int(game.waiterNumberInGrid.y-1)][int(game.waiterNumberInGrid.x)] + if self.positionY != 0: + collisionObject = game.grid[self.positionY - 1][self.positionX] if collisionObject.type == "gridElement": - game.grid[int(game.waiterNumberInGrid.y-1)][int(game.waiterNumberInGrid.x)].y += 50 - game.grid[int(game.waiterNumberInGrid.y)][int(game.waiterNumberInGrid.x)].y -= 50 - game.grid[int(game.waiterNumberInGrid.y-1)][int(game.waiterNumberInGrid.x)], \ - game.grid[int(game.waiterNumberInGrid.y)][int(game.waiterNumberInGrid.x)] = \ - game.grid[int(game.waiterNumberInGrid.y)][int(game.waiterNumberInGrid.x)], \ - game.grid[int(game.waiterNumberInGrid.y-1)][int(game.waiterNumberInGrid.x)] - game.waiterNumberInGrid.y -= 1 + game.grid[self.positionY - 1][self.positionX].y += 50 + game.grid[self.positionY][self.positionX].y -= 50 + game.grid[self.positionY - 1][self.positionX], \ + game.grid[self.positionY][self.positionX] = \ + game.grid[self.positionY][self.positionX], \ + game.grid[self.positionY - 1][self.positionX] + self.positionY -= 1 self.lastStep.append("Up") else: pass def moveDown(self, game): - if int(game.waiterNumberInGrid.y) != game.y-1: - collisionObject = game.grid[int(game.waiterNumberInGrid.y + 1)][int(game.waiterNumberInGrid.x)] + if self.positionY != game.y-1: + collisionObject = game.grid[self.positionY + 1][self.positionX] if collisionObject.type == "gridElement": - game.grid[int(game.waiterNumberInGrid.y + 1)][int(game.waiterNumberInGrid.x)].y -= 50 - game.grid[int(game.waiterNumberInGrid.y)][int(game.waiterNumberInGrid.x)].y += 50 - game.grid[int(game.waiterNumberInGrid.y + 1)][int(game.waiterNumberInGrid.x)], \ - game.grid[int(game.waiterNumberInGrid.y)][int(game.waiterNumberInGrid.x)] = \ - game.grid[int(game.waiterNumberInGrid.y)][int(game.waiterNumberInGrid.x)], \ - game.grid[int(game.waiterNumberInGrid.y + 1)][int(game.waiterNumberInGrid.x)] - game.waiterNumberInGrid.y += 1 + game.grid[self.positionY + 1][self.positionX].y -= 50 + game.grid[self.positionY][self.positionX].y += 50 + game.grid[self.positionY + 1][self.positionX], \ + game.grid[self.positionY][self.positionX] = \ + game.grid[self.positionY][self.positionX], \ + game.grid[self.positionY + 1][self.positionX] + self.positionY += 1 self.lastStep.append("Down") else: pass @@ -93,5 +97,5 @@ class Waiter(object): def draw(self): self.rect1 = pygame.Rect(self.x, self.y, 50, 50) pygame.draw.rect(self.game.screen, (0, 150, 255), self.rect1) - print(self.lastStep) + #print(self.lastStep) self.game.screen.blit(self.image, (self.x, self.y))