From a88cb60fbd4cd9018bcc8cff5a90adff863dad50 Mon Sep 17 00:00:00 2001 From: dardwo Date: Sun, 26 Mar 2023 12:00:34 +0200 Subject: [PATCH 1/2] fix tractor movement, added function to tractor and plant --- __pycache__/settings.cpython-310.pyc | Bin 480 -> 492 bytes main.py | 21 +++++---- src/Plant.py | 12 ++++++ src/Tractor.py | 55 ++++++++++++++++++++---- src/__pycache__/map.cpython-310.pyc | Bin 1424 -> 1436 bytes src/__pycache__/plant.cpython-310.pyc | Bin 997 -> 1315 bytes src/__pycache__/tractor.cpython-310.pyc | Bin 929 -> 2085 bytes src/screen.py | 29 ------------- tractor.py | 33 -------------- 9 files changed, 71 insertions(+), 79 deletions(-) delete mode 100644 src/screen.py delete mode 100644 tractor.py diff --git a/__pycache__/settings.cpython-310.pyc b/__pycache__/settings.cpython-310.pyc index 534c1bf681553d1ec6fdaecccf818fb2d41dae40..4d2d62ec63cf3dde28f9c847e9e78970b06cb8d9 100644 GIT binary patch delta 165 zcmaFB{Dzr3pO=@50SH1BUWiU-2UNX<;oD2d{N@QO35Qlogm?Be*u-2BqK xl9dcaLLlQn#4mIG(BjmhV*QlFqRhmU^8BKz%Dm$2M17ak;_Qv1SHHQEI delta 153 zcmaFE{D7G|pO=@50SNBikekTeDtL=6IkBiHzvLEML4HYMN&c;g3nkdtf$~M{6ZdO! z@BmqUn!L9reh3S@#hsR!nv)V=o|#gTaf=7S$wqHER;AwJ1+$Ce6La%R n^Ga4S6iI=M0};Qp^)vEwQ}weFvrCioi%UvVG7~4SU~~Zh+QBu- diff --git a/main.py b/main.py index 6b262b8..26bbac1 100644 --- a/main.py +++ b/main.py @@ -9,7 +9,7 @@ from src.Plant import Plant # pygame initialization pygame.init() clock = pygame.time.Clock() -pygame.mouse.set_visible(False) +#pygame.mouse.set_visible(False) #GAME SCREEN screen = pygame.display.set_mode(SIZE) @@ -25,8 +25,10 @@ for line in range(26): pygame.draw.line(background, (0, 0, 0), (line * 36, 0), (line * 36, SIZE[1])) #TRACTOR -tractor = Tractor('oil','manual') +tractor = Tractor('oil','manual', 'fuel', 'fertilizer1') tractor_group = pygame.sprite.Group() +tractor.rect.x = 0 +tractor.rect.y = 0 tractor_group.add(tractor) #PLANTS @@ -42,13 +44,16 @@ if __name__ == "__main__": running = False pygame.quit() sys.exit() - if event.type == pygame.MOUSEBUTTONDOWN: - tractor.collect(plant_group) - - pygame.display.flip() + if event.type == pygame.KEYDOWN: + if event.key==pygame.K_RETURN: + tractor.collect(plant_group) + if event.key == pygame.K_ESCAPE: + running = False + + Tractor.movement(tractor) screen.blit(background,(0,0)) plant_group.draw(screen) tractor_group.draw(screen) tractor_group.update() - clock.tick(60) - + pygame.display.flip() + clock.tick(60) \ No newline at end of file diff --git a/src/Plant.py b/src/Plant.py index 7fa7e1b..4702979 100644 --- a/src/Plant.py +++ b/src/Plant.py @@ -9,24 +9,36 @@ class Plant(pygame.sprite.Sprite): if species=="carrot": self.growth_time=100 self.weight=50 + self.min_hydration = 30 + self.max_hydration = 60 + self.soil_type = "torf" self.fertilizer="carrot_fertilizer" self.pic_path="assets/Carrot.png" elif species=="beetroot": self.growth_time=200 self.weight=200 + self.min_hydration = 20 + self.max_hydration = 60 + self.soil_type = "piaszczyste" self.fertilizer="beetroot_fertilizer" self.pic_path="assets/Beetroot.png" elif species=="potato": self.growth_time=100 self.weight=100 + self.min_hydration = 10 + self.max_hydration = 30 + self.soil_type = "ilaste" self.fertilizer="potatoe_fertilizer" self.pic_path="assets/Potato.png" else: self.growth_time=250 self.weight=75 + self.min_hydration = 10 + self.max_hydration = 65 + self.soil_type = "gliniaste" self.fertilizer="wheat_fertilizer" self.pic_path="assets/Wheat.png" diff --git a/src/Tractor.py b/src/Tractor.py index 39e2624..3cfc78e 100644 --- a/src/Tractor.py +++ b/src/Tractor.py @@ -1,23 +1,60 @@ import pygame + class Tractor(pygame.sprite.Sprite): - def __init__(self,engine,transmission): + def __init__(self,engine,transmission,fuel,fertilizer): super().__init__() self.image=pygame.image.load("assets/tractor/tractor.png") self.image=pygame.transform.scale(self.image,(36,36)) + self.UP = pygame.transform.rotate(self.image, 0) + self.DOWN = pygame.transform.rotate(self.image, 180) + self.LEFT = pygame.transform.rotate(self.image, 90) + self.RIGHT = pygame.transform.rotate(self.image, -90) self.rect = self.image.get_rect() self.engine=engine self.transmission=transmission - self.fuel=100 - + self.fuel=fuel + self.fertilizer=fertilizer + + def movement(self): + keys = pygame.key.get_pressed() + + if keys[pygame.K_LEFT] and self.rect.x>0: + self.image = self.LEFT + self.rect.x -= 36 + if keys[pygame.K_RIGHT] and self.rect.x<900: + self.image = self.RIGHT + self.rect.x += 36 + if keys[pygame.K_UP] and self.rect.y>0: + self.image = self.UP + self.rect.y -= 36 + if keys[pygame.K_DOWN] and self.rect.y<900: + self.image = self.DOWN + self.rect.y += 36 + def collect(self,plant_group): - self.plant_group=plant_group - print("collected plant") - pygame.sprite.spritecollide(self,self.plant_group,True) + self.plant_group=plant_group + print("collected plant") + pygame.sprite.spritecollide(self,self.plant_group,True) # collected=collected+1 # print("plants in trunk "+collected) - - def update(self): - self.rect.center=pygame.mouse.get_pos() + + def water_plant(self,plant_group): + self.plant_group=plant_group + print("watered plant") + # def update(self): + # self.rect.center=pygame.mouse.get_pos() + + def fertilize(self, plant_group): + self.plant_group=plant_group + print("fertilize") + + def plant(self, plant_group): + self.plant_group=plant_group + print("new plant") + + def find_nearest_plant(self,plant_group): + self.plant_group=plant_group + \ No newline at end of file diff --git a/src/__pycache__/map.cpython-310.pyc b/src/__pycache__/map.cpython-310.pyc index efd55d62e7a1eaf8032e6d3684934638bf227787..9d06a5f53b0f32a31df2a8ac70ed365e2fe95070 100644 GIT binary patch delta 217 zcmbQhJ%^h+pO=@50SLkr6y+zT++wV_#hR3ppPYS*u`-GyDX}OoJ~KBx ziUq`4$xtK%)bYzqKeRZts8~NGu_!Y!r98i=sxq%QJ5k>ywK%&ZzhLrFCQnAW&HT(U zj1Ez(1v!a%B~fBvGmGPkQ&Uq?Q{pr8;?puyb5e>Vf#wxS1Bockywvh|uwt+!5JGnH gY8FdI&B;$$GUSy(O65R=CWrvJ1c{KHoWrUD0H}{Wr2qf` delta 186 zcmbQkJ%O7$pO=@50SLC=klV;z!(?}hr6@l!1X8Urs`)UW|t=E7nhW#WF}6&$mGeWxLKMxhLPhIYe7z8UdgS= z^(+z!Qa}wwGC<-MXI^S~JXi*73WQLYyq(38QGfDBmJE3{kWxhup${TJRv{4zlPg$N E0H6OfwEzGB diff --git a/src/__pycache__/plant.cpython-310.pyc b/src/__pycache__/plant.cpython-310.pyc index 4605e26795c3a00cdd01f0840037827a726398a2..21fa799ffc9851f2178fd5d8b8665b9097dbc304 100644 GIT binary patch literal 1315 zcmai!&5qkP5XVV1Ye{42s8srP@!Iv1wDThUyGzE$xK@cD*is(XcHMC8yEGZ-x zyEc4FfV{?TZ+VkE1Ft>#6>`c@wo%_I!#~bQ^Pd?GEmxgRO7QyU_yIhP2>I7J`&WR@ zGyLiY2p~WUl94|Mc;J5`;0rRNGw-9H`9R;2VX($1@;Z0izx=JE@1h|{MuBABXELTh z!TS_v{$~=9EWixD4c`>JG3@u~=F)}UxL`{O4Um-<5Xc)o)+B;1f?HD@91P+mDIYP}1)V$x; zan(ZTBBQ2S3wmhB&_^aPK&ItQIKnl6o5)@4G1@J-g^b}gGJzkEsX3Unudv=My>@$R zqknjH1N}DKxpuX%BaG-?6SR9Pe-%vd?ySf9KyZLRzP3@$m8#4da9ryr4)+{R5LsX< zHO_jQ2sReV$U-iKTK2fs!syY9M*FxfCpJD6!l()}eRcXHr$4AA*UNml&_-l~UBG^# z!8XxvTXB;rsw=}ywRS(YERqFx^8V(g*jMk`c+R)=w3_( zH~aGLw)o%ffm08?^-ri$UBqx;Lw#NgWn;!LhhfaNbS-izw2h=@vM92HiK;Hllo>e} zHo6dUGBsIeE=x9DfZ|40CA$1_&rNhC3uYFz$kP8Nn#HxuSQ(-Zfwvn%0+2}8iqE|q8O`z+emW?VO?oxJrL z0r#HiSBR8G_=!Eo-6#HEKk|36ZtZ$~+NNE)JlxdSjUBgyM^NHS@CZ`I<`tY5&TcdI z;hYznCrv-Lv)x-Rih?oq&<&x%eP=y#@DR;^gKIt}N3^*!4Ae3DHqy0{1`qRXvo_E6 W(lohT8XKQ%`uK&Sr#HE7d*1;Paa(Z! literal 997 zcmaJ=&2AGh5VrR(o3!aaLI{eu=0H~B42YitLP(`jDSEY>vH#|r1VjBAcz>#nCJE3Gj7lcKN2ryp6fXM<Wo#`D0p8@>bli$;%GGQJV`&4%v+|B-KjmGbSt?*x7q zc}`B?d%;Eaj(k>?#%Q-)5{*&m zY^?cI;dzs>&(l(^m{8Sso0cn~6l3NP8d$+YJUvFhfeu5BE#~Ba2G0@v1>O2`2vzzv d{7?p`KX7YlLPAXA^XIERUQ)0u=Gr6&(O)@K0-OK< diff --git a/src/__pycache__/tractor.cpython-310.pyc b/src/__pycache__/tractor.cpython-310.pyc index 1a4249dd9339ee27f71ac1a94f68bdcdceecceae..7bb4d92f3c7514461389cb95abab89e4cdd660b1 100644 GIT binary patch literal 2085 zcmahKO>Y}TbY^#Uz5a@wv<+?PAqT!zKnzp@R3U^!p+G8wXeuOMM$69F+GM?JX4ZsQ z=9EbN4;)Z@LCT%q!4H@d5~rNGaUi@m>rI`u5o7I}_ujmDZ{DZ#cDq4f{d!|d{8=O9 zFCfoO|0*y~RSBZCH5?3miF zisB+yvA1FoaeO)&*1rHK$PqcA3qncZ?71gQ&;^|n?gHhV_;a%73TNS5aB7z0T25eP zN)EG}`U=OhoW=^rx11(wIB6{i=xoo?*4iBPcjhj@?wkQ!7X)0W^=G#ut!1HmMd?bl zZ%?vO=$yR*?^o!Fq5#f*M=$`8{C0kR9&Q*%%loE!?a9?>N>vo27*llF9A5Erp|esg1elb zl7H^?9&4#|Pedw-#6hlRhne1wdiSN?FY-xmcdEY6A-_PVo>p-WaLo1gud=M!f^ex`E@xO8~y-L$$9Z>>l-m%5u) zcN?VRr8Mf6fUjMawz`{GQq>o-zAYJBJjpS58g^6wZW?!A9-1a5c%mfKo-qCn$KE9?W_0D1K$ zf@k90wBp?Q_7-Z!Y3S1yon5OQvm$ZjgVft_Ep+;({2i@4gs#0TbC&BoUe`gpO@s%Yb#>wZGvKwlFZ^qZe$#0gK*x z@w@pn6hnbuxgF?x%=E$zUWnj8gZklg?>t<%m|(l93$L=Jrbg*umvIR z*`K%Rx3*SkT~@7GryoA2SH1q)qQc)%;ne8je|I-}gajnCA*KkXFoPIEF9dqVu%6+6 zG@1Fn)dDbazsSbB#XjQe7&>+h8;``l_62tW!$lJ42or2jx4ltzL?U2|dPXaM6Ax^G;E(h7LN0^>km+E|i2ch6csQF^q+%TiI7+$3pz*^J*7yed?D) zIeFBoP*o+w!GX^)s_9fsH;%?_LWGFLFpJ$@!tG=?=(%yXUsFx4ITt@5bA7lLqO)B| N??^1i7^Bc9-d{|0+FJks diff --git a/src/screen.py b/src/screen.py deleted file mode 100644 index 35d197a..0000000 --- a/src/screen.py +++ /dev/null @@ -1,29 +0,0 @@ -import pygame - -# size in pixels of one tile = 36px/36px -tile = (36, 36) - -# later move it to another class "barn"? -barn_img = pygame.image.load('assets/barn.png') -barn = pygame.transform.scale(barn_img, tile) - -# screen settings -SIZE = (900, 900) -SCREEN = pygame.display.set_mode(SIZE) -pygame.display.set_caption("Traktor_interaktor") - -# screen dispaly -def set_screen(myTractor): - # setting background color - SCREEN.fill((90,50,20)) - - # dispaly agent icon - TRACTOR = SCREEN.blit(myTractor.IMG, (myTractor.x, myTractor.y)) - # display barn - SCREEN.blit(barn, (0, 863)) - # draw lines(horizontal, vertical) on the screen - for line in range(25): - pygame.draw.line(SCREEN, (0, 0, 0), (0, line * 36), (SIZE[0], line * 36)) - pygame.draw.line(SCREEN, (0, 0, 0), (line * 36, 0), (line * 36, SIZE[1])) - - pygame.display.update() \ No newline at end of file diff --git a/tractor.py b/tractor.py deleted file mode 100644 index 44b5d9c..0000000 --- a/tractor.py +++ /dev/null @@ -1,33 +0,0 @@ -import pygame - -class Tractor: - # this is where tractor spawns when program starts (center) - x=432 - y=432 - # it's speed -> pixels it moves after pressing arrow - speed = 36 - # tractor image - tractor_img = pygame.image.load('assets/tractor/tractor.png') - IMG = pygame.transform.scale(tractor_img, (36, 36)) - # tractor image rotation - UP = pygame.transform.rotate(IMG, 0) - DOWN = pygame.transform.rotate(IMG, 180) - LEFT = pygame.transform.rotate(IMG, 90) - RIGHT = pygame.transform.rotate(IMG, -90) - - -def movement(myTractor): - keys = pygame.key.get_pressed() - - if keys[pygame.K_LEFT] and myTractor.x>0: - myTractor.IMG = myTractor.LEFT - myTractor.x -= myTractor.speed - if keys[pygame.K_RIGHT] and myTractor.x<900-myTractor.speed: - myTractor.IMG = myTractor.RIGHT - myTractor.x += myTractor.speed - if keys[pygame.K_UP] and myTractor.y>0: - myTractor.IMG = myTractor.UP - myTractor.y -= myTractor.speed - if keys[pygame.K_DOWN] and myTractor.y<900-myTractor.speed: - myTractor.IMG = myTractor.DOWN - myTractor.y += myTractor.speed From f3d727cf9d9c30999519d42e3ef4f5e7e4135e07 Mon Sep 17 00:00:00 2001 From: dardwo Date: Sun, 26 Mar 2023 14:20:58 +0200 Subject: [PATCH 2/2] added field class --- src/Field.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 src/Field.py diff --git a/src/Field.py b/src/Field.py new file mode 100644 index 0000000..77b78d6 --- /dev/null +++ b/src/Field.py @@ -0,0 +1,21 @@ +from pygame.sprite import Sprite + +class Field(Sprite): + def __init__(self, type, row_id, col_id, image, cost, hydration_level , soil, + fertilizer_degree, development_degree, plant_type, fertilizer_type, to_water): + + self.type = type + self.row_id = row_id + self.col_id = col_id + self.position = (row_id, col_id) + self.image = image + self.cost = cost + + self.hydration_level = hydration_level + self.soil = soil + self.fertilizer_degree = fertilizer_degree + self.development_degree = development_degree + self.plant_type = plant_type + self.fertilizer_type = fertilizer_type + self.to_water = to_water +