From 7113805f981b883f8aed54e50d8dba6f74ca3975 Mon Sep 17 00:00:00 2001 From: Andrzej Date: Sat, 24 Apr 2021 03:05:17 +0200 Subject: [PATCH] Change way to moving --- bin/Classess/__pycache__/Field.cpython-37.pyc | Bin 2867 -> 3171 bytes .../__pycache__/Player.cpython-37.pyc | Bin 1616 -> 1832 bytes bin/classess/Player.py | 38 ++++++--- bin/main/main.py | 79 ++++++++++++++---- files/arrow/arrow_east.png | Bin 0 -> 854 bytes files/arrow/arrow_north.png | Bin 0 -> 847 bytes files/arrow/arrow_south.png | Bin 0 -> 844 bytes files/arrow/arrow_west.png | Bin 0 -> 853 bytes 8 files changed, 91 insertions(+), 26 deletions(-) create mode 100644 files/arrow/arrow_east.png create mode 100644 files/arrow/arrow_north.png create mode 100644 files/arrow/arrow_south.png create mode 100644 files/arrow/arrow_west.png diff --git a/bin/Classess/__pycache__/Field.cpython-37.pyc b/bin/Classess/__pycache__/Field.cpython-37.pyc index 26164ac43eab47dbc198284d5dacfc5afad6af7d..983225f31e4c1c66555b4f920b78340e3b7aa2c7 100644 GIT binary patch delta 415 zcmXw!O-n*S6o%(quU@@+)x3TeLS*B(ilE6it zKaiUiK`Z}AtpbBK?Q0c8t7gCs%;C)YJRCUV@JH0xHVmDJ>i%Axw(pE@MF&)&)4d^e zpgMJ2JGrY*nvNb6Ne}v@VsJ0_aX+7-Zt5ARA_)i{Xqr4ojR64RA^D#gUg{gzg%cK8 z_}(0mDF+^*5GB+vp4=3edQss;n=x+ssTmYsL2dk?Bmj2tSzR1| z+S-6MbqI6#W!u7nJtd|Sdk5n9Wi-0JJYm9;-h}igOM2tm>5G-PFhLB(shG_)B!X^k? z$o&J_i2XK}c4BFpRR9N{Y^|c$?->#^3Y_(#$(l zamARO(R^^h1{1JlwB5S;O`5WECKzwvi!leaWMX(wnU{ns%-5A;pK;a`tUDO>`iw`I zF&WfxWZs1eM>=o(t9(OE5xUkk?BJnwlwDQDnu<*oTlj1(LWm#MLa;20iP1i2?jN_i M9bQ$uhNj*51FqXvZvX%Q diff --git a/bin/Classess/__pycache__/Player.cpython-37.pyc b/bin/Classess/__pycache__/Player.cpython-37.pyc index 8a5408310a73f2c2e8645b19e9c62197a4f4e656..bfd1607f4955602a542182854a2deba06105dabc 100644 GIT binary patch literal 1832 zcmcIkNpBM|6!xr{Y~3VO_Dvv>3#t&C5JD^sZ6q2HiwaRBGsM$&+HBZUN~+%Ahrp3P zz?Bn!!dFiH3!M0#CzCX&a6n=#e}4Y_?D_2X?EB?%f#Lhs`S7|QF!qBw+2_Kzi>fXG z1Zyy1H7sE_Y*a@$4R?tNS9l+p@FMSn)9{7=j8$^+cb~ENs{=S5nha}V<&TWk6)sw=D}1z`$cX^0FY=;*HYbXrgf^`PR0SQ8(f5^~fCPLT%;V zQk6feHLBWGNz~WVnO`VnIDq$W#6agoETdKu_qw_;GL@digx(G}a(LVc*Q1Ow(uUMb z>P0dq8QM(BR4hn|+G}5!Jc@n(yi~o_d@^{j5z0F;5+*Q?h)N0HtIs-yVJvY*_?^c(kYwJQc|Vi+_dIdVs9~dc@L4N z0B>41n2n&Dz9Z6}V*+K@_bEdvt|TdP3ZRP*pWa)k^3~en^JO_rqn4bfQQBn+$Bf@f z?_Jzoe;TiEB(w*GG{;6}Prn6<37(x0OdkJDZ;4dWNlSWa!BsJUrsX-cI-0ShUHB$s;C@3EA`tnpA!SgHl3RTeh6r zW1p%mpy^h;hJN2jh$w7tAskml%`eUR_dZ${Yb6btXMP#gnsSpCLF$aGKy0 z;1A*O)8oDc4@FU9Rsk1wTzAV8NmQ@o>85wXPQJwqbNXlG^T?hiWhihq+ZGCV6|3Xe7wqEj;vSmBuza_PzGqf d_hu8%qnUEpUvzLg6?}(Y2u1&MEmIuV`2}#cd`AEP literal 1616 zcma)6OHbQC5MIa6Jb0xKIQ2{pMHQ-4RH3RoQixPi1XQ$9q^-#sNC-~4HZ4Zn%Ae^U z=s&3XAAId8$6kBtH)}ftnxcBOv$NxGXJ@{h-PMVS0>c;oh(7!>8T(0->@%ReL=Wa6 z1Zyy%H8hcH6L zr%*fwpA0_X`HGQWVPJ$`VPQ0dEgX!N$cq9-TNJTJDYmw|Zsf_9mU^X;{H~z~OAtc4 zWIU13It;TMMzZRmL6%vvnF3aBDQOD^-+Fz3(AfZ;Rh-y9=RxSoFt(#q$+ym=^!$*Y z$3r!W3$?A4jVj-*HL9@@gkC?M%5bifZUpo#LsZd#^ty*%nViICzvrvZo7>Uau`5rT zf!ptUvU$+P+2)rO@CMhrUquAlR?YBeDi&z)XVy0PW4q6H0#Z-#Ta5s3O^b}8h zCZ zjErA8EJ@W>aimQ;)nHtFwX?ES<@>euy-i7pNr%j(#JpLpZEWsI)F_iBh>9jBNT=iz zF$FCyZuLI3{iB`s(Q$YmhF}_kY13(QK+dFgQBLU@0gq?s9E&rC=19w(m~!!&qoo@h zshRGt0;jT8D@?2iLvYm5Xnvb1wPu7VHP4umGuVHShZtolAz{dn#C2n`OyUk=3Q4Z7 zy~FSkpeZk9#Y(?S>bFIq-QXB;i+@N;#QQpHebtIj= self.x_start: self.current_x -= self.step self.current_array_x -= 1 - elif self.current_y - self.step >= self.y_start: - self.current_x = FRAME_WIDTH - self.step - self.current_array_x = 9 - self.current_array_y -= 1 - self.current_y -= self.step + # # Changes the line up + # elif self.current_y - self.step >= self.y_start: + # self.current_x = FRAME_WIDTH - self.step + # self.current_array_x = 9 + # self.current_array_y -= 1 + # self.current_y -= self.step def MovingUp(self): if self.current_y - self.step >= self.y_start: @@ -46,3 +54,13 @@ class Player(object): if self.current_y + self.step < FRAME_HEIGHT: self.current_y += self.step self.current_array_y += 1 + + def Moving(self): + if self.direction == "north": + self.MovingUp() + if self.direction == "south": + self.MovingDown() + if self.direction == "west": + self.MovingLeft() + if self.direction == "east": + self.MovingRight() diff --git a/bin/main/main.py b/bin/main/main.py index 8918dbf..05fe255 100644 --- a/bin/main/main.py +++ b/bin/main/main.py @@ -1,10 +1,10 @@ +import os import random from tkinter import * -import os -from bin.classess.Player import Player from bin.classess.Field import Field from bin.classess.Mine import Mine +from bin.classess.Player import Player WINDOW_X = 533 + 1200 WINDOW_Y = 950 @@ -21,6 +21,20 @@ player = Player() field = Field() +def Arrow(direction): + image = "" + if direction == "north": + image = player.arrow_north_image + elif direction == "south": + image = player.arrow_south_image + elif direction == "west": + image = player.arrow_west_image + elif direction == "east": + image = player.arrow_east_image + + field.small_field_canvas.create_image(player.current_x, player.current_y, anchor=NW, image=image) + + # Putting images def Fill(): field.PuttingSmallImages() @@ -46,28 +60,48 @@ def Rectangle(): player.current_y + player.step - 2, width=3, outline='blue2') +def Next_direction(side): + # Define next direction + current_direction = player.direction + t = -1 + for i in range(4): + if player.directions[i] == current_direction: + t = i + break + + # Write next direction to Player + if side == "Right": + player.direction = player.directions[(t + 1) % 4] + elif side == "Left": + player.direction = player.directions[(t - 1) % 4] + + return player.direction + + def Moving(event): # Moving if event.keysym == "Right": - player.MovingRight() + # player.MovingRight() field.Moving() Fill() - Rectangle() + next_direction = Next_direction(event.keysym) + Arrow(next_direction) elif event.keysym == "Left": - player.MovingLeft() + # player.MovingLeft() field.Moving() Fill() - Rectangle() + next_direction = Next_direction(event.keysym) + Arrow(next_direction) elif event.keysym == "Up": - player.MovingUp() + player.Moving() field.Moving() Fill() - Rectangle() - elif event.keysym == "Down": - player.MovingDown() - field.Moving() - Fill() - Rectangle() + Arrow(player.direction) + # elif event.keysym == "space": + # player.MovingDown() + # field.Moving() + # Fill() + # Arrow(player.arrow_south_image) def ImagesInArray(directory, array): @@ -108,7 +142,7 @@ def CellDesignation(array, color): def Action(event): - if event.keysym in ["Right", "Left", "Up", "Down"]: + if event.keysym in ["Right", "Left", "Up", "space"]: Moving(event) elif event.keysym in ["1", "2"]: if event.keysym == "1": @@ -199,10 +233,23 @@ def main(): large_directory = "../../files/large_images" ImagesInArray(large_directory, field.large_image_array) + # Add arrow image to Player class + images = [] + for file in os.listdir("../../files/arrow"): + path = f"../../files/arrow/{file}" + img = PhotoImage(master=field.small_field_canvas, file=path) + images.append(img) + + player.arrow_east_image = images[0] + player.arrow_north_image = images[1] + player.arrow_south_image = images[2] + player.arrow_west_image = images[3] + # Filling window with images Fill() - # Drawing rectangle (player) - Rectangle() + # Drawing arrow (player) + Arrow(player.direction) + # Rectangle() # Binding keyboard press to function field.win.bind("", Action) # Starting mainloop for window diff --git a/files/arrow/arrow_east.png b/files/arrow/arrow_east.png new file mode 100644 index 0000000000000000000000000000000000000000..f1e1038f5968acdac06b8d49a00bba6c0961ad44 GIT binary patch literal 854 zcmeAS@N?(olHy`uVBq!ia0vp^Mj*_=3?wxlRx|@C#^NA%C&rs6b?Si}mUKs7M+SzC z{oH>NS%GqV0X`wFKyi6_c^)1fAOj9qS%LCUz|0IX4+z-U*dPoD$;8A2WWZHIxIht3 zPENQ2EiEk|8)7&Y7s#bRAR{Bg$jB%mApvBwv$F$9US3|11kg#0j6hOEL1ZWhH0TBU`KONs@|uzmBmK`;*q^Uq+W43! zQ%h~$o>QE!73{qwX0UDB(<|u~!pSE8*QKhzQ|L;;q@w=C0_{14UCzl5gb!BwNM2@b zR$g<_;FjQ|X|J*;18w0f@Q5r1`b-#v85w5H0fq=;wx^3@h==#wYuAGg8wjulI3^VO ztY22{!@Jj+WAFEK|NnDnKTkVmGhy$?%BZ(*&bds~ITlr7Yh3t^mhqc(xYT+?-n+PfjeUagk*7D+ z-P$Ia>{)nE+Wp+8uBv)YyEs8QtrZnMXpbHTB}V~ zJY|~Hw);v+nBm+51k!KQJx#mE;$(S2C*#TdIowB7nJcY+(pEHs=xi=$lQs4&-#S4(;BDdYA2&2k ziB?APER5M09%TQj)b&R9`t9Fdn;ur3_jKiihmMn;-h3<{-fL>NE@s_6zQESv{jnL^ VZ>Cn;83W^j!PC{xWt~$(697Ff1D^l@ literal 0 HcmV?d00001 diff --git a/files/arrow/arrow_north.png b/files/arrow/arrow_north.png new file mode 100644 index 0000000000000000000000000000000000000000..fdb2e48bdd9c5170ef8c2d7b23f5781c15f7f358 GIT binary patch literal 847 zcmeAS@N?(olHy`uVBq!ia0vp^Mj*_=3?wxlRx|@C#^NA%C&rs6b?Si}mUKs7M+SzC z{oH>NS%GqV0X`wFKyi6_c^)1fAOj9qS%LCUz|0IX4+z-U*dPoD$;8A2WWZHIxIht3 zPENQ2EiEk|8)7&Y7s#bRAR{Bg$jB%mApvBwv$F$9US3|11kg#0j6hOEL1ZWhH0TBU`KONs@|uzmBmK`;*q^Uq+W43! zQ%h~$o>QE!73{qwX0UDB(<|u~!pSE8*QKhzQ|L;;q@w=C0_{14UCzl5gb!BwNM2@b zR$g<_;FjQ|X|J*;18w0f@Q5r1`b-#v85w5H0fq=;il>WXh==#vN!OzeIS916AKcIq zr_!{*P^nA8C1gY5`Ww6V{qLTU;;%5lY2BWHf2)hrp4C|2tFc) zQ%*#6i&poYrH|UKCP=y}ge()~(mmKj+`i|NVPedB7{@FU&%X+Hcf0evku3 O0)wZkpUXO@geCw--|-v( literal 0 HcmV?d00001 diff --git a/files/arrow/arrow_south.png b/files/arrow/arrow_south.png new file mode 100644 index 0000000000000000000000000000000000000000..8337cfb7cbd07a604356bc036f13e07615326576 GIT binary patch literal 844 zcmeAS@N?(olHy`uVBq!ia0vp^Mj*_=3?wxlRx|@C#^NA%C&rs6b?Si}mUKs7M+SzC z{oH>NS%GqV0X`wFKyi6_c^)1fAOj9qS%LCUz|0IX4+z-U*dPoD$;8A2WWZHIxIht3 zPENQ2EiEk|8)7&Y7s#bRAR{Bg$jB%mApvBwv$F$9US3|11kg#0j6hOEL1ZWhH0TBU`KONs@|uzmBmK`;*q^Uq+W43! zQ%h~$o>QE!73{qwX0UDB(<|u~!pSE8*QKhzQ|L;;q@w=C0_{14UCzl5gb!BwNM2@b zR$g<_;FjQ|X|J*;18w0f@Q5r1`b-#v85w5H0fq=;qNj^vh==#v%jwRC3$2qpQ2*@cBP#;fp-syG{EA+wu}^9v!YoNw9gu{QI~3Px*ZtU(UQ)*}|uM>-TYWC)v}-H0MSe z7?p4zI}ttWQpL3zho-88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